https://github.com/butonly/string-replacer
asynchronous/synchronous string replace
https://github.com/butonly/string-replacer
async-replace regexp string string-manipulation string-replace
Last synced: 10 months ago
JSON representation
asynchronous/synchronous string replace
- Host: GitHub
- URL: https://github.com/butonly/string-replacer
- Owner: butonly
- Created: 2016-03-13T09:47:19.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-18T05:09:52.000Z (almost 10 years ago)
- Last Synced: 2025-03-11T20:47:08.086Z (11 months ago)
- Topics: async-replace, regexp, string, string-manipulation, string-replace
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
string-replacer
===============
### strReplacer#replace
* `str` - target string to be replace.
* `regexp` - A RegExp object.
* `iterator` - A function to be invoked to create the new substring.
```js
let content = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let reg = /[A-Y]/g;
let str = strSplicer.replace(content, new RegExp(reg), (match)=> {
// match is the result of RegExp(reg).exec()
return match[0] + '-';
});
// str: A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z
```
### strReplacer#replaceAsync
* `str` - target string to be replace.
* `regexp` - A RegExp object.
* `iteratorAsync` - A function to be invoked with the new substring callback.
* `done` - invoked until no more substring matches by `regexp` in `str`
```js
let content = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let reg = /[A-Y]/g;
strSplicer.replaceAsync(content, new RegExp(reg), iteratorAsync(match, cb)=> {
// match is the result of RegExp(reg).exec()
cb(null, match[0] + '-');
}, (err, str)=> {
// err: null
// str: A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z
});
```