Socket
Socket
Sign inDemoInstall

reduce-function-call

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    reduce-function-call

Reduce function calls in a string, using a callback


Version published
Weekly downloads
1.1M
increased by5.5%
Maintainers
1
Install size
14.4 kB
Created
Weekly downloads
 

Readme

Source

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

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

Changelog

License


Security contact information

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

Keywords

FAQs

Last updated on 12 Sep 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc