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.
typeof-arguments
Advanced tools
typeof-arguments
is a module that validates arguments' types passed to the enclosing function.
npm install typeof-arguments
var args = require('typeof-arguments');
args(arguments,types[,callback])
arguments
[Object]arguments
objecttypes
[Array] of [String] items.'null'
, 'undefined'
, or any value equal to contructor.name
, eg. 'string'
, 'number'
, 'regexp'
, 'array'
, 'object'
, 'boolean'
.'String'
, 'string'
, 'StRiNg'
checks if the argument is of type [String]''
or 'any'
, then the argument can be of any type|
, eg: 'array|object'
, 'boolean|number|null|undefined'
, string|number
var args = require('typeof-arguments');
hello('hello', "world!");
function hello(paramA,paramB){
args(arguments,['string','string']);
}
callback
[Function] (optional)Invalid argument. The [String] argument has been passed, while the [Number] one is expected.
actual
[String] and expected
[String] is passed to the callback function. The parameter actual
indicates the actual type of the argument passed to the enclosing function, eg '[String]'
, when the expected
parameter indicates the type(s) expected by the user, eg. '[Array]'
, '[Boolean|Number]'
.var args = require('typeof-arguments');
hello(10, "hello!");
function hello(paramA,paramB){
args(arguments,['any','string|number'],(actual,expected)=>{
console.log(new Error(`Not good! You passed ${actual}, when you should have passed ${expected}.`));
});
}
The function args()
returns true
when all arguments passed to the enclosing function are of valid types.
The function args()
returns false
when at least one of the arguments passed to the enclosing function is of invalid type.
var args = require('typeof-arguments');
hello("hello","world!");
function hello(paramA,paramB){
var areValid = args(arguments,['string','string']);
if(!areValid) return; //stop executing code if at least one argument is of invalid type
return paramA + " " + paramB;
}
var args = require('typeof-arguments');
function hello(paramA,paramB,paramC){
args(arguments,['number|string','any','null|array']);
}
hello("hello", "it's me!", null);
//no errors
hello(10, 20, [1,2,3]);
//no errors
hello(true,20,null);
//Invalid argument. The [Boolean] argument has been passed, while the [Number|String] one is expected.
hello({name:'Paul'},false,/test/);
//Invalid argument. The [Object] argument has been passed, while the [Number|String] one is expected.
//Invalid argument. The [RegExp] argument has been passed, while the [Null|Array] one is expected.
hello(10,20,null,30,40,50,60,70);
//no errors
hello(10);
//Invalid argument. The [undefined] argument has been passed, while the [Null|Array] one is expected.
FAQs
Validate the type of arguments passed through the function.
The npm package typeof-arguments receives a total of 3,809 weekly downloads. As such, typeof-arguments popularity was classified as popular.
We found that typeof-arguments 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.