Package Exports
- string-object-formatter
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (string-object-formatter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
string-object-formatter
Inspired by python named formatter function, replace text inside a string based on object properties names and values.
Example usage
Default delimiters
const Formatter = require('string-object-formatter');
const formatter = new Formatter();
const toFormat = 'My name is {firstName} {lastName}';
const formatted = formatter.format(toFormat, {firstName: 'John', lastName: 'Doe'});
// formatted is 'My name is John Doe'
Custom delimiters
const Formatter = require('string-object-formatter');
const formatter = new Formatter('{{', '}}');
const toFormat = 'My name is {{firstName}} {{lastName}}';
const formatted = formatter.format(toFormat, {firstName: 'John', lastName: 'Doe'});
// formatted is 'My name is John Doe'
Formatter
Kind: global class
- Formatter
- new Formatter()
- instance
- .format(stringToFormat, formatItems) ⇒
string
- .format(stringToFormat, formatItems) ⇒
- static
new Formatter()
Formatter Class
formatter.format(stringToFormat, formatItems) ⇒ string
Formats string according to object
Kind: instance method of Formatter
Param | Type | Description |
---|---|---|
stringToFormat | string |
|
formatItems | object |
Ex.: {'toReplace': 'replaced'} turns 'example_{toReplace}' to 'example_replaced' |
Formatter.Formatter
Kind: static class of Formatter
new Formatter([startDelimiter], [endDelimiter])
Creates an instance of Formatter.
Param | Type | Default |
---|---|---|
[startDelimiter] | string |
"'{'" |
[endDelimiter] | string |
"'}'" |