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