Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
assert-types
Advanced tools
A small JavaScript library for arguments assertion. Browser and Node.JS compatible.
The main mission is to provide simple and slick API for checking arguments and throwing exceptions. Let's get rid of explicit complex conditions.
7.5 Kb unminified with comments, 3.6 Kb minified
npm install assert-types
Install dependencies
npm install && bower install
Build Project
npm run build
Run Tests
npm run test
If you're running in Node.js, you can require
assertTypes.js like so:
var assertTypes = require('assert-types');
It also supports Require.js:
require.config({
paths: {
'assert-types': 'assert-types.js/dist/assert-types.min.js'
}
});
require(['assert-types'], function(assert) {});
Also assertTypes.js could be included with an HTML <script>
tag and assertTypes
variable will be visible globally.
// Numbers
assertTypes.number(num);
assertTypes.numberPositive(num);
assertTypes.numberNegative(num);
assertTypes.numberOdd(num);
assertTypes.numberEven(num);
assertTypes.numberInt(num);
assertTypes.numberFloat(num);
assertTypes.numberRange(num, min, max);
// Equals
assertTypes.equal(value, expectedValue);
// Boolean
assertTypes.bool(value);
assertTypes.boolTrue(value);
assertTypes.boolFalse(value);
// String
assertTypes.string(value);
assertTypes.stringNotEmpty(value);
// Other
assertTypes.object(value);
assertTypes.fn(value);
assertTypes.array(value);
assertTypes.instance(value, instance);
assertTypes.nulled(value);
assertTypes.defined(value);
assertTypes.date(value);
In case if assertion is failed, assertTypes will throw Error.
Also the library has possibility to define conditions. Let's take a look here:
// These could be translated as: if value is defined then it should be a number
assertTypes.number(value, assertTypes.conditionIfDefined);
// Other examples
assertTypes.object(value, assertTypes.conditionIfDefined);
// You can define your own conditions
assertTypes.defined(value, today === 'Friday');
// Condition could be a function
assertTypes.numberPositive(value, function(value) {
return today === 'Friday' || today === 'Monday';
});
The assertion will be performed if condition is true;
FAQs
A small JavaScript library for arguments assertion
We found that assert-types 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.