1.1.2 • Published 6 years ago

typeis v1.1.2

Weekly downloads
461
License
MIT
Repository
github
Last release
6 years ago

In Javascript, "Everything is (or acts like) an Object" We need to write "typeis.js" due to a problem (type check) arised other than except the conveniences it is a providing to us.

typeis.js

Typeis. it's the smart and simple javascript type check and validation library ~226 Bytes;

ValueNativeTypeis.js
Undeclared variablesundefined---
undefinedundefinedUndefined
nullobjectNull
BooleansbooleanBoolean
NumbersnumberNumber
StringstringString
FunctionsfunctionFunction
ArrayobjectArray
ObjectobjectObject
DateobjectDate
RegExpobjectRegExp

Download

Installation

npm install typeis
bower install typeis

Usage

In Node.js:

require('typeis');

In a browser:

<script src="typeis.js"></script>

Examples

typeis(variable);
// return Array, Object, RegExp, Date etc.

// OR

new Typeis(variable).get()

Multi type validation

typeis(variable, ['array', 'object']);
// if variable is Array or Object return true otherwise false

Type valition with regex

typeis(variable, 'array|object');
// if variable is Array or object return true otherwise false

typeis(variable, '.+[yep]$');
// if variable type end of "y", "e" and "p" like Array, Date, RegExp return true otherwise false

typeis(variable, '(^(?!array|object).+)[^n]$');
// if variable is Array, Object or ending "n" like Function and Boolean return false otherwise true

Real world Usage

function realWorld( options ){
    if(typeis(options, 'object')){
        //do something
    } else {
        //do another something
    }
}

Browser Support

IE9 and below also support all modern browser.

Changelog

2.0.0-alpha

rewrite library with typescript removed property usage

1.1.2

Property usage warning

1.1.1

Update readme

1.1.0

Multi type validation support

variable.typeis(['array', 'object']);
// if variable is Array or Object return true otherwise false

type validation with regex support

variable.typeis('array|object');
// if variable is Array or object return true otherwise false
1.0

Typeis.js Released