Skip to main content

Asynchronous string replacement with concurrency limiting.

Works with
This package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
3 weeks ago (1.0.6)

async-replace Build Status

Install

npm install --save @tugrul/async-replace

Sample

const {replace} = require('@tugrul/async-replace');

const text = 'the [example.com] website is the best website but [example.org] is better one';
const pattern = /\[([^\]]+)\]/g

// concurrency limiting to avoid resource saturation
const limit = 5;

async function addStatusCode(text) {

    return replace(text, pattern, async(match, [domain]) => {
        
        const {status} = await fetch('https://' + domain);

        return '[' + domain + ' (' + status + ')]';
    }, limit);

}

// the [example.com (200)] website is the best website but [example.org (200)] is better one
addStatusCode(text).then(result => console.log(result));
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @tugrul/async-replace

Import symbol

import * as mod from "@tugrul/async-replace";

Add Package

npx jsr add @tugrul/async-replace

Import symbol

import * as mod from "@tugrul/async-replace";

Add Package

yarn dlx jsr add @tugrul/async-replace

Import symbol

import * as mod from "@tugrul/async-replace";

Add Package

pnpm dlx jsr add @tugrul/async-replace

Import symbol

import * as mod from "@tugrul/async-replace";

Add Package

bunx jsr add @tugrul/async-replace

Import symbol

import * as mod from "@tugrul/async-replace";