Giter VIP home page Giter VIP logo

simple-is's Introduction

simple-is.js

A maximally minimal type-testing library. Use it to make your code more readable. Works in node and browsers.

Usage

var is = require("simple-is");

Use is.number(x) instead of typeof x === "number" (also is.boolean, is.string, is.fn).

Use is.nan(x) instead of typeof x === "number" && isNaN(x), x !== x or ES6 Number.isNaN(x).

Use is.object(x) instead of x !== null && typeof x === "object".

Use is.primitive(x) instead of x === null || x === undefined || typeof x === "boolean" || typeof x === "number" || typeof x === "string" (verbose on purpose).

Use is.array(x) instead of ES5 Array.isArray.

Use is.finitenumber(x) instead of typeof x === "number" && isFinite(x) or ES6 Number.isFinite(x).

Use is.someof(x, ["first", 2, obj]) instead of (usually) x === "first" || x === 2 || x === obj or (alternatively) ["first", 2, obj].indexOf(x) >= 0. Great for reducing copy and paste mistake in if-conditions and for making them more readable.

Use is.noneof(x, ["first", 2, obj]) instead of (usually) x !== "first" && x !== 2 && x !== obj or (alternatively) ["first", 2, obj].indexOf(x) === -1.

Use is.own(x, "name") instead of Object.prototype.hasOwnProperty.call(x, "name").

That's it.

Installation

Node

Install using npm

npm install simple-is
var is = require("simple-is");

Browser

Clone the repo and include it in a script tag

git clone https://github.com/olov/simple-is.git
<script src="simple-is/simple-is.js"></script>

simple-is's People

Contributors

olov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.