reduce-function-call
Reduce function calls in a string, using a callback
Professionally supported reduce-function-call is now available
Installation
npm install reduce-function-call
Usage
var reduceFunctionCall = require("reduce-function-call")
reduceFunctionCall("foo(1)", "foo", function(body) {
return parseInt(body, 10) + 1
})
var nothingOrUpper = function(body, functionIdentifier) {
if (body === "") {
return functionIdentifier + "()"
}
return body.toUpperCase()
}
reduceFunctionCall("bar()", "bar", nothingOrUpper)
reduceFunctionCall("upper(baz)", "upper", nothingOrUpper)
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
}
})
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", "!")
}
See unit tests for others examples.
Contributing
Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.
git clone https://github.com/MoOx/reduce-function-call.git
git checkout -b patch-1
npm install
npm test
Security contact information
To report a security vulnerability, please use the
Tidelift security contact. Tidelift will
coordinate the fix and disclosure.