New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fast-replace

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-replace

Recursive find and replace command line utility

latest
Source
npmnpm
Version
3.0.4
Version published
Maintainers
1
Created
Source

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 => {});

Keywords

find

FAQs

Package last updated on 02 Nov 2020

Did you know?

Socket

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.

Install

Related posts