SlimIO is (JavaScript Primitives & Objects type checker)
npm install @slimio/isNode.js JavaScript Type checker (Primitives, Objects, etc..)
Package heavily inspired by @sindresorhus/is. This package aims to work on Node.js (no browser support).
- Focus on type checking (no fancy feature).
- Focus on Node.js support.
- Come with a TypeScript definition (which works).
- Is concerned about being stable.
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
``bash`
$ npm i @slimio/isor
$ yarn add @slimio/is
`js
const { strictEqual } = require("assert");
const is = require("@slimio/is");
strictEqual(is.bool(true), true);
strictEqual(is.string("hello"), true);
strictEqual(is.map(new Map()), true);
strictEqual(is.func(() => {}), true);
`
The is const namespace is a Plain JavaScript Object with a lot of exported methods (check the below API Documentation).
All methods can be called as follow: is.{methodName}. All methods return a boolean value.
| method | example |
| --- | --- |
| string | is.string("hello") |is.number(10)
| number | |is.boolean(true)
| boolean | |is.bool(false)
| bool | |is.symbol(Symbol("foo"))
| symbol | |is.undefined(undefined)
| undefined | |is.bigint(50n)
| bigint | |is.nullValue(null)
| nullValue | |is.nullOrUndefined(null)
| nullOrUndefined | |is.primitive("hello")
| primitive | |
> is.null is not available because of a name restriction.
| method | example |
| --- | --- |
| promise | is.promise(new Promise()) |is.classObject(new Class{})
| classObject | |is.array([])
| array | |is.object({})
| object | |is.plainObject(Object.create(null))
| plainObject | |is.set(new Set())
| set | |is.map(new Map())
| map | |is.weakMap(new WeakMap())
| weakMap | |is.weakSet(new WeakSet())
| weakSet | |is.error(new Error("ooppss!"))
| error | |is.date(new Date())
| date | |is.regExp(/^hello world$/)
| regExp | |is.buffer(Buffer.from("hello"))
| buffer | |
> is.class is not available because of a name restriction.
| method | example |
| --- | --- |
| func | is.func(new Function()) |is.asyncFunction(async function() {})
| generatorFunction | N/A |
| asyncFunction | |is.boundFunction((function(){}).bind(null))
| boundFunction | |is.iterable([1, 2])
| iterable | |
| asyncIterable | N/A |
| generator | N/A |
> is.function has been reduced to is.func because of a name restriction.
| method | example |
| --- | --- |
| typedArray | is.typedArray(new int8Array()) |is.int8Array(new int8Array())
| int8Array | |is.uint8Array(new uint8Array())
| uint8Array | |is.uint8ClampedArray(new uint8ClampedArray())
| uint8ClampedArray | |is.int16Array(new int16Array())
| int16Array | |is.uint16Array(new uint16Array())
| uint16Array | |is.int32Array(new int32Array())
| int32Array | |is.uint32Array(new uint32Array())
| uint32Array | |is.float32Array(new float32Array())
| float32Array | |is.float64Array(new float64Array())
| float64Array | |is.arrayBuffer(new ArrayBuffer())
| arrayBuffer | |is.sharedArrayBuffer(new SharedArrayBuffer())
| sharedArrayBuffer | |is.dataView(new DataView(new ArrayBuffer(8)))
| dataView | |
| method | example |
| --- | --- |
| nan | is.nan(Number("booom!")) |is.integer(5 / 10)
| integer | |is.directInstanceOf(Object, {})
| directInstanceOf | |is.truthy(true)
| truthy | |is.falsy("")
| falsy | |is.emptyString("")` |
| emptyString |
This project have no dependencies.