Skip to content

Commit 5e64df1

Browse files
committed
Tweaks to readme
1 parent d94c3aa commit 5e64df1

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ You can also specify a callback that returns a string or a regular expression. T
198198
```js
199199
const options = {
200200
files: 'path/to/file',
201-
from: (file) => RegExp(`${foo('SomePattern[A-Za-z-]+', file)}`, g);,
201+
from: (file) => new RegExp(file, 'g'),
202202
to: 'bar',
203203
};
204204
```
@@ -220,10 +220,7 @@ This callback provides for an extra argument above the String replace method, wh
220220
const options = {
221221
files: 'path/to/file',
222222
from: /SomePattern[A-Za-z-]+/g,
223-
to: (...args) => {
224-
const file = args.pop();
225-
return file;
226-
},
223+
to: (...args) => args.pop(),
227224
};
228225
```
229226

lib/helpers/make-replacements.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ module.exports = function makeReplacements(contents, from, to, file) {
2828

2929
//Make replacements
3030
from.forEach((item, i) => {
31-
//`from` callback is called with a filename argument
32-
//and returns string or regexp
31+
32+
//Call function if given, passing the filename
3333
if (typeof item === 'function') {
3434
item = item(file);
3535
}
@@ -39,9 +39,10 @@ module.exports = function makeReplacements(contents, from, to, file) {
3939
if (replacement === null) {
4040
return;
4141
}
42+
43+
//Call function if given, appending the filename
4244
if (typeof replacement === 'function') {
4345
const original = replacement;
44-
//`to` callback is called with an additional filename argument
4546
replacement = (...args) => original(...args, file);
4647
}
4748

0 commit comments

Comments
 (0)