# async-replace

> Run replace on a string and update it asynchronous

Latest version **1.0.1** (published 2015-11-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-replace
pnpm add async-replace
yarn add async-replace
bun add async-replace
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-11-07 |
| First published | 2013-02-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | David Björklund |
| Maintainers | kesla |
| Keywords | string, async, replace |

## Links

- npm: https://www.npmjs.com/package/async-replace
- Repository: https://github.com/kesla/async-replace
- Homepage: https://github.com/kesla/async-replace#readme
- Issues: https://github.com/kesla/async-replace/issues
- npm.io page: https://npm.io/package/async-replace

## Dependencies (1)

- [async](https://npm.io/package/async.md) ^1.4.2

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-11-07
- 1.0.0 — 2014-06-02
- 0.0.2 — 2013-05-26
- 0.0.1 — 2013-02-20

## README

#async-replace[![build status](https://secure.travis-ci.org/kesla/async-replace.png)](http://travis-ci.org/kesla/async-replace)

Run replace on a string and update it asynchronous.

## usage

async-replace have the same api as the callback-version of `String.prototype.replace` but instead of returning the changed data another callback is called, making it possible to do asynchronous stuff in the callback.

This may sound more complicated than it is, so let's look at an example.

```js
function replacer(match, p1, p2, p3, offset, string){
    // p1 is nondigits, p2 digits, and p3 non-alphanumerics
    return [p1, p2, p3].join(' - ');
};
newString = "abc12345#$*%".replace(/([^\d]*)(\d*)([^\w]*)/, replacer);
```

Above is an example of using `String.prototype.replace` with a callback. The above could then be written in async-replace like this

```js
function replacer(match, p1, p2, p3, offset, string, done){
    // p1 is nondigits, p2 digits, and p3 non-alphanumerics
    setTimeout(function() {
        done(null, [p1, p2, p3].join(' - '));
    }, 100);
};
asyncReplace("abc12345#$*%", /([^\d]*)(\d*)([^\w]*)/, replacer, function(err, result) {
    console.log(result); // will print 'abc - 12345 - #$*%';
});
```

---
_Source: https://npm.io/package/async-replace · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
