Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.