New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

replace-once

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

replace-once

Make multiple replacements in a string without replacing ones that have already been replaced.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

replace-once

npm package version Travis build status npm package downloads code style license

Make multiple replacements in a string without replacing ones that have already been replaced.

Installation

npm install --save replace-once

Usage

replaceOnce(str, find, replace, [ flags ])

const replaceOnce = require('replace-once')

var str = 'abc abcd a ab'
var find = ['abcd', 'abc', 'ab', 'a']
var replace = ['a', 'ab', 'abc', 'abcd']
replaceOnce(str, find, replace, 'gi')
//=> 'ab a abcd abc'

Parameters

str (string)

The string to do replacements on.

find (array)

An array of strings to search for when doing replacements. Must be in the same order as their replacement specified inside of the replace parameter. Strings may contain Regular Expressions (regexp).

replace (array)

An array of strings to replace the strings specified inside of the find parameter with. Must be in the same order as their counterpart specified inside of the find parameter.

flags (string)

Optional

RegExp flags to use when doing replacements. (e.g g for global, i for case-insensitive)

License

MIT. See the license.md file for more info.

Keywords

array

FAQs

Package last updated on 28 Feb 2018

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