diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/reduce-function-call/README.md | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/reduce-function-call/README.md')
| -rwxr-xr-x | node_modules/reduce-function-call/README.md | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/node_modules/reduce-function-call/README.md b/node_modules/reduce-function-call/README.md new file mode 100755 index 00000000..cc3dac9a --- /dev/null +++ b/node_modules/reduce-function-call/README.md @@ -0,0 +1,71 @@ +# reduce-function-call [](https://travis-ci.org/MoOx/reduce-function-call) + +> Reduce function calls in a string, using a callback + +## Installation + +```bash +npm install reduce-function-call +``` + +## Usage + +```js +var reduceFunctionCall = require("reduce-function-call") + +reduceFunctionCall("foo(1)", "foo", function(body) { + // body === "1" + return parseInt(body, 10) + 1 +}) +// "2" + +var nothingOrUpper = function(body, functionIdentifier) { + // ignore empty value + if (body === "") { + return functionIdentifier + "()" + } + + return body.toUpperCase() +} + +reduceFunctionCall("bar()", "bar", nothingOrUpper) +// "bar()" + +reduceFunctionCall("upper(baz)", "upper", nothingOrUpper) +// "BAZ" + +reduceFunctionCall("math(math(2 + 2) * 4 + math(2 + 2)) and other things", "math", function(body, functionIdentifier, call) { + try { + return eval(body) + } + catch (e) { + return call + } +}) +// "20 and other things" + +reduceFunctionCall("sha bla blah() blaa bla() abla() aabla() blaaa()", /\b([a-z]?bla[a-z]?)\(/, function(body, functionIdentifier) { + if (functionIdentifier === "bla") { + return "ABRACADABRA" + } + return functionIdentifier.replace("bla", "!") +} +// "sha bla !h blaa ABRACADABRA a! aabla() blaaa()" +``` + +See [unit tests](test/index.js) for others examples. + +## Contributing + +Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature. + +```bash +git clone https://github.com/MoOx/reduce-function-call.git +git checkout -b patch-1 +npm install +npm test +``` + +## [Changelog](CHANGELOG.md) + +## [License](LICENSE-MIT) |
