tag2content
Replace a tag with content in a configurable way
Install
Install with npm:
$ npm install --save tag2content
Import
// ES6; // CommonJSconst tag2content = default;
Basic usage
Create a text, in which you define some tags:
const text = 'I would like to go to [country] next year, with my friend [friend-name].';
Create a configuration for you tags:
const tags = 'Japan' 'Joe';
Replace tags with their content:
const updatedText = ; console //=> 'I would like to go to Japan next year, with my friend Joe.';
Variables
You can add some variables to your tags:
const text = 'I go to [country name="England"] next year, with [friend name="Lucy" to-uppercase="true"].';
When you defines a function for each tag, variables are passed as argument. Kebab case variables are transformed to Pascal case ("to-uppercase" becomes "toUppercase").
const tags = { return variablesname; } { return toUppercase ? name : name; };
Custom delimiters
You can use custom delimiters:
const text = 'My first name is {first-name value="Robin"}.'; const tags = value; const updatedText = ; console //=> 'My first name is Robin.';