forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis.js
More file actions
140 lines (110 loc) · 3.02 KB
/
is.js
File metadata and controls
140 lines (110 loc) · 3.02 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const
hasMap = typeof Map === 'function',
hasSet = typeof Set === 'function',
hasArrayBuffer = typeof ArrayBuffer === 'function'
export function isDeepEqual (a, b) {
if (a === b) {
return true
}
if (a !== null && b !== null && typeof a === 'object' && typeof b === 'object') {
if (a.constructor !== b.constructor) {
return false
}
let length, i
if (a.constructor === Array) {
length = a.length
if (length !== b.length) {
return false
}
for (i = length; i-- !== 0;) {
if (isDeepEqual(a[i], b[i]) !== true) {
return false
}
}
return true
}
if (hasMap === true && a.constructor === Map) {
if (a.size !== b.size) {
return false
}
i = a.entries().next()
while (i.done !== true) {
if (b.has(i.value[0]) !== true) {
return false
}
i = i.next()
}
i = a.entries().next()
while (i.done !== true) {
if (isDeepEqual(i.value[1], b.get(i.value[0])) !== true) {
return false
}
i = i.next()
}
return true
}
if (hasSet === true && a.constructor === Set) {
if (a.size !== b.size) {
return false
}
i = a.entries().next()
while (i.done !== true) {
if (b.has(i.value[0]) !== true) {
return false
}
i = i.next()
}
return true
}
if (hasArrayBuffer === true && a.buffer != null && a.buffer.constructor === ArrayBuffer) {
length = a.length
if (length !== b.length) {
return false
}
for (i = length; i-- !== 0;) {
if (a[i] !== b[i]) {
return false
}
}
return true
}
if (a.constructor === RegExp) {
return a.source === b.source && a.flags === b.flags
}
if (a.valueOf !== Object.prototype.valueOf) {
return a.valueOf() === b.valueOf()
}
if (a.toString !== Object.prototype.toString) {
return a.toString() === b.toString()
}
const keys = Object.keys(a).filter(key => a[key] !== void 0)
length = keys.length
if (length !== Object.keys(b).filter(key => b[key] !== void 0).length) {
return false
}
for (i = length; i-- !== 0;) {
const key = keys[i]
if (isDeepEqual(a[key], b[key]) !== true) {
return false
}
}
return true
}
// true if both NaN, false otherwise
return a !== a && b !== b // eslint-disable-line no-self-compare
}
// not perfect, but what we ARE interested is for Arrays not to slip in
// as spread operator will mess things up in various areas
// see https://jsbench.me/tbl0iliyax/1
export function isObject (v) {
return v !== null && typeof v === 'object' && Array.isArray(v) !== true
}
export function isDate (v) {
return Object.prototype.toString.call(v) === '[object Date]'
}
export function isRegexp (v) {
return Object.prototype.toString.call(v) === '[object RegExp]'
}
export function isNumber (v) {
return typeof v === 'number' && isFinite(v)
}