Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
The replaceall npm package is a simple utility for replacing all instances of a substring within a string. It provides a straightforward API to perform global replacements without the need for regular expressions.
Basic Replacement
This feature allows you to replace all occurrences of a substring with another substring. In this example, all instances of 'foo' are replaced with 'bar'.
const replaceall = require('replaceall');
const result = replaceall('foo', 'bar', 'foo is foo');
console.log(result); // 'bar is bar'
Case Sensitive Replacement
This feature performs case-sensitive replacements. Only the exact matches of the substring will be replaced. In this example, only 'Foo' is replaced with 'bar', while 'foo' remains unchanged.
const replaceall = require('replaceall');
const result = replaceall('Foo', 'bar', 'Foo is foo');
console.log(result); // 'bar is foo'
Replacing Special Characters
This feature allows you to replace special characters within a string. In this example, all instances of '?' are replaced with '!'.
const replaceall = require('replaceall');
const result = replaceall('?', '!', 'Hello? How are you?');
console.log(result); // 'Hello! How are you!'
The string-replace-all package provides similar functionality to replaceall, allowing you to replace all instances of a substring within a string. It also supports case-sensitive replacements and is a lightweight alternative.
The replace-string package is another alternative that offers global string replacement without the need for regular expressions. It is simple to use and provides similar functionality to replaceall.
The string.prototype.replaceall package is a polyfill for the String.prototype.replaceAll method introduced in ECMAScript 2021. It provides native-like functionality for replacing all instances of a substring within a string.
Replace all instances in a JavaScript string.
npm install replaceall
To then include replaceall in your node app:
var replaceall = require("replaceall");
var result = replaceall("instances of this", "with this string", "in this string");
var original = "hello world goodbye world";
replaceall("world", "everyone", original);
// "hello everyone goodbye everyone"
replaceall("l", "z", original);
// "hezzo worzd goodbye worzd"
FAQs
Replace all instances in a JavaScript string
The npm package replaceall receives a total of 337,749 weekly downloads. As such, replaceall popularity was classified as popular.
We found that replaceall 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.