For type-checking Javascript values.
Examplejs const t = require('typical')
booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanReturns true if input is a number
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| n | * |
the input to test |
Examplejs > t.isNumber(0) true > t.isNumber(1) true > t.isNumber(1.1) true > t.isNumber(0xff) true > t.isNumber(0644) true > t.isNumber(6.2e5) true > t.isNumber(NaN) false > t.isNumber(Infinity) false
booleanA plain object is a simple object literal, it is not an instance of a class. Returns true if the input typeof is object and directly decends from Object.
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
Examplejs > t.isPlainObject({ something: 'one' }) true > t.isPlainObject(new Date()) false > t.isPlainObject([ 0, 1 ]) false > t.isPlainObject(/test/) false > t.isPlainObject(1) false > t.isPlainObject('one') false > t.isPlainObject(null) false > t.isPlainObject((function * () {})()) false > t.isPlainObject(function * () {}) false
booleanAn array-like value has all the properties of an array, but is not an array instance. Examples in the arguments object. Returns true if the input value is an object, not null and has a length property with a numeric value.
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
Examplejs function sum(x, y){ console.log(t.isArrayLike(arguments)) // prints `true` }
booleanreturns true if the typeof input is 'object', but not null!
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
booleanReturns true if the input value is defined
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
booleanReturns true if the input value is a string
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
booleanReturns true if the input value is a boolean
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
booleanReturns true if the input value is a function
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
booleanReturns true if the input value is an es2015 class.
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
booleanReturns true if the input is a string, number, symbol, boolean, null or undefined value.
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
booleanReturns true if the input is a Promise.
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
booleanReturns true if the input is an iterable (Map, Set, Array, Generator etc.).
Kind: static method of typical
| Param | Type | Description |
|---|---|---|
| input | * |
the input to test |
Examplejs > t.isIterable('string') true > t.isIterable(new Map()) true > t.isIterable([]) true > t.isIterable((function * () {})()) true > t.isIterable(Promise.resolve()) false > t.isIterable(Promise) false > t.isIterable(true) false > t.isIterable({}) false > t.isIterable(0) false > t.isIterable(1.1) false > t.isIterable(NaN) false > t.isIterable(Infinity) false > t.isIterable(function () {}) false > t.isIterable(Date) false > t.isIterable() false > t.isIterable({ then: function () {} }) false
This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.
Node.js:
const typical = require('typical')
Within Node.js with ECMAScript Module support enabled:
import typical from 'typical'
Within a modern browser ECMAScript Module:
import typical from './node_modules/typical/index.mjs'
Old browser (adds window.typical):
<script nomodule src="./node_modules/typical/dist/index.js"></script>
© 2014-19 Lloyd Brookes <75pound@gmail.com\. Documented by jsdoc-to-markdown.