UNPKG

1.83 kBJavaScriptView Raw
1
2/**
3 * Types utilities
4 */
5
6const UNDEFINED = void 0;
7
8/**
9 * Return an empty function
10 * @return {Function}
11 */
12export const EMPTY_FN = function() {};
13
14/**
15 * Check passed argument is an object
16 * @param {Object} obj
17 * @return {Boolean}
18 */
19export const isObj =
20 (obj) => Object.prototype.toString.call(obj) === '[object Object]';
21
22/**
23 * Check passed argument is a function
24 * @param {Function} obj
25 * @return {Boolean}
26 */
27export const isFn =
28 (obj) => Object.prototype.toString.call(obj) === '[object Function]';
29
30/**
31 * Check passed argument is an array
32 * @param {Array} obj
33 * @return {Boolean}
34 */
35export const isArray =
36 (obj) => Object.prototype.toString.call(obj) === '[object Array]';
37
38/**
39 * Check passed argument is a string
40 * @param {String} obj obj
41 * @returns {Boolean}
42 */
43export const isString =
44 (obj) => Object.prototype.toString.call(obj) === '[object String]';
45
46/**
47 * Check passed argument is a number
48 * @param {Number} obj
49 * @returns {Boolean}
50 */
51export const isNumber =
52 (obj) => Object.prototype.toString.call(obj) === '[object Number]';
53
54/**
55 * Check passed argument is a boolean
56 * @param {Boolean} obj
57 * @returns {Boolean}
58 */
59export const isBoolean =
60 (obj) => Object.prototype.toString.call(obj) === '[object Boolean]';
61
62/**
63 * Check passed argument is undefined
64 * @param {Any} obj
65 * @return {Boolean}
66 */
67export const isUndef = (obj) => obj === UNDEFINED;
68
69/**
70 * Check passed argument is null
71 * @param {Any} obj
72 * @return {Boolean}
73 */
74export const isNull = (obj) => obj === null;
75
76/**
77 * Check passed argument is empty (undefined, null or empty string)
78 * @param {Any} obj
79 * @return {Boolean}
80 */
81export const isEmpty = (obj) => isUndef(obj) || isNull(obj) || obj.length === 0;