
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
string-replace-enhanced
Advanced tools
string-replace-enhanced allow you to go futher with the command replace for string in javascript. You have two options, use the object and implement his settings or use the functions in a standalone way.
Using npm:
npm install -S string-replace-enhanced
... and then:
import stringReplaceEnhanced from 'string-replace-enhanced'
// or
import {replaceBefore, replaceAfter, replaceAround, replace, replaceRegex} from 'string-replace-enhanced'
// or
const {default: stringReplaceEnhanced} = require('string-replace-enhanced')
In NodeJS:
const {default : stringReplaceEnhanced} = require('string-replace-enhanced')
// or
import {replaceBefore, replaceAfter, replaceAround, replace, replaceRegex} from 'string-replace-enhanced'
In a browser:
<script src="https://unpkg.com/string-replace-enhanced@latest/lib/sre.min.js"></script>
<script>
/* stringReplaceEnhanced is available here */
/* in object style */
new StringReplaceEnhanced.default(options) //constructor
/* standalone functions */
StringReplaceEnhanced.replace(...args) //function
</script>
There is two possibilities, use the object ou the separated functions.
With the object it will be possible to reuse a preset configuration or use the default one.
import stringReplaceEnhanced from 'string-replace-enhanced'
// If an option is missing, it will be given a default value
const options = {
after: ['«'],
around: [],
before: ['!', '?', ':', ';', '»'],
regex: [],
replacer: ' ',
toReplace: ' ',
};
// Create a new stringReplaceEnhanced object
const sre = new stringReplaceEnhanced(options);
// Use its methods simply giving the string to work on
console.log(sre.replaceBefore('Hello world !'));
// Hello world !
For the standalone functions you will need to specify every arguments
import { replaceBefore } from 'string-replace-enhanced'
console.log(replaceBefore('Hello world !', ' ', ' '))
// Hello world !
Check the links below to have the up to date version:
| name | type | default | description |
|---|---|---|---|
| after | ReadonlyArray or string | ['«'] | Array of char in need of potential need of replacement after itself |
| around | ReadonlyArray or string | [] | Array of char in need of potential need of replacement around itself |
| before | ReadonlyArray or string | ['!', '?', ':', ';', '»'] | Array of char in need of potential need of replacement before itself |
| regex | ReadonlyArray or RegExp | [] | Array of regex, replace match by the replacer |
| replacer | string | ' ' | Replacer of matching toReplace |
| toReplace | string | ' ' | String to replace, in the function replace toReplace can be an array of string |
To see more about the methods and properties you can access to the documentation here
To see more about the functions or the configuration you can access it in the latest documentation here or one in the forked project:
npm i && npm run build:doc
The documentation will be available in the docs file.
FAQs
A package to go further with string replace
We found that string-replace-enhanced 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.