![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
tag2content
Advanced tools
Replace a tag with content in a configurable way
Install with npm:
$ npm install --save tag2content
// ES6
import tag2content from 'tag2content';
// CommonJS
const tag2content = require('tag2content').default;
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 = {
country: () => 'Japan',
'friend-name': () => 'Joe',
};
Replace tags with their content:
const updatedText = tag2content({
tags,
text,
});
console.log(updatedText) //=> 'I would like to go to Japan next year, with my friend Joe.';
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 = {
country: variables => {
return variables.name;
},
friend: ({ name, toUppercase }) => {
return toUppercase ? name.toUpperCase() : name;
}
};
You can use custom delimiters:
const text = 'My first name is {first-name value="Robin"}.';
const tags = {
'first-name': ({ value }) => value,
};
const updatedText = tag2content({
delimiters: {
end: '}',
start: '{',
},
tags,
text,
});
console.log(updatedText) //=> 'My first name is Robin.';
FAQs
Replace a tag with content in a configurable way
We found that tag2content demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.