
Research
Security News
Malicious npm Packages Use Telegram to Exfiltrate BullX Credentials
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
replace-string-loader
Advanced tools
Webpack loader for replacing a text and other data in a file
npm install --save-dev replace-string-loader
options: {
search: "string or /regExp/",
replace: "string or function",
flags: "string",
file: bool
}
search: a string or a regular expression that will be found and replaced in the file.
replace: a string or a function for replacing.
If an options.replace is a function: this function recieves next arguments:
match – a found match,
p1, p2, ..., pn – string content (if exist),
offset – position where the match was found,
s – a basic string.
The function must return a string!!!
flags: regExp flags (g, i, m). Used if options.search is a string and ignored if options.search is a regular expression.
file: if true - a found result will save to the file.
Searching and replacing '105px' to '200px' in scss files: Result will be saved to a json file.
module: {
rules: [{
test: /\.scss$/,
use[{
loader: 'replace-string-loader',
options: {
search: '105px',
replace: '200px',
flags: 'g',
file: true
}
}]
}]
}
An output json file:
{
"file": "[last-file-folder][file-name].[ext]",
"fullFilePath": "full-path-to-file/[file-name].[ext]",
"matches": [
{
"matchLine": 12,
"matchContent": "min-height: 105px;",
"replaceTo": "min-height: 200px;"
},
{
"matchLine": 22,
"matchContent": "min-height: 105px;",
"replaceTo": "min-height: 200px;"
}
]
}
or, without saving into the file
module: {
rules: [{
test: /\.scss$/,
use[{
loader: 'replace-string-loader',
options: {
search: /105px/g,
replace: '200px',
file: false
}
}]
}]
}
Searching and replacing 'exampleVarA' to 'exampleVarB' in js files:
module: {
rules: [{
test: /\.js$/,
use[{
loader: 'replace-string-loader',
options: {
search: /exampleVarA/g,
replace: 'exampleVarB'
}
}]
}]
}
Searching and replacing '105px' to '1050px' in css files:
module: {
rules: [{
test: /\.css$/,
use[{
loader: 'replace-string-loader',
options: {
search: '105px',
replace: function(match){ return `${parseInt(match) * 10}px`;}
}
}]
}]
}
FAQs
Webpack loader for replacing a text and other data in a file
The npm package replace-string-loader receives a total of 674 weekly downloads. As such, replace-string-loader popularity was classified as not popular.
We found that replace-string-loader 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 uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.
Security News
AI-generated slop reports are making bug bounty triage harder, wasting maintainer time, and straining trust in vulnerability disclosure programs.