1.0.2 • Published 6 years ago

@egoist/async-replace v1.0.2

Weekly downloads
12
License
MIT
Repository
github
Last release
6 years ago

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')

const newString = replace('[foo] [bar]', /\[(.*?)\]/g, async (_, p1) => {
  await sleep(300)
  return `hi ${p1}`
})
//=> '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

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.0

6 years ago