
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
reduce-function-call
Advanced tools
The reduce-function-call npm package allows you to reduce the arguments of a function call within a string. This can be particularly useful for processing CSS functions or other string-based function calls.
Reduce CSS function calls
This feature allows you to reduce the arguments of CSS function calls. In this example, the `calc` function call is reduced to a simpler form.
const reduceFunctionCall = require('reduce-function-call');
const input = 'calc(100% - 50px)';
const output = reduceFunctionCall(input, 'calc', (body) => {
return '50%';
});
console.log(output); // 'calc(50%)'
Custom function call reduction
You can use this feature to reduce custom function calls within a string. In this example, the `myFunc` function call is reduced to a single argument.
const reduceFunctionCall = require('reduce-function-call');
const input = 'myFunc(1, 2, 3)';
const output = reduceFunctionCall(input, 'myFunc', (body) => {
return '4';
});
console.log(output); // 'myFunc(4)'
The postcss-calc package is a PostCSS plugin that reduces calc() references in CSS. It is specifically designed for CSS and provides more advanced optimizations for calc() functions compared to reduce-function-call.
cssnano is a modular minifier for CSS that includes a variety of optimizations, including reducing calc() functions. It offers a broader range of CSS optimizations beyond just function call reductions.
Reduce function calls in a string, using a callback
Professionally supported reduce-function-call is now available
npm install reduce-function-call
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.
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
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
FAQs
Reduce function calls in a string, using a callback
The npm package reduce-function-call receives a total of 1,129,287 weekly downloads. As such, reduce-function-call popularity was classified as popular.
We found that reduce-function-call demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.