Tweaks to readme

This commit is contained in:
Adam Reis
2018-03-22 11:47:57 +13:00
parent d94c3aaa49
commit 5e64df1c89
2 changed files with 6 additions and 8 deletions

View File

@@ -198,7 +198,7 @@ You can also specify a callback that returns a string or a regular expression. T
```js
const options = {
files: 'path/to/file',
from: (file) => RegExp(`${foo('SomePattern[A-Za-z-]+', file)}`, g);,
from: (file) => new RegExp(file, 'g'),
to: 'bar',
};
```
@@ -220,10 +220,7 @@ This callback provides for an extra argument above the String replace method, wh
const options = {
files: 'path/to/file',
from: /SomePattern[A-Za-z-]+/g,
to: (...args) => {
const file = args.pop();
return file;
},
to: (...args) => args.pop(),
};
```

View File

@@ -28,8 +28,8 @@ module.exports = function makeReplacements(contents, from, to, file) {
//Make replacements
from.forEach((item, i) => {
//`from` callback is called with a filename argument
//and returns string or regexp
//Call function if given, passing the filename
if (typeof item === 'function') {
item = item(file);
}
@@ -39,9 +39,10 @@ module.exports = function makeReplacements(contents, from, to, file) {
if (replacement === null) {
return;
}
//Call function if given, appending the filename
if (typeof replacement === 'function') {
const original = replacement;
//`to` callback is called with an additional filename argument
replacement = (...args) => original(...args, file);
}