New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tag2content

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tag2content

Replace a tag with content in a configurable way

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

tag2content

Replace a tag with content in a configurable way

Linux Build Status

Install

Install with npm:

$ npm install --save tag2content

Import

// ES6
import tag2content from 'tag2content';

// CommonJS
const tag2content = require('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 = {
  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.';

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 = {
  country: variables => {
    return variables.name;
  },
  friend: ({ name, toUppercase }) => {
      return toUppercase ? name.toUpperCase() : name;
   }
};

Custom delimiters

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.';

Keywords

FAQs

Package last updated on 08 Jan 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc