0.6.0 • Published 1 year ago

@booco-public/substitutem v0.6.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

substitutem - substitute substrings with context

This library exports methods that allows to replace substring by values from acontext or returned by a callback.

Installation

npm install --save @booco-public/substitutem

Usage

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: 
  }
};

Usage with callback

import { substitute } from '@booco-public/substitutem';

substitute('Hello {message}!', (key: string) => (key === 'message' ? 'World' : `{${key}}`)); // Hello World!

Usage with async callback

import { substituteAsync } from '@booco-public/substitutem';

await substituteAsync('Hello {message}!', async (key: string) => (key === 'message' ? 'World' : `{${key}}`)); // Hello World!
0.6.0

1 year ago

0.5.0

1 year ago

0.4.3

1 year ago

0.4.1

1 year ago

0.4.2

1 year ago

0.3.0

1 year ago

0.4.0

1 year ago

0.2.2

2 years ago

0.2.1

2 years ago