Skip to content

Repository files navigation

reduce-function-call Build Status

Reduce function calls in a string, using a callback


Professionally supported reduce-function-call is now available


Installation

npm install reduce-function-call

Usage

varreduceFunctionCall=require("reduce-function-call")reduceFunctionCall("foo(1)","foo",function(body){// body === "1"returnparseInt(body,10)+1})// "2"varnothingOrUpper=function(body,functionIdentifier){// ignore empty valueif(body===""){returnfunctionIdentifier+"()"}returnbody.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{returneval(body)}catch(e){returncall}})// "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"}returnfunctionIdentifier.replace("bla","!")}// "sha bla !h blaa ABRACADABRA a! aabla() blaaa()"

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.gitgit checkout -b patch-1npm installnpm test


Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

About

Reduce function calls in a string, using a callback

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages