adamreisnz / replace-in-file

A simple utility to quickly replace contents in one or more files
580 stars 65 forks source link

need replaceAll #151

Closed Rabbitzzc closed 1 year ago

Rabbitzzc commented 2 years ago

https://github.com/adamreisnz/replace-in-file/blob/main/lib/helpers/make-replacements.js#L43

need add :

if (typeof item === 'string') item = new RegExp(item, 'g')
adamreisnz commented 1 year ago

From the readme:

Please note that the value specified in the from parameter is passed straight to the native String replace method. As such, if you pass a string as the from parameter, it will only replace the first occurrence.

To replace multiple occurrences at once, you must use a regular expression for the from parameter with the global flag enabled, e.g. /foo/g.

const options = {
  from: /foo/g,
  to: 'bar',
};