JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 94317
  • Score
    100M100P100Q155185F
  • License MIT

Asynchronous String.prototype.replace()

Package Exports

  • string-replace-async

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (string-replace-async) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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)

string

Type: string
Required

A string to be processed.

expression

Type: regexp, string
Required

An expression to match substrings to replace.

replacer

Type: fuction, string
Required

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

License

MIT © Dmitriy Sobolev