3.0.4 • Published 4 years ago

fast-replace v3.0.4

Weekly downloads
308
License
MIT
Repository
github
Last release
4 years ago

fast-replace

fast-replace is a command line utility that recursively finds and replaces regex at blazing fast speeds

  • ~12x faster than other replacers (uses ripgrep under the hood)
  • recursive by default
  • respects .gitignore by default
  • matches file globs
  • supports regex capture groups

Installation

npm install -g fast-replace

Examples

Replace all occurrences of foo with bar recursively starting from the current directory:

fast-replace 'foo' 'bar'

Preview replacements without modifying any files:

fast-replace 'foo' 'bar' -D

Replace only in mock.js and the tests/ directory:

fast-replace 'foo' 'bar' mock.js tests/

Replace snake_case_words with kebob-case-words:

fast-replace '(\S)_(\S)' '$1-$2'

Replace only in files with names matching *.js or *.jsx:

fast-replace 'foo' 'bar' -g '*.js' '*.jsx'

Replace only in files not in the vendors/ directory:

fast-replace 'foo' 'bar' -G 'vendors/**'

Options

fast-replace <from> <to> [paths...]

  <from>              Regex pattern to match
  <to>                String to replace matched pattern, use $1, $2, etc to
                      match regex groups
  [paths...]          Directories or files to recursively search

Options:
  --dryrun, -D            print replacements without making changes    [boolean]
  --quiet, -q             don't log to console                         [boolean]
  --unrestricted, -u      don't respect .gitignore                     [boolean]
  --ignoreCase, -i        search with case insensitively               [boolean]
  --fixedStrings, -F      treat pattern as a literal string instead of a regular
                          expression                                   [boolean]
  --globs, -g             include files / directories matching the given glob
                                                                         [array]
  --ignoreGlobs, -G       exclude files / directories matching the given glob
                                                                         [array]
  --ignoreLargeFiles, -L  Ignore files larger than 50KB in size        [boolean]
  --help                  Show help                                    [boolean]
  --version               Show version number                          [boolean]

API

const fastReplace = require('fast-replace');

fastReplace('from', 'to', { /* options, matches CLI */ }).then(changedFiles => {});
3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.0.0

4 years ago

0.2.0

5 years ago

0.1.6

5 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago