string-replace
Asynchronous String.prototype.replace, sequential or parallel
Last updated 5 years ago by eush77 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install string-replace 
SYNC missed versions from official npm registry.

npm

string-replace

Build Status Dependency Status

Asynchronous version of String.prototype.replace.

Example

stringReplace('name: {name}, value: {value}', /\{([^}]+)\}/g, replace,
              function done(err, result) {
  if (err) throw err;
  console.log(result);
});

function replace(cb, match, key) {
  // Do some async stuff here.
  // Arguments to this function are almost the same as for String.prototype.replace.
  // Except for the callback.
  // ...
  cb(null, value);
}

API

stringReplace(string, pattern, replacer(cb, match, ...), [opts], cb(err, result))

Applies String.prototype.replace asynchronously.

Replaces all occurences of pattern (regexp or string) in a string with invocations of replacer function. Functionally equivalent to string.replace(pattern, replacer(match, ...)) but replacer has to return value by calling cb.

Replacers are firing in sequence unless opts.parallel is set to true.

Install

npm install string-replace

License

MIT

Current Tags

  • 0.2.0                                ...           latest (5 years ago)

4 Versions

  • 0.2.0                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |