wj42ftns / replace-in-files Goto Github PK
View Code? Open in Web Editor NEWReplace text in one or more files or globs.
License: MIT License
Replace text in one or more files or globs.
License: MIT License
If I just want to extract of files regexp matched data to a file, How can i do this.
Tested as node script on Windows (11) with the following options:
replacing: style="display:inline;fill:XXXX"
Not working:
const options = {
files: '../src/assets/vectors/**/*',
// from: /hallo?/g,
from: /display:.*;/g,
to: '',
}
But this does actually work:
const options = {
files: '../src/assets/vectors/**/*',
// from: /hallo?/g,
from: /display:.*;/g,
to: ' ',
}
Also the changedFiles param from the readme example write undefined in both cases.
Modified files: undefined
Count of matches by paths: [ { '../src/assets/vectors/dealer_word.svg': 10 } ]
was called with: { files: '../src/assets/vectors/**/*', from: /display:.*;/g, to: ' ' }
Hello! Simple issue: most important feature for replacing (at least for me) it's changing value from some string to empty string.
If I trying to do something like:
let options = { files: ['../src/*', '../src/**/*'], from: /test/gm, to: "" }
I always have only occurrences in result, but files not changing.
Node version: v11.5.0
Package version: Latest at the moment.
Thanks in advance!
I tried to use your library using a regexp find and function replace, but spent 20 minutes getting my head round the options and console logging stuff to see what I needed to do. Eventually I gave up and I ended up writing a glob and doing it myself.
This was my use case - converting tags (with ml-
prefix) from snake-case
to PascalCase
:
const Fs = require('fs')
const glob = require('glob')
// options
const options = { encoding:'utf8' }
// start
glob('./src/**/*.vue', function (er, files) {
// debug
console.log(`Processing ${files.length} files...`)
// process files
files.forEach(file => {
// variables
let count = 0
const text = Fs.readFileSync(file, options)
// replacement
const output = text.replace(/<\/?ml-[\w-]+/g, function (match, pos, all) {
count += 1
return match
.replace(/-\w/g, m => m.slice(1).toUpperCase())
.replace('ml', 'Ml')
})
// if replacements were made
if (count) {
Fs.writeFileSync(file, output, options)
console.log(count, file)
}
})
})
With your lib I just didn't know what the replace function's arguments were, so specifically documenting an example would make it less ambiguous.
Thanks
I have file called AndroidManifest.xml which is - application/octet-stream; charset=binary (file -I AndroidManifest.xml)
Here is a screenshot from my ide when I try to open it
https://i.ibb.co/48Vn1H2/Screenshot-2020-09-02-at-16-47-17.png
In options, I have set
shouldSkipBinaryFiles: false
But it's doesn't help :(
string.replace
allows patterns like '$1'
in the to
string to refer to capture groups. These patterns don't work in this library. Instead, the literal string '$1'
is inserted.
Hello! Thanks for your work on this package, it's been very helpful for my work.
I'm running into an issue where running the package on a directory with images cause those files to become corrupted. I've created a simplified example to make it easier to test.
To reproduce:
git clone [email protected]:zachwolf/replace-in-files-reduces-test-case.git
cd replace-in-files-reduces-test-case
npm i
npm start
git status
Notice that the favicon is now reporting a binary diff, and it can not be opened by browsers.
I know that there are options and glob matches to work with this already provided. It would be very helpful if the default behavior only ran replace on string-like content. I'm not sure what the use case would be for replacing in image files intentionally.
Thanks again!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.