immutable 5.1.3 → 5.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/immutable.js CHANGED
@@ -28,105 +28,25 @@
28
28
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Immutable = {}));
29
29
  })(this, (function (exports) { 'use strict';
30
30
 
31
- // Used for setting prototype methods that IE8 chokes on.
32
- var DELETE = 'delete';
33
- // Constants describing the size of trie nodes.
34
- var SHIFT = 5; // Resulted in best performance after ______?
35
- var SIZE = 1 << SHIFT;
36
- var MASK = SIZE - 1;
37
- // A consistent shared value representing "not set" which equals nothing other
38
- // than itself, and nothing that could be provided externally.
39
- var NOT_SET = {};
40
- // Boolean references, Rough equivalent of `bool &`.
41
- function MakeRef() {
42
- return { value: false };
43
- }
44
- function SetRef(ref) {
45
- if (ref) {
46
- ref.value = true;
47
- }
48
- }
49
- // A function which returns a value representing an "owner" for transient writes
50
- // to tries. The return value will only ever equal itself, and will not equal
51
- // the return of any subsequent call of this function.
52
- function OwnerID() { }
53
- function ensureSize(iter) {
54
- // @ts-expect-error size should exists on Collection
55
- if (iter.size === undefined) {
56
- // @ts-expect-error size should exists on Collection, __iterate does exist on Collection
57
- iter.size = iter.__iterate(returnTrue);
58
- }
59
- // @ts-expect-error size should exists on Collection
60
- return iter.size;
61
- }
62
- function wrapIndex(iter, index) {
63
- // This implements "is array index" which the ECMAString spec defines as:
64
- //
65
- // A String property name P is an array index if and only if
66
- // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
67
- // to 2^32−1.
68
- //
69
- // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
70
- if (typeof index !== 'number') {
71
- var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
72
- if ('' + uint32Index !== index || uint32Index === 4294967295) {
73
- return NaN;
74
- }
75
- index = uint32Index;
76
- }
77
- return index < 0 ? ensureSize(iter) + index : index;
78
- }
79
- function returnTrue() {
80
- return true;
81
- }
82
- function wholeSlice(begin, end, size) {
83
- return (((begin === 0 && !isNeg(begin)) ||
84
- (size !== undefined && begin <= -size)) &&
85
- (end === undefined || (size !== undefined && end >= size)));
86
- }
87
- function resolveBegin(begin, size) {
88
- return resolveIndex(begin, size, 0);
89
- }
90
- function resolveEnd(end, size) {
91
- return resolveIndex(end, size, size);
92
- }
93
- function resolveIndex(index, size, defaultIndex) {
94
- // Sanitize indices using this shorthand for ToInt32(argument)
95
- // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
96
- return index === undefined
97
- ? defaultIndex
98
- : isNeg(index)
99
- ? size === Infinity
100
- ? size
101
- : Math.max(0, size + index) | 0
102
- : size === undefined || size === index
103
- ? index
104
- : Math.min(size, index) | 0;
105
- }
106
- function isNeg(value) {
107
- // Account for -0 which is negative, but not less than 0.
108
- return value < 0 || (value === 0 && 1 / value === -Infinity);
109
- }
110
-
111
- // Note: value is unchanged to not break immutable-devtools.
112
- var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
31
+ var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
113
32
  /**
114
- * True if `maybeCollection` is a Collection, or any of its subclasses.
33
+ * True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
115
34
  *
116
35
  * ```js
117
- * import { isCollection, Map, List, Stack } from 'immutable';
36
+ * import { isIndexed, Map, List, Stack, Set } from 'immutable';
118
37
  *
119
- * isCollection([]); // false
120
- * isCollection({}); // false
121
- * isCollection(Map()); // true
122
- * isCollection(List()); // true
123
- * isCollection(Stack()); // true
38
+ * isIndexed([]); // false
39
+ * isIndexed({}); // false
40
+ * isIndexed(Map()); // false
41
+ * isIndexed(List()); // true
42
+ * isIndexed(Stack()); // true
43
+ * isIndexed(Set()); // false
124
44
  * ```
125
45
  */
126
- function isCollection(maybeCollection) {
127
- return Boolean(maybeCollection &&
128
- // @ts-expect-error: maybeCollection is typed as `{}`, need to change in 6.0 to `maybeCollection && typeof maybeCollection === 'object' && IS_COLLECTION_SYMBOL in maybeCollection`
129
- maybeCollection[IS_COLLECTION_SYMBOL]);
46
+ function isIndexed(maybeIndexed) {
47
+ return Boolean(maybeIndexed &&
48
+ // @ts-expect-error: maybeIndexed is typed as `{}`, need to change in 6.0 to `maybeIndexed && typeof maybeIndexed === 'object' && IS_INDEXED_SYMBOL in maybeIndexed`
49
+ maybeIndexed[IS_INDEXED_SYMBOL]);
130
50
  }
131
51
 
132
52
  var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
@@ -149,27 +69,6 @@
149
69
  maybeKeyed[IS_KEYED_SYMBOL]);
150
70
  }
151
71
 
152
- var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
153
- /**
154
- * True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
155
- *
156
- * ```js
157
- * import { isIndexed, Map, List, Stack, Set } from 'immutable';
158
- *
159
- * isIndexed([]); // false
160
- * isIndexed({}); // false
161
- * isIndexed(Map()); // false
162
- * isIndexed(List()); // true
163
- * isIndexed(Stack()); // true
164
- * isIndexed(Set()); // false
165
- * ```
166
- */
167
- function isIndexed(maybeIndexed) {
168
- return Boolean(maybeIndexed &&
169
- // @ts-expect-error: maybeIndexed is typed as `{}`, need to change in 6.0 to `maybeIndexed && typeof maybeIndexed === 'object' && IS_INDEXED_SYMBOL in maybeIndexed`
170
- maybeIndexed[IS_INDEXED_SYMBOL]);
171
- }
172
-
173
72
  /**
174
73
  * True if `maybeAssociative` is either a Keyed or Indexed Collection.
175
74
  *
@@ -188,6 +87,27 @@
188
87
  return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
189
88
  }
190
89
 
90
+ // Note: value is unchanged to not break immutable-devtools.
91
+ var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
92
+ /**
93
+ * True if `maybeCollection` is a Collection, or any of its subclasses.
94
+ *
95
+ * ```js
96
+ * import { isCollection, Map, List, Stack } from 'immutable';
97
+ *
98
+ * isCollection([]); // false
99
+ * isCollection({}); // false
100
+ * isCollection(Map()); // true
101
+ * isCollection(List()); // true
102
+ * isCollection(Stack()); // true
103
+ * ```
104
+ */
105
+ function isCollection(maybeCollection) {
106
+ return Boolean(maybeCollection &&
107
+ // @ts-expect-error: maybeCollection is typed as `{}`, need to change in 6.0 to `maybeCollection && typeof maybeCollection === 'object' && IS_COLLECTION_SYMBOL in maybeCollection`
108
+ maybeCollection[IS_COLLECTION_SYMBOL]);
109
+ }
110
+
191
111
  var Collection = function Collection(value) {
192
112
  // eslint-disable-next-line no-constructor-return
193
113
  return isCollection(value) ? value : Seq(value);
@@ -236,158 +156,236 @@
236
156
  Collection.Indexed = IndexedCollection;
237
157
  Collection.Set = SetCollection;
238
158
 
239
- var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
240
- /**
241
- * True if `maybeSeq` is a Seq.
242
- */
243
- function isSeq(maybeSeq) {
244
- return Boolean(maybeSeq &&
245
- // @ts-expect-error: maybeSeq is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSeq === 'object' && MAYBE_SEQ_SYMBOL in maybeSeq`
246
- maybeSeq[IS_SEQ_SYMBOL]);
247
- }
248
-
249
- var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
250
- /**
251
- * True if `maybeRecord` is a Record.
252
- */
253
- function isRecord(maybeRecord) {
254
- return Boolean(maybeRecord &&
255
- // @ts-expect-error: maybeRecord is typed as `{}`, need to change in 6.0 to `maybeRecord && typeof maybeRecord === 'object' && IS_RECORD_SYMBOL in maybeRecord`
256
- maybeRecord[IS_RECORD_SYMBOL]);
257
- }
258
-
259
- /**
260
- * True if `maybeImmutable` is an Immutable Collection or Record.
261
- *
262
- * Note: Still returns true even if the collections is within a `withMutations()`.
263
- *
264
- * ```js
265
- * import { isImmutable, Map, List, Stack } from 'immutable';
266
- * isImmutable([]); // false
267
- * isImmutable({}); // false
268
- * isImmutable(Map()); // true
269
- * isImmutable(List()); // true
270
- * isImmutable(Stack()); // true
271
- * isImmutable(Map().asMutable()); // true
272
- * ```
273
- */
274
- function isImmutable(maybeImmutable) {
275
- return isCollection(maybeImmutable) || isRecord(maybeImmutable);
276
- }
277
-
278
- var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
279
- function isOrdered(maybeOrdered) {
280
- return Boolean(maybeOrdered &&
281
- // @ts-expect-error: maybeOrdered is typed as `{}`, need to change in 6.0 to `maybeOrdered && typeof maybeOrdered === 'object' && IS_ORDERED_SYMBOL in maybeOrdered`
282
- maybeOrdered[IS_ORDERED_SYMBOL]);
283
- }
284
-
285
159
  var ITERATE_KEYS = 0;
286
160
  var ITERATE_VALUES = 1;
287
161
  var ITERATE_ENTRIES = 2;
288
-
162
+ // TODO Symbol is widely available in modern JavaScript environments, clean this
289
163
  var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
290
164
  var FAUX_ITERATOR_SYMBOL = '@@iterator';
291
-
292
165
  var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
293
-
166
+ // @ts-expect-error: properties are not supported in buble
294
167
  var Iterator = function Iterator(next) {
295
- this.next = next;
168
+ // @ts-expect-error: properties are not supported in buble
169
+ this.next = next;
296
170
  };
297
-
298
171
  Iterator.prototype.toString = function toString () {
299
- return '[Iterator]';
172
+ return '[Iterator]';
300
173
  };
301
-
174
+ // @ts-expect-error: static properties are not supported in buble
302
175
  Iterator.KEYS = ITERATE_KEYS;
176
+ // @ts-expect-error: static properties are not supported in buble
303
177
  Iterator.VALUES = ITERATE_VALUES;
178
+ // @ts-expect-error: static properties are not supported in buble
304
179
  Iterator.ENTRIES = ITERATE_ENTRIES;
305
-
180
+ // @ts-expect-error: properties are not supported in buble
306
181
  Iterator.prototype.inspect = Iterator.prototype.toSource = function () {
307
- return this.toString();
182
+ return this.toString();
308
183
  };
184
+ // @ts-expect-error don't know how to type this
309
185
  Iterator.prototype[ITERATOR_SYMBOL] = function () {
310
- return this;
186
+ return this;
311
187
  };
312
-
313
188
  function iteratorValue(type, k, v, iteratorResult) {
314
- var value =
315
- type === ITERATE_KEYS ? k : type === ITERATE_VALUES ? v : [k, v];
316
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
317
- iteratorResult
318
- ? (iteratorResult.value = value)
319
- : (iteratorResult = {
320
- value: value,
321
- done: false,
322
- });
323
- return iteratorResult;
189
+ var value = type === ITERATE_KEYS ? k : type === ITERATE_VALUES ? v : [k, v];
190
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
191
+ iteratorResult
192
+ ? (iteratorResult.value = value)
193
+ : (iteratorResult = {
194
+ // @ts-expect-error ensure value is not undefined
195
+ value: value,
196
+ done: false,
197
+ });
198
+ return iteratorResult;
324
199
  }
325
-
326
200
  function iteratorDone() {
327
- return { value: undefined, done: true };
201
+ return { value: undefined, done: true };
328
202
  }
329
-
330
203
  function hasIterator(maybeIterable) {
331
- if (Array.isArray(maybeIterable)) {
332
- // IE11 trick as it does not support `Symbol.iterator`
333
- return true;
334
- }
335
-
336
- return !!getIteratorFn(maybeIterable);
204
+ if (Array.isArray(maybeIterable)) {
205
+ // IE11 trick as it does not support `Symbol.iterator`
206
+ return true;
207
+ }
208
+ return !!getIteratorFn(maybeIterable);
337
209
  }
338
-
339
210
  function isIterator(maybeIterator) {
340
- return maybeIterator && typeof maybeIterator.next === 'function';
211
+ return !!(maybeIterator &&
212
+ // @ts-expect-error: maybeIterator is typed as `{}`
213
+ typeof maybeIterator.next === 'function');
341
214
  }
342
-
343
215
  function getIterator(iterable) {
344
- var iteratorFn = getIteratorFn(iterable);
345
- return iteratorFn && iteratorFn.call(iterable);
216
+ var iteratorFn = getIteratorFn(iterable);
217
+ return iteratorFn && iteratorFn.call(iterable);
346
218
  }
347
-
348
219
  function getIteratorFn(iterable) {
349
- var iteratorFn =
350
- iterable &&
351
- ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
352
- iterable[FAUX_ITERATOR_SYMBOL]);
353
- if (typeof iteratorFn === 'function') {
354
- return iteratorFn;
355
- }
220
+ var iteratorFn = iterable &&
221
+ // @ts-expect-error: maybeIterator is typed as `{}`
222
+ ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
223
+ // @ts-expect-error: maybeIterator is typed as `{}`
224
+ iterable[FAUX_ITERATOR_SYMBOL]);
225
+ if (typeof iteratorFn === 'function') {
226
+ return iteratorFn;
227
+ }
356
228
  }
357
-
358
229
  function isEntriesIterable(maybeIterable) {
359
- var iteratorFn = getIteratorFn(maybeIterable);
360
- return iteratorFn && iteratorFn === maybeIterable.entries;
230
+ var iteratorFn = getIteratorFn(maybeIterable);
231
+ // @ts-expect-error: maybeIterator is typed as `{}`
232
+ return iteratorFn && iteratorFn === maybeIterable.entries;
361
233
  }
362
-
363
234
  function isKeysIterable(maybeIterable) {
364
- var iteratorFn = getIteratorFn(maybeIterable);
365
- return iteratorFn && iteratorFn === maybeIterable.keys;
235
+ var iteratorFn = getIteratorFn(maybeIterable);
236
+ // @ts-expect-error: maybeIterator is typed as `{}`
237
+ return iteratorFn && iteratorFn === maybeIterable.keys;
366
238
  }
367
239
 
368
- var hasOwnProperty = Object.prototype.hasOwnProperty;
369
-
370
- function isArrayLike(value) {
371
- if (Array.isArray(value) || typeof value === 'string') {
372
- return true;
373
- }
374
- // @ts-expect-error "Type 'unknown' is not assignable to type 'boolean'" : convert to Boolean
375
- return (value &&
376
- typeof value === 'object' &&
377
- // @ts-expect-error check that `'length' in value &&`
378
- Number.isInteger(value.length) &&
379
- // @ts-expect-error check that `'length' in value &&`
380
- value.length >= 0 &&
381
- // @ts-expect-error check that `'length' in value &&`
382
- (value.length === 0
383
- ? // Only {length: 0} is considered Array-like.
384
- Object.keys(value).length === 1
385
- : // An object is only Array-like if it has a property where the last value
386
- // in the array-like may be found (which could be undefined).
387
- // @ts-expect-error check that `'length' in value &&`
388
- value.hasOwnProperty(value.length - 1)));
240
+ // Used for setting prototype methods that IE8 chokes on.
241
+ var DELETE = 'delete';
242
+ // Constants describing the size of trie nodes.
243
+ var SHIFT = 5; // Resulted in best performance after ______?
244
+ var SIZE = 1 << SHIFT;
245
+ var MASK = SIZE - 1;
246
+ // A consistent shared value representing "not set" which equals nothing other
247
+ // than itself, and nothing that could be provided externally.
248
+ var NOT_SET = {};
249
+ // Boolean references, Rough equivalent of `bool &`.
250
+ function MakeRef() {
251
+ return { value: false };
389
252
  }
390
-
253
+ function SetRef(ref) {
254
+ if (ref) {
255
+ ref.value = true;
256
+ }
257
+ }
258
+ // A function which returns a value representing an "owner" for transient writes
259
+ // to tries. The return value will only ever equal itself, and will not equal
260
+ // the return of any subsequent call of this function.
261
+ function OwnerID() { }
262
+ function ensureSize(iter) {
263
+ // @ts-expect-error size should exists on Collection
264
+ if (iter.size === undefined) {
265
+ // @ts-expect-error size should exists on Collection, __iterate does exist on Collection
266
+ iter.size = iter.__iterate(returnTrue);
267
+ }
268
+ // @ts-expect-error size should exists on Collection
269
+ return iter.size;
270
+ }
271
+ function wrapIndex(iter, index) {
272
+ // This implements "is array index" which the ECMAString spec defines as:
273
+ //
274
+ // A String property name P is an array index if and only if
275
+ // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
276
+ // to 2^32−1.
277
+ //
278
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
279
+ if (typeof index !== 'number') {
280
+ var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
281
+ if ('' + uint32Index !== index || uint32Index === 4294967295) {
282
+ return NaN;
283
+ }
284
+ index = uint32Index;
285
+ }
286
+ return index < 0 ? ensureSize(iter) + index : index;
287
+ }
288
+ function returnTrue() {
289
+ return true;
290
+ }
291
+ function wholeSlice(begin, end, size) {
292
+ return (((begin === 0 && !isNeg(begin)) ||
293
+ (size !== undefined && begin <= -size)) &&
294
+ (end === undefined || (size !== undefined && end >= size)));
295
+ }
296
+ function resolveBegin(begin, size) {
297
+ return resolveIndex(begin, size, 0);
298
+ }
299
+ function resolveEnd(end, size) {
300
+ return resolveIndex(end, size, size);
301
+ }
302
+ function resolveIndex(index, size, defaultIndex) {
303
+ // Sanitize indices using this shorthand for ToInt32(argument)
304
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
305
+ return index === undefined
306
+ ? defaultIndex
307
+ : isNeg(index)
308
+ ? size === Infinity
309
+ ? size
310
+ : Math.max(0, size + index) | 0
311
+ : size === undefined || size === index
312
+ ? index
313
+ : Math.min(size, index) | 0;
314
+ }
315
+ function isNeg(value) {
316
+ // Account for -0 which is negative, but not less than 0.
317
+ return value < 0 || (value === 0 && 1 / value === -Infinity);
318
+ }
319
+
320
+ var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
321
+ /**
322
+ * True if `maybeRecord` is a Record.
323
+ */
324
+ function isRecord(maybeRecord) {
325
+ return Boolean(maybeRecord &&
326
+ // @ts-expect-error: maybeRecord is typed as `{}`, need to change in 6.0 to `maybeRecord && typeof maybeRecord === 'object' && IS_RECORD_SYMBOL in maybeRecord`
327
+ maybeRecord[IS_RECORD_SYMBOL]);
328
+ }
329
+
330
+ /**
331
+ * True if `maybeImmutable` is an Immutable Collection or Record.
332
+ *
333
+ * Note: Still returns true even if the collections is within a `withMutations()`.
334
+ *
335
+ * ```js
336
+ * import { isImmutable, Map, List, Stack } from 'immutable';
337
+ * isImmutable([]); // false
338
+ * isImmutable({}); // false
339
+ * isImmutable(Map()); // true
340
+ * isImmutable(List()); // true
341
+ * isImmutable(Stack()); // true
342
+ * isImmutable(Map().asMutable()); // true
343
+ * ```
344
+ */
345
+ function isImmutable(maybeImmutable) {
346
+ return isCollection(maybeImmutable) || isRecord(maybeImmutable);
347
+ }
348
+
349
+ var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
350
+ function isOrdered(maybeOrdered) {
351
+ return Boolean(maybeOrdered &&
352
+ // @ts-expect-error: maybeOrdered is typed as `{}`, need to change in 6.0 to `maybeOrdered && typeof maybeOrdered === 'object' && IS_ORDERED_SYMBOL in maybeOrdered`
353
+ maybeOrdered[IS_ORDERED_SYMBOL]);
354
+ }
355
+
356
+ var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
357
+ /**
358
+ * True if `maybeSeq` is a Seq.
359
+ */
360
+ function isSeq(maybeSeq) {
361
+ return Boolean(maybeSeq &&
362
+ // @ts-expect-error: maybeSeq is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSeq === 'object' && MAYBE_SEQ_SYMBOL in maybeSeq`
363
+ maybeSeq[IS_SEQ_SYMBOL]);
364
+ }
365
+
366
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
367
+
368
+ function isArrayLike(value) {
369
+ if (Array.isArray(value) || typeof value === 'string') {
370
+ return true;
371
+ }
372
+ // @ts-expect-error "Type 'unknown' is not assignable to type 'boolean'" : convert to Boolean
373
+ return (value &&
374
+ typeof value === 'object' &&
375
+ // @ts-expect-error check that `'length' in value &&`
376
+ Number.isInteger(value.length) &&
377
+ // @ts-expect-error check that `'length' in value &&`
378
+ value.length >= 0 &&
379
+ // @ts-expect-error check that `'length' in value &&`
380
+ (value.length === 0
381
+ ? // Only {length: 0} is considered Array-like.
382
+ Object.keys(value).length === 1
383
+ : // An object is only Array-like if it has a property where the last value
384
+ // in the array-like may be found (which could be undefined).
385
+ // @ts-expect-error check that `'length' in value &&`
386
+ value.hasOwnProperty(value.length - 1)));
387
+ }
388
+
391
389
  var Seq = /*@__PURE__*/(function (Collection) {
392
390
  function Seq(value) {
393
391
  // eslint-disable-next-line no-constructor-return
@@ -751,119 +749,16 @@
751
749
  : undefined;
752
750
  }
753
751
 
754
- var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
755
- /**
756
- * True if `maybeMap` is a Map.
757
- *
758
- * Also true for OrderedMaps.
759
- */
760
- function isMap(maybeMap) {
761
- return Boolean(maybeMap &&
762
- // @ts-expect-error: maybeMap is typed as `{}`, need to change in 6.0 to `maybeMap && typeof maybeMap === 'object' && IS_MAP_SYMBOL in maybeMap`
763
- maybeMap[IS_MAP_SYMBOL]);
764
- }
765
-
766
- /**
767
- * True if `maybeOrderedMap` is an OrderedMap.
768
- */
769
- function isOrderedMap(maybeOrderedMap) {
770
- return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
771
- }
772
-
773
- /**
774
- * True if `maybeValue` is a JavaScript Object which has *both* `equals()`
775
- * and `hashCode()` methods.
776
- *
777
- * Any two instances of *value objects* can be compared for value equality with
778
- * `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
779
- */
780
- function isValueObject(maybeValue) {
781
- return Boolean(maybeValue &&
782
- // @ts-expect-error: maybeValue is typed as `{}`
783
- typeof maybeValue.equals === 'function' &&
784
- // @ts-expect-error: maybeValue is typed as `{}`
785
- typeof maybeValue.hashCode === 'function');
752
+ function asImmutable() {
753
+ return this.__ensureOwner();
786
754
  }
787
755
 
788
- /**
789
- * An extension of the "same-value" algorithm as [described for use by ES6 Map
790
- * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
791
- *
792
- * NaN is considered the same as NaN, however -0 and 0 are considered the same
793
- * value, which is different from the algorithm described by
794
- * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
795
- *
796
- * This is extended further to allow Objects to describe the values they
797
- * represent, by way of `valueOf` or `equals` (and `hashCode`).
798
- *
799
- * Note: because of this extension, the key equality of Immutable.Map and the
800
- * value equality of Immutable.Set will differ from ES6 Map and Set.
801
- *
802
- * ### Defining custom values
803
- *
804
- * The easiest way to describe the value an object represents is by implementing
805
- * `valueOf`. For example, `Date` represents a value by returning a unix
806
- * timestamp for `valueOf`:
807
- *
808
- * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
809
- * var date2 = new Date(1234567890000);
810
- * date1.valueOf(); // 1234567890000
811
- * assert( date1 !== date2 );
812
- * assert( Immutable.is( date1, date2 ) );
813
- *
814
- * Note: overriding `valueOf` may have other implications if you use this object
815
- * where JavaScript expects a primitive, such as implicit string coercion.
816
- *
817
- * For more complex types, especially collections, implementing `valueOf` may
818
- * not be performant. An alternative is to implement `equals` and `hashCode`.
819
- *
820
- * `equals` takes another object, presumably of similar type, and returns true
821
- * if it is equal. Equality is symmetrical, so the same result should be
822
- * returned if this and the argument are flipped.
823
- *
824
- * assert( a.equals(b) === b.equals(a) );
825
- *
826
- * `hashCode` returns a 32bit integer number representing the object which will
827
- * be used to determine how to store the value object in a Map or Set. You must
828
- * provide both or neither methods, one must not exist without the other.
829
- *
830
- * Also, an important relationship between these methods must be upheld: if two
831
- * values are equal, they *must* return the same hashCode. If the values are not
832
- * equal, they might have the same hashCode; this is called a hash collision,
833
- * and while undesirable for performance reasons, it is acceptable.
834
- *
835
- * if (a.equals(b)) {
836
- * assert( a.hashCode() === b.hashCode() );
837
- * }
838
- *
839
- * All Immutable collections are Value Objects: they implement `equals()`
840
- * and `hashCode()`.
841
- */
842
- function is(valueA, valueB) {
843
- if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
844
- return true;
845
- }
846
- if (!valueA || !valueB) {
847
- return false;
848
- }
849
- if (typeof valueA.valueOf === 'function' &&
850
- typeof valueB.valueOf === 'function') {
851
- valueA = valueA.valueOf();
852
- valueB = valueB.valueOf();
853
- if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
854
- return true;
855
- }
856
- if (!valueA || !valueB) {
857
- return false;
858
- }
859
- }
860
- return !!(isValueObject(valueA) &&
861
- isValueObject(valueB) &&
862
- valueA.equals(valueB));
756
+ function asMutable() {
757
+ return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
863
758
  }
864
759
 
865
- var imul =
866
- typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
760
+ // TODO remove in v6 as Math.imul is widely available now: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
761
+ var imul = typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
867
762
  ? Math.imul
868
763
  : function imul(a, b) {
869
764
  a |= 0; // int
@@ -872,247 +767,238 @@
872
767
  var d = b & 0xffff;
873
768
  // Shift by 0 fixes the sign on the high part.
874
769
  return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
875
- };
876
-
770
+ };
877
771
  // v8 has an optimization for storing 31-bit signed numbers.
878
772
  // Values which have either 00 or 11 as the high order bits qualify.
879
773
  // This function drops the highest order bit in a signed number, maintaining
880
774
  // the sign bit.
881
775
  function smi(i32) {
882
- return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
776
+ return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
883
777
  }
884
778
 
885
779
  var defaultValueOf = Object.prototype.valueOf;
886
-
887
780
  function hash(o) {
888
- // eslint-disable-next-line eqeqeq
889
- if (o == null) {
890
- return hashNullish(o);
891
- }
892
-
893
- if (typeof o.hashCode === 'function') {
894
- // Drop any high bits from accidentally long hash codes.
895
- return smi(o.hashCode(o));
896
- }
897
-
898
- var v = valueOf(o);
899
-
900
- // eslint-disable-next-line eqeqeq
901
- if (v == null) {
902
- return hashNullish(v);
903
- }
904
-
905
- switch (typeof v) {
906
- case 'boolean':
907
- // The hash values for built-in constants are a 1 value for each 5-byte
908
- // shift region expect for the first, which encodes the value. This
909
- // reduces the odds of a hash collision for these common values.
910
- return v ? 0x42108421 : 0x42108420;
911
- case 'number':
912
- return hashNumber(v);
913
- case 'string':
914
- return v.length > STRING_HASH_CACHE_MIN_STRLEN
915
- ? cachedHashString(v)
916
- : hashString(v);
917
- case 'object':
918
- case 'function':
919
- return hashJSObj(v);
920
- case 'symbol':
921
- return hashSymbol(v);
922
- default:
923
- if (typeof v.toString === 'function') {
924
- return hashString(v.toString());
925
- }
926
- throw new Error('Value type ' + typeof v + ' cannot be hashed.');
927
- }
781
+ // eslint-disable-next-line eqeqeq
782
+ if (o == null) {
783
+ return hashNullish(o);
784
+ }
785
+ // @ts-expect-error don't care about object beeing typed as `{}` here
786
+ if (typeof o.hashCode === 'function') {
787
+ // Drop any high bits from accidentally long hash codes.
788
+ // @ts-expect-error don't care about object beeing typed as `{}` here
789
+ return smi(o.hashCode(o));
790
+ }
791
+ var v = valueOf(o);
792
+ // eslint-disable-next-line eqeqeq
793
+ if (v == null) {
794
+ return hashNullish(v);
795
+ }
796
+ switch (typeof v) {
797
+ case 'boolean':
798
+ // The hash values for built-in constants are a 1 value for each 5-byte
799
+ // shift region expect for the first, which encodes the value. This
800
+ // reduces the odds of a hash collision for these common values.
801
+ return v ? 0x42108421 : 0x42108420;
802
+ case 'number':
803
+ return hashNumber(v);
804
+ case 'string':
805
+ return v.length > STRING_HASH_CACHE_MIN_STRLEN
806
+ ? cachedHashString(v)
807
+ : hashString(v);
808
+ case 'object':
809
+ case 'function':
810
+ return hashJSObj(v);
811
+ case 'symbol':
812
+ return hashSymbol(v);
813
+ default:
814
+ if (typeof v.toString === 'function') {
815
+ return hashString(v.toString());
816
+ }
817
+ throw new Error('Value type ' + typeof v + ' cannot be hashed.');
818
+ }
928
819
  }
929
-
930
820
  function hashNullish(nullish) {
931
- return nullish === null ? 0x42108422 : /* undefined */ 0x42108423;
821
+ return nullish === null ? 0x42108422 : /* undefined */ 0x42108423;
932
822
  }
933
-
934
823
  // Compress arbitrarily large numbers into smi hashes.
935
824
  function hashNumber(n) {
936
- if (n !== n || n === Infinity) {
937
- return 0;
938
- }
939
- var hash = n | 0;
940
- if (hash !== n) {
941
- hash ^= n * 0xffffffff;
942
- }
943
- while (n > 0xffffffff) {
944
- n /= 0xffffffff;
945
- hash ^= n;
946
- }
947
- return smi(hash);
825
+ if (n !== n || n === Infinity) {
826
+ return 0;
827
+ }
828
+ var hash = n | 0;
829
+ if (hash !== n) {
830
+ hash ^= n * 0xffffffff;
831
+ }
832
+ while (n > 0xffffffff) {
833
+ n /= 0xffffffff;
834
+ hash ^= n;
835
+ }
836
+ return smi(hash);
948
837
  }
949
-
950
838
  function cachedHashString(string) {
951
- var hashed = stringHashCache[string];
952
- if (hashed === undefined) {
953
- hashed = hashString(string);
954
- if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
955
- STRING_HASH_CACHE_SIZE = 0;
956
- stringHashCache = {};
839
+ var hashed = stringHashCache[string];
840
+ if (hashed === undefined) {
841
+ hashed = hashString(string);
842
+ if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
843
+ STRING_HASH_CACHE_SIZE = 0;
844
+ stringHashCache = {};
845
+ }
846
+ STRING_HASH_CACHE_SIZE++;
847
+ stringHashCache[string] = hashed;
957
848
  }
958
- STRING_HASH_CACHE_SIZE++;
959
- stringHashCache[string] = hashed;
960
- }
961
- return hashed;
849
+ return hashed;
962
850
  }
963
-
964
851
  // http://jsperf.com/hashing-strings
965
852
  function hashString(string) {
966
- // This is the hash from JVM
967
- // The hash code for a string is computed as
968
- // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
969
- // where s[i] is the ith character of the string and n is the length of
970
- // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
971
- // (exclusive) by dropping high bits.
972
- var hashed = 0;
973
- for (var ii = 0; ii < string.length; ii++) {
974
- hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
975
- }
976
- return smi(hashed);
853
+ // This is the hash from JVM
854
+ // The hash code for a string is computed as
855
+ // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
856
+ // where s[i] is the ith character of the string and n is the length of
857
+ // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
858
+ // (exclusive) by dropping high bits.
859
+ var hashed = 0;
860
+ for (var ii = 0; ii < string.length; ii++) {
861
+ hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
862
+ }
863
+ return smi(hashed);
977
864
  }
978
-
979
865
  function hashSymbol(sym) {
980
- var hashed = symbolMap[sym];
981
- if (hashed !== undefined) {
866
+ var hashed = symbolMap[sym];
867
+ if (hashed !== undefined) {
868
+ return hashed;
869
+ }
870
+ hashed = nextHash();
871
+ symbolMap[sym] = hashed;
982
872
  return hashed;
983
- }
984
-
985
- hashed = nextHash();
986
-
987
- symbolMap[sym] = hashed;
988
-
989
- return hashed;
990
873
  }
991
-
874
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
992
875
  function hashJSObj(obj) {
993
- var hashed;
994
- if (usingWeakMap) {
995
- hashed = weakMap.get(obj);
996
- if (hashed !== undefined) {
997
- return hashed;
876
+ var hashed;
877
+ if (usingWeakMap) {
878
+ // @ts-expect-error weakMap is defined
879
+ hashed = weakMap.get(obj);
880
+ if (hashed !== undefined) {
881
+ return hashed;
882
+ }
998
883
  }
999
- }
1000
-
1001
- hashed = obj[UID_HASH_KEY];
1002
- if (hashed !== undefined) {
1003
- return hashed;
1004
- }
1005
-
1006
- if (!canDefineProperty) {
1007
- hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
884
+ // @ts-expect-error used for old code, will be removed
885
+ hashed = obj[UID_HASH_KEY];
1008
886
  if (hashed !== undefined) {
1009
- return hashed;
887
+ return hashed;
1010
888
  }
1011
-
1012
- hashed = getIENodeHash(obj);
1013
- if (hashed !== undefined) {
1014
- return hashed;
889
+ if (!canDefineProperty) {
890
+ // @ts-expect-error used for old code, will be removed
891
+ hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
892
+ if (hashed !== undefined) {
893
+ return hashed;
894
+ }
895
+ hashed = getIENodeHash(obj);
896
+ if (hashed !== undefined) {
897
+ return hashed;
898
+ }
1015
899
  }
1016
- }
1017
-
1018
- hashed = nextHash();
1019
-
1020
- if (usingWeakMap) {
1021
- weakMap.set(obj, hashed);
1022
- } else if (isExtensible !== undefined && isExtensible(obj) === false) {
1023
- throw new Error('Non-extensible objects are not allowed as keys.');
1024
- } else if (canDefineProperty) {
1025
- Object.defineProperty(obj, UID_HASH_KEY, {
1026
- enumerable: false,
1027
- configurable: false,
1028
- writable: false,
1029
- value: hashed,
1030
- });
1031
- } else if (
1032
- obj.propertyIsEnumerable !== undefined &&
1033
- obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable
1034
- ) {
1035
- // Since we can't define a non-enumerable property on the object
1036
- // we'll hijack one of the less-used non-enumerable properties to
1037
- // save our hash on it. Since this is a function it will not show up in
1038
- // `JSON.stringify` which is what we want.
1039
- obj.propertyIsEnumerable = function () {
1040
- return this.constructor.prototype.propertyIsEnumerable.apply(
1041
- this,
1042
- arguments
1043
- );
1044
- };
1045
- obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
1046
- } else if (obj.nodeType !== undefined) {
1047
- // At this point we couldn't get the IE `uniqueID` to use as a hash
1048
- // and we couldn't use a non-enumerable property to exploit the
1049
- // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
1050
- // itself.
1051
- obj[UID_HASH_KEY] = hashed;
1052
- } else {
1053
- throw new Error('Unable to set a non-enumerable property on object.');
1054
- }
1055
-
1056
- return hashed;
900
+ hashed = nextHash();
901
+ if (usingWeakMap) {
902
+ // @ts-expect-error weakMap is defined
903
+ weakMap.set(obj, hashed);
904
+ }
905
+ else if (isExtensible !== undefined && isExtensible(obj) === false) {
906
+ throw new Error('Non-extensible objects are not allowed as keys.');
907
+ }
908
+ else if (canDefineProperty) {
909
+ Object.defineProperty(obj, UID_HASH_KEY, {
910
+ enumerable: false,
911
+ configurable: false,
912
+ writable: false,
913
+ value: hashed,
914
+ });
915
+ }
916
+ else if (obj.propertyIsEnumerable !== undefined &&
917
+ obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
918
+ // Since we can't define a non-enumerable property on the object
919
+ // we'll hijack one of the less-used non-enumerable properties to
920
+ // save our hash on it. Since this is a function it will not show up in
921
+ // `JSON.stringify` which is what we want.
922
+ obj.propertyIsEnumerable = function () {
923
+ return this.constructor.prototype.propertyIsEnumerable.apply(this,
924
+ // eslint-disable-next-line prefer-rest-params
925
+ arguments);
926
+ };
927
+ // @ts-expect-error used for old code, will be removed
928
+ obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
929
+ // @ts-expect-error used for old code, will be removed
930
+ }
931
+ else if (obj.nodeType !== undefined) {
932
+ // At this point we couldn't get the IE `uniqueID` to use as a hash
933
+ // and we couldn't use a non-enumerable property to exploit the
934
+ // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
935
+ // itself.
936
+ // @ts-expect-error used for old code, will be removed
937
+ obj[UID_HASH_KEY] = hashed;
938
+ }
939
+ else {
940
+ throw new Error('Unable to set a non-enumerable property on object.');
941
+ }
942
+ return hashed;
1057
943
  }
1058
-
1059
944
  // Get references to ES5 object methods.
1060
945
  var isExtensible = Object.isExtensible;
1061
-
1062
946
  // True if Object.defineProperty works as expected. IE8 fails this test.
947
+ // TODO remove this as widely available https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
1063
948
  var canDefineProperty = (function () {
1064
- try {
1065
- Object.defineProperty({}, '@', {});
1066
- return true;
1067
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1068
- } catch (e) {
1069
- return false;
1070
- }
949
+ try {
950
+ Object.defineProperty({}, '@', {});
951
+ return true;
952
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
953
+ }
954
+ catch (e) {
955
+ return false;
956
+ }
1071
957
  })();
1072
-
1073
958
  // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
1074
959
  // and avoid memory leaks from the IE cloneNode bug.
960
+ // TODO remove this method as only used if `canDefineProperty` is false
1075
961
  function getIENodeHash(node) {
1076
- if (node && node.nodeType > 0) {
1077
- switch (node.nodeType) {
1078
- case 1: // Element
1079
- return node.uniqueID;
1080
- case 9: // Document
1081
- return node.documentElement && node.documentElement.uniqueID;
962
+ // @ts-expect-error don't care
963
+ if (node && node.nodeType > 0) {
964
+ // @ts-expect-error don't care
965
+ switch (node.nodeType) {
966
+ case 1: // Element
967
+ // @ts-expect-error don't care
968
+ return node.uniqueID;
969
+ case 9: // Document
970
+ // @ts-expect-error don't care
971
+ return node.documentElement && node.documentElement.uniqueID;
972
+ }
1082
973
  }
1083
- }
1084
974
  }
1085
-
1086
975
  function valueOf(obj) {
1087
- return obj.valueOf !== defaultValueOf && typeof obj.valueOf === 'function'
1088
- ? obj.valueOf(obj)
1089
- : obj;
976
+ return obj.valueOf !== defaultValueOf && typeof obj.valueOf === 'function'
977
+ ? // @ts-expect-error weird the "obj" parameter as `valueOf` should not have a parameter
978
+ obj.valueOf(obj)
979
+ : obj;
1090
980
  }
1091
-
1092
981
  function nextHash() {
1093
- var nextHash = ++_objHashUID;
1094
- if (_objHashUID & 0x40000000) {
1095
- _objHashUID = 0;
1096
- }
1097
- return nextHash;
982
+ var nextHash = ++_objHashUID;
983
+ if (_objHashUID & 0x40000000) {
984
+ _objHashUID = 0;
985
+ }
986
+ return nextHash;
1098
987
  }
1099
-
1100
988
  // If possible, use a WeakMap.
989
+ // TODO using WeakMap should be true everywhere now that WeakMap is widely supported: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap
1101
990
  var usingWeakMap = typeof WeakMap === 'function';
1102
991
  var weakMap;
1103
992
  if (usingWeakMap) {
1104
- weakMap = new WeakMap();
993
+ weakMap = new WeakMap();
1105
994
  }
1106
-
1107
995
  var symbolMap = Object.create(null);
1108
-
1109
996
  var _objHashUID = 0;
1110
-
997
+ // TODO remove string as Symbol is now widely supported: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
1111
998
  var UID_HASH_KEY = '__immutablehash__';
1112
999
  if (typeof Symbol === 'function') {
1113
- UID_HASH_KEY = Symbol(UID_HASH_KEY);
1000
+ UID_HASH_KEY = Symbol(UID_HASH_KEY);
1114
1001
  }
1115
-
1116
1002
  var STRING_HASH_CACHE_MIN_STRLEN = 16;
1117
1003
  var STRING_HASH_CACHE_MAX_SIZE = 255;
1118
1004
  var STRING_HASH_CACHE_SIZE = 0;
@@ -2128,255 +2014,102 @@
2128
2014
  return a > b ? 1 : a < b ? -1 : 0;
2129
2015
  }
2130
2016
 
2131
- // http://jsperf.com/copy-array-inline
2132
- function arrCopy(arr, offset) {
2133
- offset = offset || 0;
2134
- var len = Math.max(0, arr.length - offset);
2135
- var newArr = new Array(len);
2136
- for (var ii = 0; ii < len; ii++) {
2137
- // @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design
2138
- newArr[ii] = arr[ii + offset];
2139
- }
2140
- return newArr;
2141
- }
2142
-
2143
- function invariant(condition, error) {
2144
- if (!condition)
2145
- { throw new Error(error); }
2146
- }
2147
-
2148
- function assertNotInfinite(size) {
2149
- invariant(size !== Infinity, 'Cannot perform this action with an infinite size.');
2150
- }
2151
-
2152
- function coerceKeyPath(keyPath) {
2153
- if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
2154
- return keyPath;
2155
- }
2156
- if (isOrdered(keyPath)) {
2157
- return keyPath.toArray();
2158
- }
2159
- throw new TypeError('Invalid keyPath: expected Ordered Collection or Array: ' + keyPath);
2160
- }
2161
-
2162
- var toString = Object.prototype.toString;
2163
- function isPlainObject(value) {
2164
- // The base prototype's toString deals with Argument objects and native namespaces like Math
2165
- if (!value ||
2166
- typeof value !== 'object' ||
2167
- toString.call(value) !== '[object Object]') {
2168
- return false;
2169
- }
2170
- var proto = Object.getPrototypeOf(value);
2171
- if (proto === null) {
2172
- return true;
2173
- }
2174
- // Iteratively going up the prototype chain is needed for cross-realm environments (differing contexts, iframes, etc)
2175
- var parentProto = proto;
2176
- var nextProto = Object.getPrototypeOf(proto);
2177
- while (nextProto !== null) {
2178
- parentProto = nextProto;
2179
- nextProto = Object.getPrototypeOf(parentProto);
2180
- }
2181
- return parentProto === proto;
2182
- }
2183
-
2184
2017
  /**
2185
- * Returns true if the value is a potentially-persistent data structure, either
2186
- * provided by Immutable.js or a plain Array or Object.
2187
- */
2188
- function isDataStructure(value) {
2189
- return (typeof value === 'object' &&
2190
- (isImmutable(value) || Array.isArray(value) || isPlainObject(value)));
2191
- }
2192
-
2193
- /**
2194
- * Converts a value to a string, adding quotes if a string was provided.
2018
+ * True if `maybeValue` is a JavaScript Object which has *both* `equals()`
2019
+ * and `hashCode()` methods.
2020
+ *
2021
+ * Any two instances of *value objects* can be compared for value equality with
2022
+ * `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
2195
2023
  */
2196
- function quoteString(value) {
2197
- try {
2198
- return typeof value === 'string' ? JSON.stringify(value) : String(value);
2199
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2200
- }
2201
- catch (_ignoreError) {
2202
- return JSON.stringify(value);
2203
- }
2024
+ function isValueObject(maybeValue) {
2025
+ return Boolean(maybeValue &&
2026
+ // @ts-expect-error: maybeValue is typed as `{}`
2027
+ typeof maybeValue.equals === 'function' &&
2028
+ // @ts-expect-error: maybeValue is typed as `{}`
2029
+ typeof maybeValue.hashCode === 'function');
2204
2030
  }
2205
2031
 
2206
2032
  /**
2207
- * Returns true if the key is defined in the provided collection.
2033
+ * An extension of the "same-value" algorithm as [described for use by ES6 Map
2034
+ * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
2208
2035
  *
2209
- * A functional alternative to `collection.has(key)` which will also work with
2210
- * plain Objects and Arrays as an alternative for
2211
- * `collection.hasOwnProperty(key)`.
2036
+ * NaN is considered the same as NaN, however -0 and 0 are considered the same
2037
+ * value, which is different from the algorithm described by
2038
+ * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
2039
+ *
2040
+ * This is extended further to allow Objects to describe the values they
2041
+ * represent, by way of `valueOf` or `equals` (and `hashCode`).
2042
+ *
2043
+ * Note: because of this extension, the key equality of Immutable.Map and the
2044
+ * value equality of Immutable.Set will differ from ES6 Map and Set.
2045
+ *
2046
+ * ### Defining custom values
2047
+ *
2048
+ * The easiest way to describe the value an object represents is by implementing
2049
+ * `valueOf`. For example, `Date` represents a value by returning a unix
2050
+ * timestamp for `valueOf`:
2051
+ *
2052
+ * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
2053
+ * var date2 = new Date(1234567890000);
2054
+ * date1.valueOf(); // 1234567890000
2055
+ * assert( date1 !== date2 );
2056
+ * assert( Immutable.is( date1, date2 ) );
2057
+ *
2058
+ * Note: overriding `valueOf` may have other implications if you use this object
2059
+ * where JavaScript expects a primitive, such as implicit string coercion.
2060
+ *
2061
+ * For more complex types, especially collections, implementing `valueOf` may
2062
+ * not be performant. An alternative is to implement `equals` and `hashCode`.
2063
+ *
2064
+ * `equals` takes another object, presumably of similar type, and returns true
2065
+ * if it is equal. Equality is symmetrical, so the same result should be
2066
+ * returned if this and the argument are flipped.
2067
+ *
2068
+ * assert( a.equals(b) === b.equals(a) );
2069
+ *
2070
+ * `hashCode` returns a 32bit integer number representing the object which will
2071
+ * be used to determine how to store the value object in a Map or Set. You must
2072
+ * provide both or neither methods, one must not exist without the other.
2073
+ *
2074
+ * Also, an important relationship between these methods must be upheld: if two
2075
+ * values are equal, they *must* return the same hashCode. If the values are not
2076
+ * equal, they might have the same hashCode; this is called a hash collision,
2077
+ * and while undesirable for performance reasons, it is acceptable.
2078
+ *
2079
+ * if (a.equals(b)) {
2080
+ * assert( a.hashCode() === b.hashCode() );
2081
+ * }
2082
+ *
2083
+ * All Immutable collections are Value Objects: they implement `equals()`
2084
+ * and `hashCode()`.
2212
2085
  */
2213
- function has(collection, key) {
2214
- return isImmutable(collection)
2215
- ? // @ts-expect-error key might be a number or symbol, which is not handled be Record key type
2216
- collection.has(key)
2217
- : // @ts-expect-error key might be anything else than PropertyKey, and will return false in that case but runtime is OK
2218
- isDataStructure(collection) && hasOwnProperty.call(collection, key);
2219
- }
2220
-
2221
- function get(collection, key, notSetValue) {
2222
- return isImmutable(collection)
2223
- ? collection.get(key, notSetValue)
2224
- : !has(collection, key)
2225
- ? notSetValue
2226
- : // @ts-expect-error weird "get" here,
2227
- typeof collection.get === 'function'
2228
- ? // @ts-expect-error weird "get" here,
2229
- collection.get(key)
2230
- : // @ts-expect-error key is unknown here,
2231
- collection[key];
2232
- }
2233
-
2234
- function shallowCopy(from) {
2235
- if (Array.isArray(from)) {
2236
- return arrCopy(from);
2237
- }
2238
- var to = {};
2239
- for (var key in from) {
2240
- if (hasOwnProperty.call(from, key)) {
2241
- to[key] = from[key];
2242
- }
2086
+ function is(valueA, valueB) {
2087
+ if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
2088
+ return true;
2243
2089
  }
2244
- return to;
2245
- }
2246
-
2247
- function remove(collection, key) {
2248
- if (!isDataStructure(collection)) {
2249
- throw new TypeError('Cannot update non-data-structure value: ' + collection);
2090
+ if (!valueA || !valueB) {
2091
+ return false;
2250
2092
  }
2251
- if (isImmutable(collection)) {
2252
- // @ts-expect-error weird "remove" here,
2253
- if (!collection.remove) {
2254
- throw new TypeError('Cannot update immutable value without .remove() method: ' + collection);
2093
+ if (typeof valueA.valueOf === 'function' &&
2094
+ typeof valueB.valueOf === 'function') {
2095
+ valueA = valueA.valueOf();
2096
+ valueB = valueB.valueOf();
2097
+ if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
2098
+ return true;
2255
2099
  }
2256
- // @ts-expect-error weird "remove" here,
2257
- return collection.remove(key);
2258
- }
2259
- // @ts-expect-error assert that key is a string, a number or a symbol here
2260
- if (!hasOwnProperty.call(collection, key)) {
2261
- return collection;
2262
- }
2263
- var collectionCopy = shallowCopy(collection);
2264
- if (Array.isArray(collectionCopy)) {
2265
- // @ts-expect-error assert that key is a number here
2266
- collectionCopy.splice(key, 1);
2267
- }
2268
- else {
2269
- // @ts-expect-error assert that key is a string, a number or a symbol here
2270
- delete collectionCopy[key];
2271
- }
2272
- return collectionCopy;
2273
- }
2274
-
2275
- function set(collection, key, value) {
2276
- if (!isDataStructure(collection)) {
2277
- throw new TypeError('Cannot update non-data-structure value: ' + collection);
2278
- }
2279
- if (isImmutable(collection)) {
2280
- // @ts-expect-error weird "set" here,
2281
- if (!collection.set) {
2282
- throw new TypeError('Cannot update immutable value without .set() method: ' + collection);
2100
+ if (!valueA || !valueB) {
2101
+ return false;
2283
2102
  }
2284
- // @ts-expect-error weird "set" here,
2285
- return collection.set(key, value);
2286
- }
2287
- // @ts-expect-error mix of key and string here. Probably need a more fine type here
2288
- if (hasOwnProperty.call(collection, key) && value === collection[key]) {
2289
- return collection;
2290
- }
2291
- var collectionCopy = shallowCopy(collection);
2292
- // @ts-expect-error mix of key and string here. Probably need a more fine type here
2293
- collectionCopy[key] = value;
2294
- return collectionCopy;
2295
- }
2296
-
2297
- function updateIn$1(collection, keyPath, notSetValue, updater) {
2298
- if (!updater) {
2299
- // handle the fact that `notSetValue` is optional here, in that case `updater` is the updater function
2300
- // @ts-expect-error updater is a function here
2301
- updater = notSetValue;
2302
- notSetValue = undefined;
2303
- }
2304
- var updatedValue = updateInDeeply(isImmutable(collection),
2305
- // @ts-expect-error type issues with Record and mixed types
2306
- collection, coerceKeyPath(keyPath), 0, notSetValue, updater);
2307
- // @ts-expect-error mixed return type
2308
- return updatedValue === NOT_SET ? notSetValue : updatedValue;
2309
- }
2310
- function updateInDeeply(inImmutable, existing, keyPath, i, notSetValue, updater) {
2311
- var wasNotSet = existing === NOT_SET;
2312
- if (i === keyPath.length) {
2313
- var existingValue = wasNotSet ? notSetValue : existing;
2314
- // @ts-expect-error mixed type with optional value
2315
- var newValue = updater(existingValue);
2316
- // @ts-expect-error mixed type
2317
- return newValue === existingValue ? existing : newValue;
2318
- }
2319
- if (!wasNotSet && !isDataStructure(existing)) {
2320
- throw new TypeError('Cannot update within non-data-structure value in path [' +
2321
- Array.from(keyPath).slice(0, i).map(quoteString) +
2322
- ']: ' +
2323
- existing);
2324
- }
2325
- var key = keyPath[i];
2326
- var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
2327
- var nextUpdated = updateInDeeply(nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
2328
- // @ts-expect-error mixed type
2329
- nextExisting, keyPath, i + 1, notSetValue, updater);
2330
- return nextUpdated === nextExisting
2331
- ? existing
2332
- : nextUpdated === NOT_SET
2333
- ? remove(existing, key)
2334
- : set(wasNotSet ? (inImmutable ? emptyMap() : {}) : existing, key, nextUpdated);
2335
- }
2336
-
2337
- /**
2338
- * Returns a copy of the collection with the value at the key path set to the
2339
- * provided value.
2340
- *
2341
- * A functional alternative to `collection.setIn(keypath)` which will also
2342
- * work with plain Objects and Arrays.
2343
- */
2344
- function setIn$1(collection, keyPath, value) {
2345
- return updateIn$1(collection, keyPath, NOT_SET, function () { return value; });
2346
- }
2347
-
2348
- function setIn(keyPath, v) {
2349
- return setIn$1(this, keyPath, v);
2350
- }
2351
-
2352
- /**
2353
- * Returns a copy of the collection with the value at the key path removed.
2354
- *
2355
- * A functional alternative to `collection.removeIn(keypath)` which will also
2356
- * work with plain Objects and Arrays.
2357
- */
2358
- function removeIn(collection, keyPath) {
2359
- return updateIn$1(collection, keyPath, function () { return NOT_SET; });
2360
- }
2361
-
2362
- function deleteIn(keyPath) {
2363
- return removeIn(this, keyPath);
2364
- }
2365
-
2366
- function update$1(collection, key, notSetValue, updater) {
2367
- return updateIn$1(
2368
- // @ts-expect-error Index signature for type string is missing in type V[]
2369
- collection, [key], notSetValue, updater);
2370
- }
2371
-
2372
- function update(key, notSetValue, updater) {
2373
- return arguments.length === 1
2374
- ? key(this)
2375
- : update$1(this, key, notSetValue, updater);
2103
+ }
2104
+ return !!(isValueObject(valueA) &&
2105
+ isValueObject(valueB) &&
2106
+ valueA.equals(valueB));
2376
2107
  }
2377
2108
 
2378
- function updateIn(keyPath, notSetValue, updater) {
2379
- return updateIn$1(this, keyPath, notSetValue, updater);
2109
+ function update$1(collection, key, notSetValue, updater) {
2110
+ return updateIn(
2111
+ // @ts-expect-error Index signature for type string is missing in type V[]
2112
+ collection, [key], notSetValue, updater);
2380
2113
  }
2381
2114
 
2382
2115
  function merge$1() {
@@ -2431,6 +2164,62 @@
2431
2164
  });
2432
2165
  }
2433
2166
 
2167
+ var toString = Object.prototype.toString;
2168
+ function isPlainObject(value) {
2169
+ // The base prototype's toString deals with Argument objects and native namespaces like Math
2170
+ if (!value ||
2171
+ typeof value !== 'object' ||
2172
+ toString.call(value) !== '[object Object]') {
2173
+ return false;
2174
+ }
2175
+ var proto = Object.getPrototypeOf(value);
2176
+ if (proto === null) {
2177
+ return true;
2178
+ }
2179
+ // Iteratively going up the prototype chain is needed for cross-realm environments (differing contexts, iframes, etc)
2180
+ var parentProto = proto;
2181
+ var nextProto = Object.getPrototypeOf(proto);
2182
+ while (nextProto !== null) {
2183
+ parentProto = nextProto;
2184
+ nextProto = Object.getPrototypeOf(parentProto);
2185
+ }
2186
+ return parentProto === proto;
2187
+ }
2188
+
2189
+ /**
2190
+ * Returns true if the value is a potentially-persistent data structure, either
2191
+ * provided by Immutable.js or a plain Array or Object.
2192
+ */
2193
+ function isDataStructure(value) {
2194
+ return (typeof value === 'object' &&
2195
+ (isImmutable(value) || Array.isArray(value) || isPlainObject(value)));
2196
+ }
2197
+
2198
+ // http://jsperf.com/copy-array-inline
2199
+ function arrCopy(arr, offset) {
2200
+ offset = offset || 0;
2201
+ var len = Math.max(0, arr.length - offset);
2202
+ var newArr = new Array(len);
2203
+ for (var ii = 0; ii < len; ii++) {
2204
+ // @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design
2205
+ newArr[ii] = arr[ii + offset];
2206
+ }
2207
+ return newArr;
2208
+ }
2209
+
2210
+ function shallowCopy(from) {
2211
+ if (Array.isArray(from)) {
2212
+ return arrCopy(from);
2213
+ }
2214
+ var to = {};
2215
+ for (var key in from) {
2216
+ if (hasOwnProperty.call(from, key)) {
2217
+ to[key] = from[key];
2218
+ }
2219
+ }
2220
+ return to;
2221
+ }
2222
+
2434
2223
  function merge(collection) {
2435
2224
  var sources = [], len = arguments.length - 1;
2436
2225
  while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
@@ -2548,19 +2337,48 @@
2548
2337
  return mergeDeepWithSources(this, iters, merger);
2549
2338
  }
2550
2339
 
2551
- function mergeIn(keyPath) {
2340
+ function mergeDeepIn(keyPath) {
2552
2341
  var iters = [], len = arguments.length - 1;
2553
2342
  while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
2554
2343
 
2555
- return updateIn$1(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
2344
+ return updateIn(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
2345
+ );
2556
2346
  }
2557
2347
 
2558
- function mergeDeepIn(keyPath) {
2348
+ function mergeIn(keyPath) {
2559
2349
  var iters = [], len = arguments.length - 1;
2560
2350
  while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
2561
2351
 
2562
- return updateIn$1(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
2563
- );
2352
+ return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
2353
+ }
2354
+
2355
+ /**
2356
+ * Returns a copy of the collection with the value at the key path set to the
2357
+ * provided value.
2358
+ *
2359
+ * A functional alternative to `collection.setIn(keypath)` which will also
2360
+ * work with plain Objects and Arrays.
2361
+ */
2362
+ function setIn$1(collection, keyPath, value) {
2363
+ return updateIn(collection, keyPath, NOT_SET, function () { return value; });
2364
+ }
2365
+
2366
+ function setIn(keyPath, v) {
2367
+ return setIn$1(this, keyPath, v);
2368
+ }
2369
+
2370
+ function update(key, notSetValue, updater) {
2371
+ return arguments.length === 1
2372
+ ? key(this)
2373
+ : update$1(this, key, notSetValue, updater);
2374
+ }
2375
+
2376
+ function updateIn$1(keyPath, notSetValue, updater) {
2377
+ return updateIn(this, keyPath, notSetValue, updater);
2378
+ }
2379
+
2380
+ function wasAltered() {
2381
+ return this.__altered;
2564
2382
  }
2565
2383
 
2566
2384
  function withMutations(fn) {
@@ -2569,16 +2387,25 @@
2569
2387
  return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
2570
2388
  }
2571
2389
 
2572
- function asMutable() {
2573
- return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
2390
+ var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
2391
+ /**
2392
+ * True if `maybeMap` is a Map.
2393
+ *
2394
+ * Also true for OrderedMaps.
2395
+ */
2396
+ function isMap(maybeMap) {
2397
+ return Boolean(maybeMap &&
2398
+ // @ts-expect-error: maybeMap is typed as `{}`, need to change in 6.0 to `maybeMap && typeof maybeMap === 'object' && IS_MAP_SYMBOL in maybeMap`
2399
+ maybeMap[IS_MAP_SYMBOL]);
2574
2400
  }
2575
2401
 
2576
- function asImmutable() {
2577
- return this.__ensureOwner();
2402
+ function invariant(condition, error) {
2403
+ if (!condition)
2404
+ { throw new Error(error); }
2578
2405
  }
2579
2406
 
2580
- function wasAltered() {
2581
- return this.__altered;
2407
+ function assertNotInfinite(size) {
2408
+ invariant(size !== Infinity, 'Cannot perform this action with an infinite size.');
2582
2409
  }
2583
2410
 
2584
2411
  var Map = /*@__PURE__*/(function (KeyedCollection) {
@@ -2715,7 +2542,7 @@
2715
2542
  MapPrototype.setIn = setIn;
2716
2543
  MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
2717
2544
  MapPrototype.update = update;
2718
- MapPrototype.updateIn = updateIn;
2545
+ MapPrototype.updateIn = updateIn$1;
2719
2546
  MapPrototype.merge = MapPrototype.concat = merge$1;
2720
2547
  MapPrototype.mergeWith = mergeWith$1;
2721
2548
  MapPrototype.mergeDeep = mergeDeep;
@@ -3317,45 +3144,200 @@
3317
3144
  return newArray;
3318
3145
  }
3319
3146
 
3320
- function spliceIn(array, idx, val, canEdit) {
3321
- var newLen = array.length + 1;
3322
- if (canEdit && idx + 1 === newLen) {
3323
- array[idx] = val;
3324
- return array;
3325
- }
3326
- var newArray = new Array(newLen);
3327
- var after = 0;
3328
- for (var ii = 0; ii < newLen; ii++) {
3329
- if (ii === idx) {
3330
- newArray[ii] = val;
3331
- after = -1;
3332
- } else {
3333
- newArray[ii] = array[ii + after];
3147
+ function spliceIn(array, idx, val, canEdit) {
3148
+ var newLen = array.length + 1;
3149
+ if (canEdit && idx + 1 === newLen) {
3150
+ array[idx] = val;
3151
+ return array;
3152
+ }
3153
+ var newArray = new Array(newLen);
3154
+ var after = 0;
3155
+ for (var ii = 0; ii < newLen; ii++) {
3156
+ if (ii === idx) {
3157
+ newArray[ii] = val;
3158
+ after = -1;
3159
+ } else {
3160
+ newArray[ii] = array[ii + after];
3161
+ }
3162
+ }
3163
+ return newArray;
3164
+ }
3165
+
3166
+ function spliceOut(array, idx, canEdit) {
3167
+ var newLen = array.length - 1;
3168
+ if (canEdit && idx === newLen) {
3169
+ array.pop();
3170
+ return array;
3171
+ }
3172
+ var newArray = new Array(newLen);
3173
+ var after = 0;
3174
+ for (var ii = 0; ii < newLen; ii++) {
3175
+ if (ii === idx) {
3176
+ after = 1;
3177
+ }
3178
+ newArray[ii] = array[ii + after];
3179
+ }
3180
+ return newArray;
3181
+ }
3182
+
3183
+ var MAX_ARRAY_MAP_SIZE = SIZE / 4;
3184
+ var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
3185
+ var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
3186
+
3187
+ function coerceKeyPath(keyPath) {
3188
+ if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
3189
+ return keyPath;
3190
+ }
3191
+ if (isOrdered(keyPath)) {
3192
+ return keyPath.toArray();
3193
+ }
3194
+ throw new TypeError('Invalid keyPath: expected Ordered Collection or Array: ' + keyPath);
3195
+ }
3196
+
3197
+ /**
3198
+ * Converts a value to a string, adding quotes if a string was provided.
3199
+ */
3200
+ function quoteString(value) {
3201
+ try {
3202
+ return typeof value === 'string' ? JSON.stringify(value) : String(value);
3203
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3204
+ }
3205
+ catch (_ignoreError) {
3206
+ return JSON.stringify(value);
3207
+ }
3208
+ }
3209
+
3210
+ /**
3211
+ * Returns true if the key is defined in the provided collection.
3212
+ *
3213
+ * A functional alternative to `collection.has(key)` which will also work with
3214
+ * plain Objects and Arrays as an alternative for
3215
+ * `collection.hasOwnProperty(key)`.
3216
+ */
3217
+ function has(collection, key) {
3218
+ return isImmutable(collection)
3219
+ ? // @ts-expect-error key might be a number or symbol, which is not handled be Record key type
3220
+ collection.has(key)
3221
+ : // @ts-expect-error key might be anything else than PropertyKey, and will return false in that case but runtime is OK
3222
+ isDataStructure(collection) && hasOwnProperty.call(collection, key);
3223
+ }
3224
+
3225
+ function get(collection, key, notSetValue) {
3226
+ return isImmutable(collection)
3227
+ ? collection.get(key, notSetValue)
3228
+ : !has(collection, key)
3229
+ ? notSetValue
3230
+ : // @ts-expect-error weird "get" here,
3231
+ typeof collection.get === 'function'
3232
+ ? // @ts-expect-error weird "get" here,
3233
+ collection.get(key)
3234
+ : // @ts-expect-error key is unknown here,
3235
+ collection[key];
3236
+ }
3237
+
3238
+ function remove(collection, key) {
3239
+ if (!isDataStructure(collection)) {
3240
+ throw new TypeError('Cannot update non-data-structure value: ' + collection);
3241
+ }
3242
+ if (isImmutable(collection)) {
3243
+ // @ts-expect-error weird "remove" here,
3244
+ if (!collection.remove) {
3245
+ throw new TypeError('Cannot update immutable value without .remove() method: ' + collection);
3246
+ }
3247
+ // @ts-expect-error weird "remove" here,
3248
+ return collection.remove(key);
3249
+ }
3250
+ // @ts-expect-error assert that key is a string, a number or a symbol here
3251
+ if (!hasOwnProperty.call(collection, key)) {
3252
+ return collection;
3253
+ }
3254
+ var collectionCopy = shallowCopy(collection);
3255
+ if (Array.isArray(collectionCopy)) {
3256
+ // @ts-expect-error assert that key is a number here
3257
+ collectionCopy.splice(key, 1);
3258
+ }
3259
+ else {
3260
+ // @ts-expect-error assert that key is a string, a number or a symbol here
3261
+ delete collectionCopy[key];
3262
+ }
3263
+ return collectionCopy;
3264
+ }
3265
+
3266
+ function set(collection, key, value) {
3267
+ if (!isDataStructure(collection)) {
3268
+ throw new TypeError('Cannot update non-data-structure value: ' + collection);
3269
+ }
3270
+ if (isImmutable(collection)) {
3271
+ // @ts-expect-error weird "set" here,
3272
+ if (!collection.set) {
3273
+ throw new TypeError('Cannot update immutable value without .set() method: ' + collection);
3274
+ }
3275
+ // @ts-expect-error weird "set" here,
3276
+ return collection.set(key, value);
3277
+ }
3278
+ // @ts-expect-error mix of key and string here. Probably need a more fine type here
3279
+ if (hasOwnProperty.call(collection, key) && value === collection[key]) {
3280
+ return collection;
3281
+ }
3282
+ var collectionCopy = shallowCopy(collection);
3283
+ // @ts-expect-error mix of key and string here. Probably need a more fine type here
3284
+ collectionCopy[key] = value;
3285
+ return collectionCopy;
3286
+ }
3287
+
3288
+ function updateIn(collection, keyPath, notSetValue, updater) {
3289
+ if (!updater) {
3290
+ // handle the fact that `notSetValue` is optional here, in that case `updater` is the updater function
3291
+ // @ts-expect-error updater is a function here
3292
+ updater = notSetValue;
3293
+ notSetValue = undefined;
3334
3294
  }
3335
- }
3336
- return newArray;
3295
+ var updatedValue = updateInDeeply(isImmutable(collection),
3296
+ // @ts-expect-error type issues with Record and mixed types
3297
+ collection, coerceKeyPath(keyPath), 0, notSetValue, updater);
3298
+ // @ts-expect-error mixed return type
3299
+ return updatedValue === NOT_SET ? notSetValue : updatedValue;
3337
3300
  }
3338
-
3339
- function spliceOut(array, idx, canEdit) {
3340
- var newLen = array.length - 1;
3341
- if (canEdit && idx === newLen) {
3342
- array.pop();
3343
- return array;
3344
- }
3345
- var newArray = new Array(newLen);
3346
- var after = 0;
3347
- for (var ii = 0; ii < newLen; ii++) {
3348
- if (ii === idx) {
3349
- after = 1;
3301
+ function updateInDeeply(inImmutable, existing, keyPath, i, notSetValue, updater) {
3302
+ var wasNotSet = existing === NOT_SET;
3303
+ if (i === keyPath.length) {
3304
+ var existingValue = wasNotSet ? notSetValue : existing;
3305
+ // @ts-expect-error mixed type with optional value
3306
+ var newValue = updater(existingValue);
3307
+ // @ts-expect-error mixed type
3308
+ return newValue === existingValue ? existing : newValue;
3350
3309
  }
3351
- newArray[ii] = array[ii + after];
3352
- }
3353
- return newArray;
3310
+ if (!wasNotSet && !isDataStructure(existing)) {
3311
+ throw new TypeError('Cannot update within non-data-structure value in path [' +
3312
+ Array.from(keyPath).slice(0, i).map(quoteString) +
3313
+ ']: ' +
3314
+ existing);
3315
+ }
3316
+ var key = keyPath[i];
3317
+ var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
3318
+ var nextUpdated = updateInDeeply(nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
3319
+ // @ts-expect-error mixed type
3320
+ nextExisting, keyPath, i + 1, notSetValue, updater);
3321
+ return nextUpdated === nextExisting
3322
+ ? existing
3323
+ : nextUpdated === NOT_SET
3324
+ ? remove(existing, key)
3325
+ : set(wasNotSet ? (inImmutable ? emptyMap() : {}) : existing, key, nextUpdated);
3354
3326
  }
3355
3327
 
3356
- var MAX_ARRAY_MAP_SIZE = SIZE / 4;
3357
- var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
3358
- var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
3328
+ /**
3329
+ * Returns a copy of the collection with the value at the key path removed.
3330
+ *
3331
+ * A functional alternative to `collection.removeIn(keypath)` which will also
3332
+ * work with plain Objects and Arrays.
3333
+ */
3334
+ function removeIn(collection, keyPath) {
3335
+ return updateIn(collection, keyPath, function () { return NOT_SET; });
3336
+ }
3337
+
3338
+ function deleteIn(keyPath) {
3339
+ return removeIn(this, keyPath);
3340
+ }
3359
3341
 
3360
3342
  var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
3361
3343
  /**
@@ -3616,7 +3598,7 @@
3616
3598
  ListPrototype.setIn = setIn;
3617
3599
  ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
3618
3600
  ListPrototype.update = update;
3619
- ListPrototype.updateIn = updateIn;
3601
+ ListPrototype.updateIn = updateIn$1;
3620
3602
  ListPrototype.mergeIn = mergeIn;
3621
3603
  ListPrototype.mergeDeepIn = mergeDeepIn;
3622
3604
  ListPrototype.withMutations = withMutations;
@@ -4048,6 +4030,13 @@
4048
4030
  return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
4049
4031
  }
4050
4032
 
4033
+ /**
4034
+ * True if `maybeOrderedMap` is an OrderedMap.
4035
+ */
4036
+ function isOrderedMap(maybeOrderedMap) {
4037
+ return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
4038
+ }
4039
+
4051
4040
  var OrderedMap = /*@__PURE__*/(function (Map) {
4052
4041
  function OrderedMap(value) {
4053
4042
  // eslint-disable-next-line no-constructor-return
@@ -4446,23 +4435,45 @@
4446
4435
  return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
4447
4436
  }
4448
4437
 
4449
- var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
4450
- /**
4451
- * True if `maybeSet` is a Set.
4452
- *
4453
- * Also true for OrderedSets.
4454
- */
4455
- function isSet(maybeSet) {
4456
- return Boolean(maybeSet &&
4457
- // @ts-expect-error: maybeSet is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSet === 'object' && MAYBE_SET_SYMBOL in maybeSet`
4458
- maybeSet[IS_SET_SYMBOL]);
4438
+ function reduce(collection, reducer, reduction, context, useFirst, reverse) {
4439
+ // @ts-expect-error Migrate to CollectionImpl in v6
4440
+ assertNotInfinite(collection.size);
4441
+ // @ts-expect-error Migrate to CollectionImpl in v6
4442
+ collection.__iterate(function (v, k, c) {
4443
+ if (useFirst) {
4444
+ useFirst = false;
4445
+ reduction = v;
4446
+ }
4447
+ else {
4448
+ reduction = reducer.call(context, reduction, v, k, c);
4449
+ }
4450
+ }, reverse);
4451
+ return reduction;
4459
4452
  }
4453
+ function keyMapper(v, k) {
4454
+ return k;
4455
+ }
4456
+ function entryMapper(v, k) {
4457
+ return [k, v];
4458
+ }
4459
+ function not(predicate) {
4460
+ return function () {
4461
+ var args = [], len = arguments.length;
4462
+ while ( len-- ) args[ len ] = arguments[ len ];
4460
4463
 
4461
- /**
4462
- * True if `maybeOrderedSet` is an OrderedSet.
4463
- */
4464
- function isOrderedSet(maybeOrderedSet) {
4465
- return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
4464
+ return !predicate.apply(this, args);
4465
+ };
4466
+ }
4467
+ function neg(predicate) {
4468
+ return function () {
4469
+ var args = [], len = arguments.length;
4470
+ while ( len-- ) args[ len ] = arguments[ len ];
4471
+
4472
+ return -predicate.apply(this, args);
4473
+ };
4474
+ }
4475
+ function defaultNegComparator(a, b) {
4476
+ return a < b ? 1 : a > b ? -1 : 0;
4466
4477
  }
4467
4478
 
4468
4479
  function deepEqual(a, b) {
@@ -4535,44 +4546,154 @@
4535
4546
  }
4536
4547
 
4537
4548
  /**
4538
- * Contributes additional methods to a constructor
4549
+ * Returns a lazy seq of nums from start (inclusive) to end
4550
+ * (exclusive), by step, where start defaults to 0, step to 1, and end to
4551
+ * infinity. When start is equal to end, returns empty list.
4552
+ */
4553
+ var Range = /*@__PURE__*/(function (IndexedSeq) {
4554
+ function Range(start, end, step) {
4555
+ if ( step === void 0 ) step = 1;
4556
+
4557
+ if (!(this instanceof Range)) {
4558
+ // eslint-disable-next-line no-constructor-return
4559
+ return new Range(start, end, step);
4560
+ }
4561
+ invariant(step !== 0, 'Cannot step a Range by 0');
4562
+ invariant(
4563
+ start !== undefined,
4564
+ 'You must define a start value when using Range'
4565
+ );
4566
+ invariant(
4567
+ end !== undefined,
4568
+ 'You must define an end value when using Range'
4569
+ );
4570
+
4571
+ step = Math.abs(step);
4572
+ if (end < start) {
4573
+ step = -step;
4574
+ }
4575
+ this._start = start;
4576
+ this._end = end;
4577
+ this._step = step;
4578
+ this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
4579
+ if (this.size === 0) {
4580
+ if (EMPTY_RANGE) {
4581
+ // eslint-disable-next-line no-constructor-return
4582
+ return EMPTY_RANGE;
4583
+ }
4584
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
4585
+ EMPTY_RANGE = this;
4586
+ }
4587
+ }
4588
+
4589
+ if ( IndexedSeq ) Range.__proto__ = IndexedSeq;
4590
+ Range.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
4591
+ Range.prototype.constructor = Range;
4592
+
4593
+ Range.prototype.toString = function toString () {
4594
+ return this.size === 0
4595
+ ? 'Range []'
4596
+ : ("Range [ " + (this._start) + "..." + (this._end) + (this._step !== 1 ? ' by ' + this._step : '') + " ]");
4597
+ };
4598
+
4599
+ Range.prototype.get = function get (index, notSetValue) {
4600
+ return this.has(index)
4601
+ ? this._start + wrapIndex(this, index) * this._step
4602
+ : notSetValue;
4603
+ };
4604
+
4605
+ Range.prototype.includes = function includes (searchValue) {
4606
+ var possibleIndex = (searchValue - this._start) / this._step;
4607
+ return (
4608
+ possibleIndex >= 0 &&
4609
+ possibleIndex < this.size &&
4610
+ possibleIndex === Math.floor(possibleIndex)
4611
+ );
4612
+ };
4613
+
4614
+ Range.prototype.slice = function slice (begin, end) {
4615
+ if (wholeSlice(begin, end, this.size)) {
4616
+ return this;
4617
+ }
4618
+ begin = resolveBegin(begin, this.size);
4619
+ end = resolveEnd(end, this.size);
4620
+ if (end <= begin) {
4621
+ return new Range(0, 0);
4622
+ }
4623
+ return new Range(
4624
+ this.get(begin, this._end),
4625
+ this.get(end, this._end),
4626
+ this._step
4627
+ );
4628
+ };
4629
+
4630
+ Range.prototype.indexOf = function indexOf (searchValue) {
4631
+ var offsetValue = searchValue - this._start;
4632
+ if (offsetValue % this._step === 0) {
4633
+ var index = offsetValue / this._step;
4634
+ if (index >= 0 && index < this.size) {
4635
+ return index;
4636
+ }
4637
+ }
4638
+ return -1;
4639
+ };
4640
+
4641
+ Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
4642
+ return this.indexOf(searchValue);
4643
+ };
4644
+
4645
+ Range.prototype.__iterate = function __iterate (fn, reverse) {
4646
+ var size = this.size;
4647
+ var step = this._step;
4648
+ var value = reverse ? this._start + (size - 1) * step : this._start;
4649
+ var i = 0;
4650
+ while (i !== size) {
4651
+ if (fn(value, reverse ? size - ++i : i++, this) === false) {
4652
+ break;
4653
+ }
4654
+ value += reverse ? -step : step;
4655
+ }
4656
+ return i;
4657
+ };
4658
+
4659
+ Range.prototype.__iterator = function __iterator (type, reverse) {
4660
+ var size = this.size;
4661
+ var step = this._step;
4662
+ var value = reverse ? this._start + (size - 1) * step : this._start;
4663
+ var i = 0;
4664
+ return new Iterator(function () {
4665
+ if (i === size) {
4666
+ return iteratorDone();
4667
+ }
4668
+ var v = value;
4669
+ value += reverse ? -step : step;
4670
+ return iteratorValue(type, reverse ? size - ++i : i++, v);
4671
+ });
4672
+ };
4673
+
4674
+ Range.prototype.equals = function equals (other) {
4675
+ return other instanceof Range
4676
+ ? this._start === other._start &&
4677
+ this._end === other._end &&
4678
+ this._step === other._step
4679
+ : deepEqual(this, other);
4680
+ };
4681
+
4682
+ return Range;
4683
+ }(IndexedSeq));
4684
+
4685
+ var EMPTY_RANGE;
4686
+
4687
+ var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
4688
+ /**
4689
+ * True if `maybeSet` is a Set.
4690
+ *
4691
+ * Also true for OrderedSets.
4539
4692
  */
4540
- function mixin(ctor,
4541
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
4542
- methods) {
4543
- var keyCopier = function (key) {
4544
- // @ts-expect-error how to handle symbol ?
4545
- ctor.prototype[key] = methods[key];
4546
- };
4547
- Object.keys(methods).forEach(keyCopier);
4548
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
4549
- Object.getOwnPropertySymbols &&
4550
- Object.getOwnPropertySymbols(methods).forEach(keyCopier);
4551
- return ctor;
4552
- }
4553
-
4554
- function toJS(value) {
4555
- if (!value || typeof value !== 'object') {
4556
- return value;
4557
- }
4558
- if (!isCollection(value)) {
4559
- if (!isDataStructure(value)) {
4560
- return value;
4561
- }
4562
- value = Seq(value);
4563
- }
4564
- if (isKeyed(value)) {
4565
- var result$1 = {};
4566
- value.__iterate(function (v, k) {
4567
- result$1[k] = toJS(v);
4568
- });
4569
- return result$1;
4570
- }
4571
- var result = [];
4572
- value.__iterate(function (v) {
4573
- result.push(toJS(v));
4574
- });
4575
- return result;
4693
+ function isSet(maybeSet) {
4694
+ return Boolean(maybeSet &&
4695
+ // @ts-expect-error: maybeSet is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSet === 'object' && MAYBE_SET_SYMBOL in maybeSet`
4696
+ maybeSet[IS_SET_SYMBOL]);
4576
4697
  }
4577
4698
 
4578
4699
  var Set = /*@__PURE__*/(function (SetCollection) {
@@ -4817,145 +4938,6 @@
4817
4938
  return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
4818
4939
  }
4819
4940
 
4820
- /**
4821
- * Returns a lazy seq of nums from start (inclusive) to end
4822
- * (exclusive), by step, where start defaults to 0, step to 1, and end to
4823
- * infinity. When start is equal to end, returns empty list.
4824
- */
4825
- var Range = /*@__PURE__*/(function (IndexedSeq) {
4826
- function Range(start, end, step) {
4827
- if ( step === void 0 ) step = 1;
4828
-
4829
- if (!(this instanceof Range)) {
4830
- // eslint-disable-next-line no-constructor-return
4831
- return new Range(start, end, step);
4832
- }
4833
- invariant(step !== 0, 'Cannot step a Range by 0');
4834
- invariant(
4835
- start !== undefined,
4836
- 'You must define a start value when using Range'
4837
- );
4838
- invariant(
4839
- end !== undefined,
4840
- 'You must define an end value when using Range'
4841
- );
4842
-
4843
- step = Math.abs(step);
4844
- if (end < start) {
4845
- step = -step;
4846
- }
4847
- this._start = start;
4848
- this._end = end;
4849
- this._step = step;
4850
- this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
4851
- if (this.size === 0) {
4852
- if (EMPTY_RANGE) {
4853
- // eslint-disable-next-line no-constructor-return
4854
- return EMPTY_RANGE;
4855
- }
4856
- // eslint-disable-next-line @typescript-eslint/no-this-alias
4857
- EMPTY_RANGE = this;
4858
- }
4859
- }
4860
-
4861
- if ( IndexedSeq ) Range.__proto__ = IndexedSeq;
4862
- Range.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
4863
- Range.prototype.constructor = Range;
4864
-
4865
- Range.prototype.toString = function toString () {
4866
- return this.size === 0
4867
- ? 'Range []'
4868
- : ("Range [ " + (this._start) + "..." + (this._end) + (this._step !== 1 ? ' by ' + this._step : '') + " ]");
4869
- };
4870
-
4871
- Range.prototype.get = function get (index, notSetValue) {
4872
- return this.has(index)
4873
- ? this._start + wrapIndex(this, index) * this._step
4874
- : notSetValue;
4875
- };
4876
-
4877
- Range.prototype.includes = function includes (searchValue) {
4878
- var possibleIndex = (searchValue - this._start) / this._step;
4879
- return (
4880
- possibleIndex >= 0 &&
4881
- possibleIndex < this.size &&
4882
- possibleIndex === Math.floor(possibleIndex)
4883
- );
4884
- };
4885
-
4886
- Range.prototype.slice = function slice (begin, end) {
4887
- if (wholeSlice(begin, end, this.size)) {
4888
- return this;
4889
- }
4890
- begin = resolveBegin(begin, this.size);
4891
- end = resolveEnd(end, this.size);
4892
- if (end <= begin) {
4893
- return new Range(0, 0);
4894
- }
4895
- return new Range(
4896
- this.get(begin, this._end),
4897
- this.get(end, this._end),
4898
- this._step
4899
- );
4900
- };
4901
-
4902
- Range.prototype.indexOf = function indexOf (searchValue) {
4903
- var offsetValue = searchValue - this._start;
4904
- if (offsetValue % this._step === 0) {
4905
- var index = offsetValue / this._step;
4906
- if (index >= 0 && index < this.size) {
4907
- return index;
4908
- }
4909
- }
4910
- return -1;
4911
- };
4912
-
4913
- Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
4914
- return this.indexOf(searchValue);
4915
- };
4916
-
4917
- Range.prototype.__iterate = function __iterate (fn, reverse) {
4918
- var size = this.size;
4919
- var step = this._step;
4920
- var value = reverse ? this._start + (size - 1) * step : this._start;
4921
- var i = 0;
4922
- while (i !== size) {
4923
- if (fn(value, reverse ? size - ++i : i++, this) === false) {
4924
- break;
4925
- }
4926
- value += reverse ? -step : step;
4927
- }
4928
- return i;
4929
- };
4930
-
4931
- Range.prototype.__iterator = function __iterator (type, reverse) {
4932
- var size = this.size;
4933
- var step = this._step;
4934
- var value = reverse ? this._start + (size - 1) * step : this._start;
4935
- var i = 0;
4936
- return new Iterator(function () {
4937
- if (i === size) {
4938
- return iteratorDone();
4939
- }
4940
- var v = value;
4941
- value += reverse ? -step : step;
4942
- return iteratorValue(type, reverse ? size - ++i : i++, v);
4943
- });
4944
- };
4945
-
4946
- Range.prototype.equals = function equals (other) {
4947
- return other instanceof Range
4948
- ? this._start === other._start &&
4949
- this._end === other._end &&
4950
- this._step === other._step
4951
- : deepEqual(this, other);
4952
- };
4953
-
4954
- return Range;
4955
- }(IndexedSeq));
4956
-
4957
- var EMPTY_RANGE;
4958
-
4959
4941
  /**
4960
4942
  * Returns the value at the provided key path starting at the provided
4961
4943
  * collection, or notSetValue if the key path is not defined.
@@ -5003,6 +4985,91 @@
5003
4985
  return object;
5004
4986
  }
5005
4987
 
4988
+ function toJS(value) {
4989
+ if (!value || typeof value !== 'object') {
4990
+ return value;
4991
+ }
4992
+ if (!isCollection(value)) {
4993
+ if (!isDataStructure(value)) {
4994
+ return value;
4995
+ }
4996
+ // @ts-expect-error until Seq has been migrated to TypeScript
4997
+ value = Seq(value);
4998
+ }
4999
+ if (isKeyed(value)) {
5000
+ var result$1 = {};
5001
+ // @ts-expect-error `__iterate` exists on all Keyed collections but method is not defined in the type
5002
+ value.__iterate(function (v, k) {
5003
+ result$1[k] = toJS(v);
5004
+ });
5005
+ return result$1;
5006
+ }
5007
+ var result = [];
5008
+ // @ts-expect-error value "should" be a non-keyed collection, but we may need to assert for stricter types
5009
+ value.__iterate(function (v) {
5010
+ result.push(toJS(v));
5011
+ });
5012
+ return result;
5013
+ }
5014
+
5015
+ function hashCollection(collection) {
5016
+ // @ts-expect-error Migrate to CollectionImpl in v6
5017
+ if (collection.size === Infinity) {
5018
+ return 0;
5019
+ }
5020
+ var ordered = isOrdered(collection);
5021
+ var keyed = isKeyed(collection);
5022
+ var h = ordered ? 1 : 0;
5023
+ // @ts-expect-error Migrate to CollectionImpl in v6
5024
+ collection.__iterate(keyed
5025
+ ? ordered
5026
+ ? function (v, k) {
5027
+ h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
5028
+ }
5029
+ : function (v, k) {
5030
+ h = (h + hashMerge(hash(v), hash(k))) | 0;
5031
+ }
5032
+ : ordered
5033
+ ? function (v) {
5034
+ h = (31 * h + hash(v)) | 0;
5035
+ }
5036
+ : function (v) {
5037
+ h = (h + hash(v)) | 0;
5038
+ });
5039
+ // @ts-expect-error Migrate to CollectionImpl in v6
5040
+ return murmurHashOfSize(collection.size, h);
5041
+ }
5042
+ function murmurHashOfSize(size, h) {
5043
+ h = imul(h, 0xcc9e2d51);
5044
+ h = imul((h << 15) | (h >>> -15), 0x1b873593);
5045
+ h = imul((h << 13) | (h >>> -13), 5);
5046
+ h = ((h + 0xe6546b64) | 0) ^ size;
5047
+ h = imul(h ^ (h >>> 16), 0x85ebca6b);
5048
+ h = imul(h ^ (h >>> 13), 0xc2b2ae35);
5049
+ h = smi(h ^ (h >>> 16));
5050
+ return h;
5051
+ }
5052
+ function hashMerge(a, b) {
5053
+ return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
5054
+ }
5055
+
5056
+ /**
5057
+ * Contributes additional methods to a constructor
5058
+ */
5059
+ function mixin(ctor,
5060
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
5061
+ methods) {
5062
+ var keyCopier = function (key) {
5063
+ // @ts-expect-error how to handle symbol ?
5064
+ ctor.prototype[key] = methods[key];
5065
+ };
5066
+ Object.keys(methods).forEach(keyCopier);
5067
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
5068
+ Object.getOwnPropertySymbols &&
5069
+ Object.getOwnPropertySymbols(methods).forEach(keyCopier);
5070
+ return ctor;
5071
+ }
5072
+
5006
5073
  Collection.Iterator = Iterator;
5007
5074
 
5008
5075
  mixin(Collection, {
@@ -5641,89 +5708,15 @@
5641
5708
 
5642
5709
  // #pragma Helper functions
5643
5710
 
5644
- function reduce(collection, reducer, reduction, context, useFirst, reverse) {
5645
- assertNotInfinite(collection.size);
5646
- collection.__iterate(function (v, k, c) {
5647
- if (useFirst) {
5648
- useFirst = false;
5649
- reduction = v;
5650
- } else {
5651
- reduction = reducer.call(context, reduction, v, k, c);
5652
- }
5653
- }, reverse);
5654
- return reduction;
5655
- }
5656
-
5657
- function keyMapper(v, k) {
5658
- return k;
5659
- }
5660
-
5661
- function entryMapper(v, k) {
5662
- return [k, v];
5663
- }
5664
-
5665
- function not(predicate) {
5666
- return function () {
5667
- return !predicate.apply(this, arguments);
5668
- };
5669
- }
5670
-
5671
- function neg(predicate) {
5672
- return function () {
5673
- return -predicate.apply(this, arguments);
5674
- };
5675
- }
5676
-
5677
5711
  function defaultZipper() {
5678
5712
  return arrCopy(arguments);
5679
5713
  }
5680
5714
 
5681
- function defaultNegComparator(a, b) {
5682
- return a < b ? 1 : a > b ? -1 : 0;
5683
- }
5684
-
5685
- function hashCollection(collection) {
5686
- if (collection.size === Infinity) {
5687
- return 0;
5688
- }
5689
- var ordered = isOrdered(collection);
5690
- var keyed = isKeyed(collection);
5691
- var h = ordered ? 1 : 0;
5692
-
5693
- collection.__iterate(
5694
- keyed
5695
- ? ordered
5696
- ? function (v, k) {
5697
- h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
5698
- }
5699
- : function (v, k) {
5700
- h = (h + hashMerge(hash(v), hash(k))) | 0;
5701
- }
5702
- : ordered
5703
- ? function (v) {
5704
- h = (31 * h + hash(v)) | 0;
5705
- }
5706
- : function (v) {
5707
- h = (h + hash(v)) | 0;
5708
- }
5709
- );
5710
-
5711
- return murmurHashOfSize(collection.size, h);
5712
- }
5713
-
5714
- function murmurHashOfSize(size, h) {
5715
- h = imul(h, 0xcc9e2d51);
5716
- h = imul((h << 15) | (h >>> -15), 0x1b873593);
5717
- h = imul((h << 13) | (h >>> -13), 5);
5718
- h = ((h + 0xe6546b64) | 0) ^ size;
5719
- h = imul(h ^ (h >>> 16), 0x85ebca6b);
5720
- h = imul(h ^ (h >>> 13), 0xc2b2ae35);
5721
- h = smi(h ^ (h >>> 16));
5722
- return h;
5723
- }
5724
-
5725
- function hashMerge(a, b) {
5726
- return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
5715
+ /**
5716
+ * True if `maybeOrderedSet` is an OrderedSet.
5717
+ */
5718
+ function isOrderedSet(maybeOrderedSet) {
5719
+ return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
5727
5720
  }
5728
5721
 
5729
5722
  var OrderedSet = /*@__PURE__*/(function (Set) {
@@ -5785,9 +5778,12 @@
5785
5778
  );
5786
5779
  }
5787
5780
 
5781
+ /**
5782
+ * Describes which item in a pair should be placed first when sorting
5783
+ */
5788
5784
  var PairSorting = {
5789
- LeftThenRight: -1,
5790
- RightThenLeft: 1,
5785
+ LeftThenRight: -1,
5786
+ RightThenLeft: 1,
5791
5787
  };
5792
5788
 
5793
5789
  function throwOnInvalidDefaultValues(defaultValues) {
@@ -5992,7 +5988,7 @@
5992
5988
  RecordPrototype.mergeDeepIn = mergeDeepIn;
5993
5989
  RecordPrototype.setIn = setIn;
5994
5990
  RecordPrototype.update = update;
5995
- RecordPrototype.updateIn = updateIn;
5991
+ RecordPrototype.updateIn = updateIn$1;
5996
5992
  RecordPrototype.withMutations = withMutations;
5997
5993
  RecordPrototype.asMutable = asMutable;
5998
5994
  RecordPrototype.asImmutable = asImmutable;
@@ -6180,7 +6176,9 @@
6180
6176
  return isIndexed(v) ? v.toList() : isKeyed(v) ? v.toMap() : v.toSet();
6181
6177
  }
6182
6178
 
6183
- var version = "5.1.3";
6179
+ var version = "5.1.4";
6180
+
6181
+ /* eslint-disable import/order */
6184
6182
 
6185
6183
  // Note: Iterable is deprecated
6186
6184
  var Iterable = Collection;
@@ -6230,7 +6228,7 @@
6230
6228
  exports.set = set;
6231
6229
  exports.setIn = setIn$1;
6232
6230
  exports.update = update$1;
6233
- exports.updateIn = updateIn$1;
6231
+ exports.updateIn = updateIn;
6234
6232
  exports.version = version;
6235
6233
 
6236
6234
  }));