Skip to content

Like String.prototype.replace but supports asynchronous replacer.

License

Notifications You must be signed in to change notification settings

egoist/async-replace

Repository files navigation

async-replace

NPM version NPM downloads CircleCI donate chat

Like String.prototype.replace but supports asynchronous replacer.

Install

yarn add @egoist/async-replace

Usage

const replace = require('@egoist/async-replace')

replace('[foo] [bar]', /\[(.*?)\]/g, async (_, p1) => {
  await sleep(300)
  return `hi ${p1}`
}).then(str => {
  console.log(str)
  //=> 'hi foo hi bar'
})

API

replace(str, regexp, replacer)

str

  • Type: string
  • Required: true

regexp

  • Type: RegExp
  • Required: true

replacer

  • Type: function
  • Required: true

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

async-replace © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

github.com/egoist · GitHub @egoist · Twitter @_egoistlily

About

Like String.prototype.replace but supports asynchronous replacer.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages