explaingit

arasatasaygin/is.js

9,084JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A tiny JavaScript utility library that replaces scattered typeof checks and regex tests with one clean API for validating value types, formats, and environment details.

Mindmap

mindmap
  root((is.js))
    What it does
      Type checking
      Format validation
      Env detection
    Check types
      Array string number
      null undefined NaN
      DOM element
    Format checks
      Email URL IP
      Credit card
    Interfaces
      plain not
      all any
    Use cases
      Form validation
      Function guards
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Validate user input formats like email, URL, or credit card number before submitting a form.

USE CASE 2

Guard a function by checking all its arguments are the expected types in one readable line.

USE CASE 3

Detect the browser, OS, or device type at runtime to load features conditionally.

Tech stack

JavaScript

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

is.js is a small JavaScript library for checking what kind of value a variable holds. It has no dependencies and works in browsers, in Node.js, and with AMD-style module loaders, so it drops into almost any JavaScript project without friction. The library covers a wide range of checks in one consistent style. You can ask whether something is an array, a string, a number, a date, a function, a regular expression, null, undefined, NaN, a DOM element, or the browser window object. There are also checks for whether a value is empty, whether a number falls within a certain range, whether a string matches a particular format (email, URL, credit card number, IP address, and more), and whether the code is running on a particular browser, operating system, or device type. Every check comes with three extra interfaces built in. The plain call tests a single value. The not version inverts the result, so is.not.array('foo') returns true because 'foo' is not an array. The all version tests multiple values and returns true only if every one of them passes. The any version returns true if at least one of them passes. Both all and any can accept either a list of arguments or a single array. The goal is to replace scattered typeof checks, length comparisons, and regular expression tests spread across a codebase with a single readable library call. Rather than writing multi-step conditional logic to confirm a value's type or format, a developer writes one descriptive line. The checks themselves handle the edge cases, such as the fact that NaN has type 'number' in plain JavaScript, or that arrays report as 'object' with typeof. The README is a long catalog of available checks with short code examples for each one. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Using is.js, write a JavaScript form validator that checks email is a valid email, age is a number between 18 and 120, and username is a non-empty string.
Prompt 2
With is.js, write a reusable guard function that throws a TypeError if any argument in a given list is not a number.
Prompt 3
Using is.js, detect whether the visitor is on a mobile device running iOS and show a different banner message than for Android or desktop users.
Open on GitHub → Explain another repo

← arasatasaygin on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.