UNPKG

2.52 kBJavaScriptView Raw
1"use strict";
2
3const iftype = require('iftype');
4
5function CustomType(){
6}
7
8//----------------------------
9// Check if type is 'string'
10//----------------------------
11iftype(123).is('string'); // => false
12iftype(function foo(){}).is('string'); // => false
13iftype(new CustomType()).is('string'); // => false
14iftype(["foo", "bar"]).is('string'); // => false
15iftype("bar").is('string'); // => true
16iftype(null).is('string'); // => false
17iftype(undefined).is('string'); // => false
18
19
20//----------------------------
21// Check if type is 'number'
22//----------------------------
23iftype(123).is('number'); // => true
24iftype(function foo(){}).is('number'); // => false
25iftype(new CustomType()).is('number'); // => false
26iftype(["foo", "bar"]).is('number'); // => false
27iftype("bar").is('number'); // => false
28iftype(null).is('number'); // => false
29iftype(undefined).is('number'); // => false
30
31
32//----------------------------
33// Check if type is 'object'
34//----------------------------
35iftype(123).is('object'); // => false
36iftype(function foo(){}).is('object'); // => false
37iftype(new CustomType()).is('object'); // => true
38iftype(["foo", "bar"]).is('object'); // => true
39iftype("bar").is('object'); // => false
40iftype(null).is('object'); // => false
41iftype(undefined).is('object'); // => false
42
43
44//----------------------------
45// Check if type is 'array'
46//----------------------------
47iftype(123).is('array'); // => false
48iftype(function foo(){}).is('array'); // => false
49iftype(new CustomType()).is('array'); // => false
50iftype(["foo", "bar"]).is('array'); // => true
51iftype("bar").is('array'); // => false
52iftype(null).is('array'); // => false
53iftype(undefined).is('array'); // => false
54
55
56//----------------------------
57// Check if type is 'function'
58//----------------------------
59iftype(123).is('function'); // => false
60iftype(function foo(){}).is('function'); // => true
61iftype(new CustomType()).is('function'); // => false
62iftype(["foo", "bar"]).is('function'); // => false
63iftype("bar").is('function'); // => false
64iftype(null).is('function'); // => false
65iftype(undefined).is('function'); // => false
66
67
68//----------------------------
69// Check if type is CustomType
70//----------------------------
71iftype(123).is(CustomType); // => false
72iftype(function foo(){}).is(CustomType); // => false
73iftype(new CustomType()).is(CustomType); // => true
74iftype(["foo", "bar"]).is(CustomType); // => false
75iftype("bar").is(CustomType); // => false
76iftype(null).is(CustomType); // => false
77iftype(undefined).is(CustomType); // => false
78
79