Skip to content

butonly/string-replacer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.
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
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
});

Releases

No releases published

Packages

No packages published