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

  1. string*-String

    The string to process

  2. tokensObj*-Object

    The arguments/value object

  3. settings{}Object

    A settings object to configure the parsing process

Return

  1. -String

    The processed string

Example

import { replaceTokens } from '@blackbyte/sugar/string';
replaceTokens('hello [world]', { world: 'Coco' }); // => hello Coco

Settings

  1. regexp\[([a-zA-Z0-9-_]+)\String

    The regexp to use to match the tokens

  2. 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