shared
utils
string
object
is
extension
js
tracking
string
dom
when
selection
position
iframe
event
scroll
console
node
string
project
fs
console
replaceTokens
Type:Function
Status:stable
Since:1.0.0
Platform:jsnode
@blackbyte.sugar.shared.string
This function takes as parameter a tokened string like “something [cool]”, an object of arguments/values and return the processed string with the tokens replaced by the arguments values.
Params
- string*-String
The string to process
- tokensObj*-Object
The arguments/value object
- settings{}Object
A settings object to configure the parsing process
Return
- -String
The processed string
Example
import { replaceTokens } from '@blackbyte/sugar/string';
replaceTokens('hello [world]', { world: 'Coco' }); // => hello CocoSettings
- regexp\[([a-zA-Z0-9-_]+)\String
The regexp to use to match the tokens
- stripUndefinedtrueBoolean
Specify if you want to strip the tokens that are not found in the tokensObj
Todo
- Add setting to define tokens delimiternormal
- Support multi level tokens like [something.cool]normal
- testsnormal
Author
- Olivier Bosselolivier.bossel@gmail.comhttps://blackbyte.space