diff --git a/README.md b/README.md index 10b2646..b87fd1a 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,27 @@ const sheldon = { // => "I've always wanted to go to a goth club. BAZINGA!" ``` +### `format.create(transformers)` + +This function takes an object mapping names to transformers and returns a +formatting function. A transformer is applied if its name appears, prefixed +with `!`, after a field name in a template string. + +```javascript +const fmt = format.create({ + escape: s => s.replace(/[&<>"'`]/g, c => '&#' + c.charCodeAt(0) + ';'), + upper: s => s.toUpperCase(), +}) + +fmt('Hello, {!upper}!', 'Alice') +// => 'Hello, ALICE!' + +const restaurant = {name: 'Anchor & Hope', url: 'http://anchorandhopesf.com/'} + +fmt('{name!escape}', restaurant) +// => 'Anchor & Hope' +``` + ### `format.extend(prototype, transformers)` This function takes a prototype (presumably `String.prototype`) and an object