replace-in-file
Advanced tools
Comparing version 2.5.0 to 2.5.1
@@ -125,2 +125,14 @@ 'use strict'; | ||
it('should replace substrings', done => { | ||
replace({ | ||
files: 'test1', | ||
from: /(re)\s(place)/g, | ||
to: '$2 $1', | ||
}).then(() => { | ||
const test1 = fs.readFileSync('test1', 'utf8'); | ||
expect(test1).to.equal('a place re c'); | ||
done(); | ||
}); | ||
}); | ||
it('should fulfill the promise on success', () => { | ||
@@ -127,0 +139,0 @@ return replace({ |
{ | ||
"name": "replace-in-file", | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"description": "A simple utility to quickly replace text in one or more files.", | ||
@@ -9,3 +9,3 @@ "homepage": "https://github.com/adamreisnz/replace-in-file#readme", | ||
"email": "adam@reis.nz", | ||
"url": "http://adam.reiz.nz/" | ||
"url": "https://adam.reiz.nz/" | ||
}, | ||
@@ -12,0 +12,0 @@ "license": "MIT", |
@@ -13,3 +13,7 @@ # Replace in file | ||
```shell | ||
# Using npm | ||
npm install replace-in-file | ||
# Using yarn | ||
yarn add replace-in-file | ||
``` | ||
@@ -19,3 +23,3 @@ | ||
Specify options: | ||
### Specify options | ||
@@ -26,13 +30,9 @@ ```js | ||
//Single file | ||
//Single file or glob | ||
files: 'path/to/file', | ||
//Multiple files | ||
//Multiple files or globs | ||
files: [ | ||
'path/to/file', | ||
'path/to/other/file', | ||
], | ||
//Glob(s) | ||
files: [ | ||
'path/to/files/*.html', | ||
@@ -63,3 +63,3 @@ 'another/**/*.path', | ||
Asynchronous replacement, with promises: | ||
### Asynchronous replacement with promises | ||
@@ -76,3 +76,3 @@ ```js | ||
Asynchronous replacement, with callback: | ||
### Asynchronous replacement with callback | ||
@@ -88,7 +88,7 @@ ```js | ||
Synchronous replacement: | ||
### Synchronous replacement | ||
```js | ||
try { | ||
let changedFiles = replace.sync(options); | ||
const changedFiles = replace.sync(options); | ||
console.log('Modified files:', changedFiles.join(', ')); | ||
@@ -101,4 +101,26 @@ } | ||
Via CLI: | ||
### Return value | ||
The return value of the library is an array of file names of files that were modified (e.g. | ||
had some of the contents replaced). If no replacements were made, the return array will be empty. | ||
For example: | ||
```js | ||
const changedFiles = replace.sync({ | ||
files: 'path/to/files/*.html', | ||
from: 'a', | ||
to: 'b', | ||
}); | ||
// changedFiles could be an array like: | ||
[ | ||
'path/to/files/file1.html', | ||
'path/to/files/file3.html', | ||
'path/to/files/file5.html', | ||
] | ||
``` | ||
### CLI usage | ||
```sh | ||
@@ -118,2 +140,2 @@ replace-in-file from to some/file.js,some/**/glob.js [--isRegex] | ||
Copyright 2015-2017, [Adam Reis](http://adam.reis.nz) | ||
Copyright 2015-2017, [Adam Reis](https://adam.reis.nz) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130407
966
134