Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
check (or checkjs) is a library of various validation methods.
// somewhere in the code
let numbers = [8, 11, -5, 32];
if (check.every(numbers).isPositive())
doSomething(); // this does not happen
It allows you to keep your code clean and vastly increases its readability.
if (check(myArray).includes(input))
myArray.splice(myArray.indexOf(input), 1);
else if (check.isArray(input))
myArray.push(...input);
else myArray.push(input);
It has become much easier to do the same type of tests over the array of elements.
// a long time ago
for (var i = 0; i = objects.length; i++)
if (objects[i] instanceof InvalidObject)
throw new Error("The object is invalid");
// more recently
for (let object of objects)
if (object instanceof InvalidObject)
throw new Error("The object is invalid");
// now
if (check.any(objects).is(InvalidObject))
throw new Error("The object is invalid");
The most of checkings could be done in a single line with check
.
// how did you use it
if (!app.profile || !app.profile.person || !app.profile.person.age)
throw new TypeError("Cannot find the age property");
else if (app.profile.person.age < 5 || app.profile.person.age > 42)
throw new RangeError("The age is not in range");
// maybe even like this
try {
if (app.profile.person.age < 5 || app.profile.person.age > 42)
throw new RangeError("The age is not in range");
}
catch(error) {
if (!(error instanceof RangeError))
throw new TypeError("Cannot find the age property");
}
// how will you use it in future
if (check(app).noprop(["profile", "person", "age"]))
throw new TypeError("Cannot find the age property");
else if (check(app.profile.person.age).isNotInRange([5, 42]))
throw new RangeError("The age is not in range");
check
is constantly evolving. You may suggest or ask for new method in issues if you haven't found it in the check
.
npm install checkjs
Currently the wiki is in progress.
See issues.
FAQs
Yet another value-validator in JavaScript ... Or is it?
The npm package checkjs receives a total of 1 weekly downloads. As such, checkjs popularity was classified as not popular.
We found that checkjs 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.