@konfirm/is-type
v1.0.9
Published
Simple Object type/name checks
Downloads
18
Maintainers
Readme
IsType
Simple Object type/name checks
Getting started
Installation
$ npm install --save @konfirm/is-type
Usage
As the type library as a scoped package, the scope is also need when the library is used.
const Type = require('@konfirm/is-type');
console.log(Type.isString('foo')); // true
console.log(Type.isString(Infinity)); // false
console.log(Type.isNumber('foo')); // false
console.log(Type.isNumber(Infinity)); // true
API
The IsType
library provides the same API as the Type
library, with the addition of is*
type checks for any type of detectable object/built-in type.
is*
Detect any type using its name right after is
, for example isObject
or isMyCustomObject
.
It takes the prototype chain into consideration for objects, except for the built-in simple types (String
, Number
, Boolean
) and null
values, which are not considered to be objects by IsType
.
const Type = require('@konfirm/is-type');
console.log(Type.isObject('foo')); // false
console.log(Type.isObject(null)); // false
console.log(Type.isNULL(null)); // true (in case you dislike isNull)
console.log(Type.isNull(null)); // true (in case you dislike isNULL)
class One {}
class Two extends One {}
class Three extends Two {}
const three = new Three();
console.log(Type.isThree(three)); // true
console.log(Type.isTwo(three)); // true
console.log(Type.isOne(three)); // true
Inherited methods
functionName(value)
getTypeName(value [, real = true])
instanceOf(type, value)
is(type, value)
objectName(value)
Licence
MIT License
Copyright (c) 2018 Konfirm
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.