npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-is

v0.5.3

Published

simplified descriptive type testing library

Downloads

44

Readme

is.js v0.5.2 Build Status

simplified descriptive type testing library

NPM

Supporting Node, AMDs and the browsers ( IE 6+, Chrome 1+, Firefox 3.6+, Opera 12.1+, Safari 5.1+ )


Usage

node.js

Install node-is as dependency using npm in the command line

> npm install node-js --save

Include the module in your projects javascript file

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

Browser

Download the code from Github: is.min.js

Include it in your project

<script src="path/to/is.min.js" type="text/Javascript"></script>

Test functions, returning true, when type is matching

  • is.Number(1) test for numbers
  • is.Integer(1) test for integers
  • is.Float(.001) test for floating point numbers
  • is.Negative(-1.5) test for negative values
  • is.Positive(1.5) test for positive values
  • is.NaN(NaN) test for NaN (isNaN link)
  • is.Finite(1) test for finite values (isFinite link)
  • is.Infinity(Infinity) test for Infinity and -Infinity
  • is.Boolean(false) test for boolans
  • is.True(true) test for true booleans
  • is.False(false) test for false booleans
  • is.String("is") test for strings
  • is.EmptyString("") test for empty strings
  • is.Undefined(undefined) test for undefined
  • is.Defined({}) (!is.Undefined)
  • is.Null(null) test for null
  • is.Function(function() {}) test for functions
  • is.Array([]) test for arrays
  • is.EmptyArray([]) test for empty arrays
  • is.RegExp(/^/g) test for regular expressions
  • is.Object({}) test for objects
  • is.RealObject({}) tests for real objects, null, arrays, regular expressions and errors will return false
  • is.Error(new Error()) test for errors
  • is.ReferenceError(new ReferenceError()) test for reference errors
  • is.TypeError(new TypeError()) test for type errors
  • is.SyntaxError(new SyntaxError()) test for syntax errors
  • is.URIError(new URIError()) test for uri errors
  • is.EvalError(new EvalError()) test for eval errors
  • is.RangeError(new RangeError()) test for range errors
  • is.RealError(new Error()) test for real Error-objects only, will not match RangeError, EvalError, URIError, SyntaxError, TypeError, ReferenceError

Multitest function is.type.of(obj1[, obj2[, obj3[, ...]]])

returns two testing functions:

  • equal() which can be used to test for various types that have to match all, e.g.: is.type.of(1,0).equal("Number","Integer","!Negative"); // returns true
  • either() to test for various types, where at least one has to match, e.g.: is.type.of(1,0,2).either("Float","Integer"); //returns true

equal() and either() can be used to test with custom functions too: is.type.of("hello", "world").equal("String", "!EmptyString", function(elm) { return elm[3]==="l"; }); //returns true


Use with mocha is.expect

You can now check types for your tests with mocha. Example:

var expect = require("node-is").expect;

describe("moche with node-is example", function() {
    it("is easy and awesome", function() {
            expect.type.of(1).to.be.equal("Integer", "Positive");
            expect.type.of(-1).to.be.either("Positive", "Negative");
    });
});

Extend is.js using custom test functions is.extend(name, fn)

Parameters:

  • name {String} test name, the function will be registered to is.<name>
  • fn {Function} test function, should accept one argument and return a Boolean

Example:

// register
is.extend("HelloWorld", function(value) {
    return is.String(value) && value === "Hello, World!";
});

// use
is.HelloWorld("Hello, World!"); // returns true
is.HelloWorld("Hello, Earth!"); // returns false

Changelog:

  • 0.5.2 Bower release
  • 0.5.1 Bug fix on global object (browser), added is.EmptyArray, some small improvements
  • 0.5.0 Added is.extend
  • 0.4.1 Bug fix on error type testing, and some small fixes
  • 0.4.0 Rewrote library in ES6, compiled using grunt-traceur
  • 0.3.2 Performance optimization, added usage section to README, added detailed support information
  • 0.3.1 bug fix #1
  • 0.3.0 Added mocha support is.expect
  • 0.2.0 is.type.of can now test an unlimited amount of arguments is.type.of(..).equal() and is.type.of(..).either() can now test custom functions too
  • 0.1.1 Added travis test
  • 0.1.0 initial version

License:

MIT