forked from nan-academy/tron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis.js
47 lines (45 loc) · 1.25 KB
/
is.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const isFn = fn => typeof fn === 'function'
const isArr = Array.isArray || (arr => arr && arr.constructor === Array)
const isDef = val => val !== undefined
const isNum = num => typeof num === 'number' && !isNaN(num)
const isBool = b => b === true || b === false
const isObj = obj => obj && (typeof obj === 'object')
const isStr = str => typeof str === 'string'
const isUndef = val => val === undefined
const isThenable = fn => fn && isFn(fn.then)
const isPromise = fn => isThenable(fn) && isFn(fn.catch)
const isElement = x => x instanceof Element
const isChildren = x => isStr(x) || isArr(x) || isElement(x)
const isObserv = obs => isFn(obs) && isFn(obs.set)
const isEvent = ev => isFn(ev.listen) && isFn(ev.broadcast)
const isPrimitive = prim => {
switch (typeof prim) {
case 'string':
case 'number':
case 'boolean': return true
default: return false
}
}
const isNode = typeof window !== 'undefined'
const isFloat = (float => isNum(float) && Math.floor(float) !== float)
const isInt = Number.isInteger || (int => isNum(int) && Math.floor(int) === int)
export {
isFn,
isArr,
isDef,
isInt,
isStr,
isObj,
isNum,
isBool,
isNode,
isUndef,
isFloat,
isEvent,
isObserv,
isPromise,
isElement,
isChildren,
isPrimitive,
isThenable,
}