https://github.com/g-harel/emn
command line string replacement
https://github.com/g-harel/emn
cli regexp string-replace
Last synced: about 2 months ago
JSON representation
command line string replacement
- Host: GitHub
- URL: https://github.com/g-harel/emn
- Owner: g-harel
- License: mit
- Created: 2017-06-30T01:16:29.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-04T21:00:47.000Z (almost 8 years ago)
- Last Synced: 2025-02-22T16:38:47.075Z (2 months ago)
- Topics: cli, regexp, string-replace
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# emn
> Command line string replacement.
Match files using glob patterns and replace their contents using the `string.replace` function.
# Install
````
$ npm install --save-dev emn
````# Usage
### `cli`
````shell
$ emn [--preview] [--silent]
# glob globby pattern to define files to search
# pattern: regex pattern used to find matches (can include flags)
# replacement: string to replace the matches with
# --preview: log replacements to the console without applying them
# --silent: prevemt any logging to the console
````When using the cli, it is possible to use `\1` instead of `$1` to replace using capture groups.
Make sure to also include the full regex pattern (delimiting slashes + optional flags)
````shell
$ emn 'src/**/*.js' '/var (\w+)/gi' 'let \1' --preview
````### `require`
````javascript
const enm = require('enm');enm(glob, pattern, replacement[, options]);
// glob: globby pattern to define files to search in
// pattern: regex pattern used to find matches
// replacement: string to replace matches with
// options:
// isPreview: log the replacements to the console without applying them
// isSilent: prevents any logging to the console
````````javascript
emn('src/**/*.js', /var (\w+)/gi, 'let $1', {isPreview: true});
````