@bbc/psammead-detokeniser
v1.0.7
Published
Replaces % delimited tokens with a value from the dictionary object
Downloads
53
Maintainers
Readme
psammead-detokeniser -
Description
The detokeniser
utility operates on strings and replaces % delimited tokens with a value from the dictionary object.
Installation
npm install @bbc/psammead-detokeniser --save
Props
| Argument | Type | Required | Default | Example |
| --------- | ---- | -------- | ------- | ------- |
| text | string | yes | N/A | 'Foo %token%'
|
| dictionary | object | yes | N/A | { '%token%': 'Bar'
} |
dictionary
is an object which maps keys as tokens to values. For example, in psammead-social-embeds
, all social media providers in the data are in lowercase which corresponds as the token to be interpolated into the full name.
E.g. '%youtube%' -> 'YouTube'
Usage
import detokenise from "@bbc/psammead-detokeniser"
// This will return 'Duration: 20 minutes'
detokenise('Duration: %token%', { '%token%': '20 minutes' });
When to use this utility
When not to use this utility
Accessibility notes
Roadmap
Contributing
Psammead is completely open source. We are grateful for any contributions, whether they be new utilities, bug fixes or general improvements. Please see our primary contributing guide which can be found at the root of the Psammead repository.
Code of Conduct
We welcome feedback and help on this work. By participating in this project, you agree to abide by the code of conduct. Please take a moment to read it.
License
Psammead is Apache 2.0 licensed.