Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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,036,542 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.