Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
replace-string
Advanced tools
Readme
Replace all substring matches in a string
Similar to String#replace()
, but supports replacing multiple matches. You could achieve something similar by putting the string in a RegExp
constructor with the global flag and passing it to String#replace()
, but you would then have to first escape the string anyways.
With Node.js 16, this package is partly moot as there is now a String#replaceAll
method. However, it does not have a caseInsensitive
option.
$ npm install replace-string
import replaceString from 'replace-string';
const string = 'My friend has a 🐑. I want a 🐑 too!';
replaceString(string, '🐑', '🦄');
//=> 'My friend has a 🦄. I want a 🦄 too!'
Returns a new string with all needle
matches replaced with replacement
.
Type: string
The string to work on.
Type: string
The string to match in input
.
Type: string | Function
The replacement for needle
matches.
If a function, it receives the matched substring, the match count, the original input, and the index in which the match happened (as measured from the original input):
import replaceString from 'replace-string';
replaceString('Foo 🐑 Bar', '🐑', (matchedSubstring, matchCount, input, matchIndex) => `${matchedSubstring}❤️`);
//=> 'Foo 🐑❤️ Bar'
Type: object
Type: number
Default: 0
Index at which to start replacing.
Type: boolean
Default: false
Whether or not substring matching should be case-insensitive.
RegExp
matches in a stringFAQs
Replace all substring matches in a string
The npm package replace-string receives a total of 182,422 weekly downloads. As such, replace-string popularity was classified as popular.
We found that replace-string 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.