Socket
Socket
Sign inDemoInstall

checkjs

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

checkjs

Yet another value-validator in JavaScript ... Or is it?


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

check

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.

Install

npm install checkjs

Chapters:

Currently the wiki is in progress.

TODO:

See issues.

Keywords

FAQs

Package last updated on 10 Jun 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc