BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Is.js Offers Simple Way to Check Data

Is.js Offers Simple Way to Check Data

This item in japanese

Amid huge JavaScript frameworks that do everything a developer could possibly need rises the micro-library is.js. It offers over 100 data checks in a small, convenient package.

"I wrote the checks that I would use on my daily development process," says Aras Atasaygin, the creator of is.js. To use it, just drop the is.min.js file (13K minified) into a project and ask a question:

is.capitalized("Yes it is");

So far, there's a wide variety of checks available ranging from type checks like is.function() to date checks such as is.inNextYear(). More than 100 different type, presence, regexp, string, arithmetic, and environment checks are currently available with more to come. Some checks are more reliable than others. For example, the email regular expression is notoriously difficult to get completely right as is determining if the browser is in daylight savings time.

Beyond the simple checks, is.js also includes check adapters like all and any which, when used with multiple parameters, check to see if all of the parameters pass or any of them do, respectively. Developers can also use the not to reverse the check.

None of the included checks is very complicated and likely many devs have created their own one-off check libraries to suit their specific needs, but using is.js might save developers time. One of the larger sections is the set of RegEx checks and a number of common ones are included by default. For example, to check that a string is a url:

is.url("http://www.infoq.com");

In the code, many of the checks are based on regular expressions (static strings) and therefore can't be minimized, so the library will risk becoming bloated as new checks are added. Atasaygin says that he listening to suggestions from contributors and may add modularity if people want it.

"I'm currently adding new checks from pull requests and listening the community for the next move," says Atasaygin. The project is on GitHub.

Rate this Article

Adoption
Style

BT