New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

string-replace-async

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-replace-async

Asynchronous String.prototype.replace()

1.2.1
Source
npm
Version published
Weekly downloads
73K
-5.39%
Maintainers
1
Weekly downloads
 
Created
Source

string-replace-async Build Status

Asynchronous String.prototype.replace()

Install

$ npm install --save string-replace-async

Usage

const stringReplaceAsync = require('string-replace-async');
const ghUser = require('gh-user');

function replacer(match, login) {
	return ghUser(login).then(user => user.name);
}

stringReplaceAsync('Sup, {dsblv}', /{([^}]*)}/g, replacer)
	.then(console.log);
//=> 'Sup, Dimzel Sobolev'

API

The API is basically the same as String.prototype.replace(), except the first argument is a string itself.

stringReplaceAsync(string, expression, replacer)

Invokes replacers concurrently, returns a promise that resolves to processed string.

stringReplaceAsync.seq(string, expression, replacer)

Invokes replacers sequentially, returns a promise that resolves to processed string.

string

Type: string
Required

A string to be processed.

expression

Type: regexp, string
Required

An expression to match substrings to replace.

replacer

Type: function, string
Required

A function that takes several arguments and returns a promise. Resolved value will be used as replacement string.

License

MIT © Dmitriy Sobolev

Keywords

string

FAQs

Package last updated on 20 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts