Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sussycatgirl/smart-replace
https://github.com/sussycatgirl/smart-replace
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/sussycatgirl/smart-replace
- Owner: sussycatgirl
- License: mit
- Created: 2022-04-26T07:44:37.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-04-26T12:53:04.000Z (over 2 years ago)
- Last Synced: 2024-10-03T22:08:31.145Z (about 1 month ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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!
```