This library exports methods that allows to replace substring by values from acontext or returned by a callback.
npm install --save @booco-public/substitutem
import { substitute } from '@booco-public/substitutem';
substitute('Hello {message}!', { message: 'World' }); // Hello World!
substitute('Subject: {booking.subject}', {
booking: {
subject : 'Hello World!'
}
}); // Subject: Hello World!
substitute('Date: {date,dd-MM-yyyy}', {
date: '2023-09-10T15:00:00.000Z'
}, {
timezone: 'Europe/Berlin'
}); // Date: 10-09-2023
const context = {
booking: {
subject: 'Hello World!',
start:
}
};
import { substitute } from '@booco-public/substitutem';
substitute('Hello {message}!', (key: string) => (key === 'message' ? 'World' : `{${key}}`)); // Hello World!
import { substituteAsync } from '@booco-public/substitutem';
await substituteAsync('Hello {message}!', async (key: string) => (key === 'message' ? 'World' : `{${key}}`)); // Hello World!