BT

Is.js Offers Simple Way to Check Data

| by David Iffland Follow 4 Followers on Feb 10, 2015. Estimated reading time: 1 minute |

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 Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT