Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

insert-token

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insert-token

Simple search and replace utility for replacing tokens in objects / strings / text etc

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
decreased by-70.37%
Maintainers
1
Weekly downloads
 
Created
Source

insert-token

Simple search and replace utility for replacing tokens in objects / strings / text etc

Usage:

const tokens = require('../lib/replacer');

const params = {
    name: 'Cayle',
    address: 'The Beach',
    height: 1.75,
    busy: true
};

tokens.replace('Hi {{name}}', params);  // 'Hi Cayle'

It processes arrays:

tokens.replace(['My name is {{name}}', 'Height is {{height}}'], params); 
//['My name is Cayle', 'Height is 1.75']

and objects. Both keys and values are parsed:

tokens.replace({ name: '{{name}}', '{{address}}': 1, '{{name}}': '{{height}}' }, params);
// { name: 'Cayle', 'The Beach': 1, 'Cayle': '1.75' })

Nested objects work too:

let result = tokens.replace({
    id: { name: '{{name}}',
          address: '{{address}}'
    },
    tokens: ['{{name}}', '{{busy}}', '{{height}}'],
    wins: 99
}, params);

=> {
    id: { name: 'Cayle',
        address: 'The Beach'
    },
    tokens: ['Cayle', 'true', '1.75'],
    wins: 99
});

Keywords

FAQs

Package last updated on 10 Nov 2016

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