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

token-replacer

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

token-replacer

A library to replace lines and blocks within text (or files) designated by token comments. Useful for removing example code from a template.

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
0
Weekly downloads
 
Created
Source

token-replacer

A library to replace lines and blocks within text (or files) designated by token comments (e.g. // @template:car next-line). Useful for removing example code from a template.

Installation

Install using NPM:

$ npm i token-replacer

Usage

Replace tokens within a string

import { replaceTokens } from 'token-replacer

const text = `

// @template:car next-line
const car = {}

// @template:house block-start

const house = {
    sqFt: 1000,
    bedrooms: 3,
}

// @template:house block-end
`

const replacedText = replaceTokens(text, {
    car: true,
    house: false,
})

console.log(replacedText)

Since car is set to true, it will be preserved (the token comments will be removed), but house is false, so it will be removed. The resulting replacedText will be:

// @template:car next-line
const car = {}

Replace tokens in files (in-place) within a directory (recursive)

import { replaceTokensInFiles } from 'token-replacer

replaceTokensInFiles('./code', {
    car: true,
    house: false,
})

Token Types

Next Line

Replace the line directly after the next-line comment:

// @template:car next-line

Block

Replace the lines in between a block-start and block-end comment:

// @template:house block-start

const house = {
    sqFt: 1000,
    bedrooms: 3,
}

// @template:house block-end

FAQs

Package last updated on 04 Oct 2024

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