Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
This library helps you to make your methods more flexible by managing arguments list. Just use one of wrappers to define your method. Wrapper prepares arguments list due to described pattern and calls your original method.
If you define method, which takes list of arguments of different types, you can let caller to pass them in accidental order. Use wrapper reorder to define such method. It reorders arguments for you before call original method.
###E.g. You have to get three arguments of different types: number, string and boolean.
var myMethod = rearg.reorder('nsb', function(num, str, b) {
console.log(num, str, b);
});
Now you can call your method in any way. Original method will be called with arguments list ordered in right way.
myMethod('aa', false, 5);
// [5, "aa", false]
myMethod(true, 'aa', 7);
// [7, "aa", true]
myMethod('456');
// [undefined, "456", undefined]
###Notice If you use type "O" (any Object), you can't use types "d" (Date), "r" (RegExp), "a" (Array) or "o" (other Object) in pattern, because they might be also interpreted as "O" (any Object). But you may use them with "o" (other Object) there. Anyway, you caught the error if you try to define method with collisions in pattern. (see Symbols in patterns)
Extend wrapper is used when you want to keep original order of arguments, but you want let caller to miss some of them. Just use question mark after optional params in pattern. This wrapper throws error, if passed arguments couldn't be interpreted due to pattern.
###E.g.
var myMethod = rearg.expand('nss?s?f', function(num, s1, s2, s3, f) {
console.log(arguments);
});
In this example third and fourth arguments (s2 and s3) aren't required and caller might miss them. Wrapper will replace them by undefined in that case.
myMethod(2, 'a', 'b', 'c', function() {});
// [2, "a", "b", "c", function]
myMethod(2, 'a', 'b', function() {});
// [2, "a", "b", undefined, function]
myMethod(2, 'a', function() {});
// [2, "a", undefined, undefined, function]
myMethod(2, function() {});
// throws error as second argument is required by pattern and should be string
###Notice You can define optional arguments in sequence with required arguments of the same type only when optional arguments placed in the end of this sequence. It means you can't define pattern like "s?ssn" or "ss?sn". You can define it like "sss?n" and let only last string argument be optional. The same story with type "O" (any Object) in conjunction with any of types "d" (Date), "r" (RegExp), "a" (Array) or "o" (other Object), if you use them in sequence. But it's ok with type "o" (other Object). (see Symbols in patterns)
n - number
s - string
b - boolean
f - function
O - any Object
a - Array
d - Date
r - RegExp
o - other Object (object which isn't Array, Date or RegExp)
The most interesting is type "O". Because any javaScript value (except undefined) might be strongly recognized as one of the other types. But arrays, dates, regular expressions and other objects are also recognized as "O" (any Object). That's why there are some restrictions to use type "O", described in notices for reorder and expand methods.
npm install rearg
var rearg = require('rearg');
MIT
FAQs
JavaScript library for managing your functions arguments
The npm package rearg receives a total of 0 weekly downloads. As such, rearg popularity was classified as not popular.
We found that rearg 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.