
Security News
CISA Kills Off RSS Feeds for KEVs and Cyber Alerts
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
string-multiple-replace
Advanced tools
Replace multiple substrings in a string in turn.
Replace all substring matches in a string with an mapping object that is table of replaceThis: withThis
, and you can provide a sequencer
to decide the order of replacement.
npm install --save string-multiple-replace
or
yarn add string-multiple-replace
const multiReplace = require('string-multiple-replace');
const input = "abcde";
const matcherObj = {
"a": "b",
"b": "c",
"c": "d",
"d": "e"
}
multiReplace(input, matcherObj, ["a", "b", "c", "d"]); // eeeee
multiReplace(input, matcherObj); // bcdee
const multiReplace = require('string-multiple-replace');
const input = "I'm only brave when I have to be. Being brave doesn't mean you go looking for trouble.";
const matcherObj = {
"brave": "cowardly",
"trouble": "escape"
}
const sequencer = ["brave", "trouble"];
multiReplace(input, matcherObj, sequencer);
//I'm only cowardly when I have to be. Being cowardly doesn't mean you go looking for escape.
const multiReplace = require('string-multiple-replace');
const input = "I'm only brave when I have to be. Being brave doesn't mean you go looking for trouble.";
const matcherObj = {
"brave": "cowardly",
"trouble": "escape"
}
multiReplace(input, matcherObj, keys => keys);
//I'm only cowardly when I have to be. Being cowardly doesn't mean you go looking for escape.
multiReplace(input, matcherObj[,sequencer])
The original string is replaced in turn according to the matcherObj
, where sequencer
determines the replacement order, and the existence state of sequencer
determines whether the last operation overwrites the previous operation.
Type: string
Required
A string to be processed.
Type: object
Required
An object that represents a string replacement mapping.
Type: function
, array
Required:false
A function
that takes the keys of matcherObj
, and return an suquence array.
Upgrade Instruction: the existence state of
sequencer
determines whether the last operation overwrites the previous operation.
FAQs
Replace multiple substrings in a string in turn
The npm package string-multiple-replace receives a total of 1,491 weekly downloads. As such, string-multiple-replace popularity was classified as popular.
We found that string-multiple-replace demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.