Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @philipp122/type with all npm packages installed. Try it out:

var type = require("@philipp122/type")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@philipp122/type v1.1.1

Better Type Checking

Type

This Project adds better type checking from basic JS types.

Installation

npm install --save @philipp122/type

Usage:

Type supports 14 primitive JS Types: Undefined, Null, Boolean, Number, NaN, Infinity, String, Symbol, Array, Object, WeakSet, Set, WeakMap and Map as well as 2 aliases of Number: Integer and Float.

Any value can be checked against those types:

const Type = require('@philipp122/type');

// ALL of the following return true
console.log(undefined instanceof Type.Undefined);
console.log(null instanceof Type.Null);
console.log(true instanceof Type.Boolean);
console.log(5 instanceof Type.Number);
console.log(5 instanceof Type.Integer);
console.log(5.5 instanceof Type.Number);
console.log(5.5 instanceof Type.Float);
console.log(Infinity instanceof Type.Infinity);
console.log(NaN instanceof Type.NaN);
console.log("Hello World" instanceof Type.String);
console.log(Symbol("Bye") instanceof Type.Symbol);
console.log([1, 2, 3] instanceof Type.Array);
console.log({a: 1, b: 2} instanceof Type.Object);
console.log(new WeakSet() instanceof Type.WeakSet);
console.log(new Set() instanceof Type.Set);
console.log(new WeakMap() instanceof Type.WeakMap);
console.log(new Map() instanceof Type.Map);

See index.test.js for more examples.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free