async-regexp-replace

String.replace with asynchronous replacer function

Usage no npm install needed!

<script type="module">
  import asyncRegexpReplace from 'https://cdn.skypack.dev/async-regexp-replace';
</script>

README

Async Regexp Replace

import { asyncRegexpReplace } from 'async-regexp-replace';

const source = 'The quick brown fox jumps over the lazy dog';
const result = await asyncRegexpReplace(source, /(brown|lazy)\s/g, async m => {
    // The replacer function can be asynchronous
    await new Promise(r => setTimeout(r, 0));
    return '';
});

// 'The quick fox jumps over the dog'