Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
simple-swizzle
Advanced tools
The simple-swizzle npm package is a utility for handling argument swizzling. It allows developers to manipulate and reorder function arguments easily, which can be particularly useful in scenarios where functions expect arguments in a specific order or format.
Swizzle function arguments
This feature allows developers to reorder the arguments of a function dynamically. The example shows how to use simple-swizzle to create a new function where the order of arguments can be changed by passing an array.
const swizzle = require('simple-swizzle');
function originalFunction(a, b, c) {
console.log(a, b, c);
}
const swizzledFunction = swizzle(originalFunction);
swizzledFunction('first', 'second', 'third'); // Logs: first, second, third
swizzledFunction(['second', 'third', 'first']); // Logs: second, third, first
Lodash is a comprehensive utility library that offers similar functionalities through methods like _.rearg, which creates a function that invokes the provided function with arguments arranged according to the specified indexes. Compared to simple-swizzle, lodash is more extensive and includes a wide range of utilities beyond argument manipulation.
The rearg package is specifically focused on rearranging function arguments, similar to simple-swizzle. It provides a straightforward approach to argument reordering but does not include the broader utility context that simple-swizzle might be used in conjunction with.
Swizzle your function arguments; pass in mixed arrays/values and get a clean array
var swizzle = require('simple-swizzle');
function myFunc() {
var args = swizzle(arguments);
// ...
return args;
}
myFunc(1, [2, 3], 4); // [1, 2, 3, 4]
myFunc(1, 2, 3, 4); // [1, 2, 3, 4]
myFunc([1, 2, 3, 4]); // [1, 2, 3, 4]
Functions can also be wrapped to automatically swizzle arguments and be passed the resulting array.
var swizzle = require('simple-swizzle');
var swizzledFn = swizzle.wrap(function (args) {
// ...
return args;
});
swizzledFn(1, [2, 3], 4); // [1, 2, 3, 4]
swizzledFn(1, 2, 3, 4); // [1, 2, 3, 4]
swizzledFn([1, 2, 3, 4]); // [1, 2, 3, 4]
Licensed under the MIT License. You can find a copy of it in LICENSE.
FAQs
Simply swizzle your arguments
We found that simple-swizzle 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.