1 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
2 |
|
3 | function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
4 |
|
5 | function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
6 |
|
7 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
8 |
|
9 | import isDate from 'is-date-object';
|
10 | import isArguments from 'is-arguments';
|
11 | import isPrimitive from 'is-primitive';
|
12 | import isObject from 'is-object';
|
13 | import isBuffer from 'is-buffer';
|
14 | import isString from 'is-string';
|
15 | import isError from 'is-error-x';
|
16 | import isMap from 'is-map-x';
|
17 | import isSet from 'is-set-x';
|
18 | import isNil from 'is-nil-x';
|
19 | import isRegExp from 'is-regexp-x';
|
20 | import indexOf from 'index-of-x';
|
21 | import slice from 'array-slice-x';
|
22 | import some from 'array-some-x';
|
23 | import filter from 'array-filter-x';
|
24 | import sort from 'stable';
|
25 | import $keys from 'object-keys-x';
|
26 | import $getPrototypeOf from 'get-prototype-of-x';
|
27 | import hasBoxedString from 'has-boxed-string-x';
|
28 | import toBoolean from 'to-boolean-x';
|
29 |
|
30 |
|
31 | var hasBoxedStringBug = hasBoxedString === false;
|
32 |
|
33 | var reIsUint = /^(?:0|[1-9]\d*)$/;
|
34 |
|
35 |
|
36 | var hasMapEnumerables = typeof Map === 'function' ? $keys(new Map()) : [];
|
37 |
|
38 |
|
39 | var hasSetEnumerables = typeof Set === 'function' ? $keys(new Set()) : [];
|
40 | var hasErrorEnumerables;
|
41 |
|
42 | try {
|
43 |
|
44 | throw new Error('a');
|
45 | } catch (e) {
|
46 | hasErrorEnumerables = $keys(e);
|
47 | }
|
48 |
|
49 | var indexNotFound = -1;
|
50 | var maxSafeIndex = 4294967295;
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | var isIndex = function isIndex(value) {
|
62 | var num = indexNotFound;
|
63 |
|
64 | if (reIsUint.test(value)) {
|
65 | num = Number(value);
|
66 | }
|
67 |
|
68 | return num > indexNotFound && num % 1 === 0 && num < maxSafeIndex;
|
69 | };
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | var getItem = function getItem(args) {
|
87 | var _args = _slicedToArray(args, 4),
|
88 | object = _args[0],
|
89 | key = _args[1],
|
90 | isStr = _args[2],
|
91 | isIdx = _args[3];
|
92 |
|
93 | return isStr && isIdx ? object.charAt(key) : object[key];
|
94 | };
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | var filterUnwanted = function filterUnwanted(keys, unwanted) {
|
107 | return unwanted.length ? filter(keys, function predicate(key) {
|
108 | return indexOf(unwanted, key) === indexNotFound;
|
109 | }) : keys;
|
110 | };
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | var baseDeepEqual = function baseDeepEqual(args) {
|
133 | var _args2 = _slicedToArray(args, 4),
|
134 | actual = _args2[0],
|
135 | expected = _args2[1],
|
136 | strict = _args2[2],
|
137 | previousStack = _args2[3];
|
138 |
|
139 |
|
140 | if (actual === expected) {
|
141 | return true;
|
142 | }
|
143 |
|
144 | if (isBuffer(actual) && isBuffer(expected)) {
|
145 | return actual.length === expected.length && some(actual, function predicate(item, index) {
|
146 | return item !== expected[index];
|
147 | }) === false;
|
148 | }
|
149 |
|
150 |
|
151 |
|
152 | if (isDate(actual) && isDate(expected)) {
|
153 | return actual.getTime() === expected.getTime();
|
154 | }
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | if (isRegExp(actual) && isRegExp(expected)) {
|
160 | return actual.toString() === expected.toString() && actual.lastIndex === expected.lastIndex;
|
161 | }
|
162 |
|
163 |
|
164 |
|
165 | if (isObject(actual) === false && isObject(expected) === false) {
|
166 | if (strict) {
|
167 | return actual === expected;
|
168 | }
|
169 |
|
170 |
|
171 | return actual == expected;
|
172 |
|
173 | }
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 | if (isNil(actual) || isNil(expected)) {
|
182 | return false;
|
183 | }
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | if (strict && $getPrototypeOf(actual) !== $getPrototypeOf(expected)) {
|
191 | return false;
|
192 | }
|
193 |
|
194 |
|
195 | if (isPrimitive(actual) || isPrimitive(expected)) {
|
196 | return actual === expected;
|
197 | }
|
198 |
|
199 | var ka = isArguments(actual);
|
200 | var kb = isArguments(expected);
|
201 | var aNotB = ka && kb === false;
|
202 | var bNotA = ka === false && kb;
|
203 |
|
204 | if (aNotB || bNotA) {
|
205 | return false;
|
206 | }
|
207 |
|
208 | if (ka) {
|
209 | if (ka.length !== kb.length) {
|
210 | return false;
|
211 | }
|
212 |
|
213 | return baseDeepEqual([slice(actual), slice(expected), strict, null]);
|
214 | }
|
215 |
|
216 | ka = $keys(actual);
|
217 | kb = $keys(expected);
|
218 |
|
219 | if (ka.length !== kb.length) {
|
220 | return false;
|
221 | }
|
222 |
|
223 | if (isObject(actual)) {
|
224 | if (isError(actual)) {
|
225 | ka = filterUnwanted(ka, hasErrorEnumerables);
|
226 | } else if (isMap(actual)) {
|
227 | ka = filterUnwanted(ka, hasMapEnumerables);
|
228 | } else if (isSet(actual)) {
|
229 | ka = filterUnwanted(ka, hasSetEnumerables);
|
230 | }
|
231 | }
|
232 |
|
233 | if (isObject(expected)) {
|
234 | if (isError(expected)) {
|
235 | kb = filterUnwanted(kb, hasErrorEnumerables);
|
236 | } else if (isMap(expected)) {
|
237 | kb = filterUnwanted(kb, hasMapEnumerables);
|
238 | } else if (isSet(expected)) {
|
239 | kb = filterUnwanted(kb, hasSetEnumerables);
|
240 | }
|
241 | }
|
242 |
|
243 |
|
244 | sort.inplace(ka);
|
245 | sort.inplace(kb);
|
246 | var aIsString;
|
247 | var bIsString;
|
248 |
|
249 | if (hasBoxedStringBug) {
|
250 | aIsString = isString(actual);
|
251 | bIsString = isString(expected);
|
252 | }
|
253 |
|
254 |
|
255 |
|
256 |
|
257 | return some(ka, function predicate(key, index) {
|
258 | if (key !== kb[index]) {
|
259 | return true;
|
260 | }
|
261 |
|
262 | var isIdx = (aIsString || bIsString) && isIndex(key);
|
263 | var stack = previousStack || [actual];
|
264 | var item = getItem([actual, key, aIsString, isIdx]);
|
265 | var isPrim = isPrimitive(item);
|
266 |
|
267 | if (isPrim === false) {
|
268 | if (indexOf(stack, item) !== indexNotFound) {
|
269 | throw new RangeError('Circular object');
|
270 | }
|
271 |
|
272 | stack.push(item);
|
273 | }
|
274 |
|
275 | var result = baseDeepEqual([item, getItem([expected, key, bIsString, isIdx]), strict, stack]) === false;
|
276 |
|
277 | if (isPrim === false) {
|
278 | stack.pop();
|
279 | }
|
280 |
|
281 | return result;
|
282 | }) === false;
|
283 | };
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 | var deepEqual = function deepEqual(actual, expected) {
|
305 |
|
306 | return baseDeepEqual([actual, expected, toBoolean(arguments[2])]);
|
307 | };
|
308 |
|
309 | export default deepEqual;
|
310 |
|
311 |
|
\ | No newline at end of file |