Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sussycatgirl/smart-replace


https://github.com/sussycatgirl/smart-replace

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# smart-replace

Searches a string by regex and lets you replace every occurrence by executing a matcher function.

## Usage

```js
import { smartReplace } from 'smart-replace';

const oldStr = 'Among us sus1 sus2 sus3 sus4';
const regex = /sus[0-9]+/g;
const newStr = await smartReplace(oldStr, regex, async (match) => {
return "sussy!";
});

console.log(newStr); // Among us sussy! sussy! sussy! sussy!
```