Asynchronous string replace with support for async callbacks.
TypeScript
async-replace
Install
npm install --save @tugrul/async-replace
Sample
const{replace}=require('@tugrul/async-replace');consttext='the [example.com] website is the best website but [example.org] is better one';constpattern=/\[([^\]]+)\]/g// concurrency limiting to avoid resource saturationconstlimit=5;asyncfunctionaddStatusCode(text){returnreplace(text,pattern,async(match,[domain])=>{const{status}=awaitfetch('https://'+domain);return'['+domain+' ('+status+')]';},limit);}// the [example.com (200)] website is the best website but [example.org (200)] is better oneaddStatusCode(text).then(result=>console.log(result));