Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
A lightweight library to help developers catch bugs before they skitter in by making sure the right types of arguments are being passed into functions and methods.
arg-check is a lightweight library to help developers catch bugs before they skitter in by making sure the right types of arguments are being passed into functions and methods.
It takes two arguments: (1) an argument you've passed into a function declaration, and (2) the type you expect that argument to be. It couldn't be easier:
let argCheck = require('arg-check');
let add = (a, b) => {
argCheck(a, 'number');
argCheck(b, 'number');
return a + b;
};
add(3, 4); // 7
add(3, 'four'); // TypeError: Expected argument to be of type "number" but instead received type "string"
In the terminal:
$ npm install arg-check
In path/to/my/rad/app/or/whatever/app.js:
let argCheck = require('arg-check');
Really, that's it. Start arg-checking!
Note all argument types are lowercase strings.
'null'
'undefined'
'string'
'number'
'boolean'
'array'
'object'
argCheck also supports custom class types:
class Person {
constructor(attributes) {
this.name = attributes.name;
}
}
let rachael = new Person({ name: 'Rachael' });
let personName = (person) => {
argCheck(person, 'person');
return person.name;
};
personName(rachael); // 'Rachael'
personName({ name: 'Rachael' }) // TypeError: Expected argument to be of type "person" but instead received type "object"
Note again that the expected class name will be a lowercase string.
We'd love contributors and feedback! We are currently at 100% test coverage and that's the way we like it. Hit us up and let's make this thing even better.
arg-check is released under the MIT License
FAQs
A lightweight library to help developers catch bugs before they skitter in by making sure the right types of arguments are being passed into functions and methods.
The npm package arg-check receives a total of 0 weekly downloads. As such, arg-check popularity was classified as not popular.
We found that arg-check 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.