immutable 5.1.3 → 5.1.5

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,257 +2008,104 @@ 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
- /**
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
2011
  /**
2188
- * Converts a value to a string, adding quotes if a string was provided.
2189
- */
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
- }
2198
- }
2199
-
2200
- /**
2201
- * Returns true if the key is defined in the provided collection.
2012
+ * True if `maybeValue` is a JavaScript Object which has *both* `equals()`
2013
+ * and `hashCode()` methods.
2202
2014
  *
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)`.
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`.
2206
2017
  */
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
- }
2237
- }
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);
2244
- }
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);
2249
- }
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);
2277
- }
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);
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');
2329
2024
  }
2330
2025
 
2331
2026
  /**
2332
- * Returns a copy of the collection with the value at the key path set to the
2333
- * provided value.
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)
2334
2029
  *
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.
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).
2348
2033
  *
2349
- * A functional alternative to `collection.removeIn(keypath)` which will also
2350
- * work with plain Objects and Arrays.
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()`.
2351
2079
  */
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);
2080
+ function is(valueA, valueB) {
2081
+ if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
2082
+ return true;
2083
+ }
2084
+ if (!valueA || !valueB) {
2085
+ return false;
2086
+ }
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;
2093
+ }
2094
+ if (!valueA || !valueB) {
2095
+ return false;
2096
+ }
2097
+ }
2098
+ return !!(isValueObject(valueA) &&
2099
+ isValueObject(valueB) &&
2100
+ valueA.equals(valueB));
2358
2101
  }
2359
2102
 
2360
2103
  function update$1(collection, key, notSetValue, updater) {
2361
- return updateIn$1(
2104
+ return updateIn(
2362
2105
  // @ts-expect-error Index signature for type string is missing in type V[]
2363
2106
  collection, [key], notSetValue, updater);
2364
2107
  }
2365
2108
 
2366
- function update(key, notSetValue, updater) {
2367
- return arguments.length === 1
2368
- ? key(this)
2369
- : update$1(this, key, notSetValue, updater);
2370
- }
2371
-
2372
- function updateIn(keyPath, notSetValue, updater) {
2373
- return updateIn$1(this, keyPath, notSetValue, updater);
2374
- }
2375
-
2376
2109
  function merge$1() {
2377
2110
  var iters = [], len = arguments.length;
2378
2111
  while ( len-- ) iters[ len ] = arguments[ len ];
@@ -2425,6 +2158,69 @@ 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
+ function isProtoKey(key) {
2193
+ return (typeof key === 'string' && (key === '__proto__' || key === 'constructor'));
2194
+ }
2195
+
2196
+ // http://jsperf.com/copy-array-inline
2197
+ function arrCopy(arr, offset) {
2198
+ offset = offset || 0;
2199
+ var len = Math.max(0, arr.length - offset);
2200
+ var newArr = new Array(len);
2201
+ for (var ii = 0; ii < len; ii++) {
2202
+ // @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design
2203
+ newArr[ii] = arr[ii + offset];
2204
+ }
2205
+ return newArr;
2206
+ }
2207
+
2208
+ function shallowCopy(from) {
2209
+ if (Array.isArray(from)) {
2210
+ return arrCopy(from);
2211
+ }
2212
+ var to = {};
2213
+ for (var key in from) {
2214
+ if (isProtoKey(key)) {
2215
+ continue;
2216
+ }
2217
+ if (hasOwnProperty.call(from, key)) {
2218
+ to[key] = from[key];
2219
+ }
2220
+ }
2221
+ return to;
2222
+ }
2223
+
2428
2224
  function merge(collection) {
2429
2225
  var sources = [], len = arguments.length - 1;
2430
2226
  while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
@@ -2482,6 +2278,10 @@ function mergeWithSources(collection, sources, merger) {
2482
2278
  merged.push(value);
2483
2279
  }
2484
2280
  : function (value, key) {
2281
+ if (isProtoKey(key)) {
2282
+ return;
2283
+ }
2284
+
2485
2285
  var hasVal = hasOwnProperty.call(merged, key);
2486
2286
  var nextVal =
2487
2287
  hasVal && merger ? merger(merged[key], value, key) : value;
@@ -2542,19 +2342,48 @@ function mergeDeepWith(merger) {
2542
2342
  return mergeDeepWithSources(this, iters, merger);
2543
2343
  }
2544
2344
 
2545
- function mergeIn(keyPath) {
2345
+ function mergeDeepIn(keyPath) {
2546
2346
  var iters = [], len = arguments.length - 1;
2547
2347
  while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
2548
2348
 
2549
- return updateIn$1(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
2349
+ return updateIn(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
2350
+ );
2550
2351
  }
2551
2352
 
2552
- function mergeDeepIn(keyPath) {
2353
+ function mergeIn(keyPath) {
2553
2354
  var iters = [], len = arguments.length - 1;
2554
2355
  while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
2555
2356
 
2556
- return updateIn$1(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
2557
- );
2357
+ return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
2358
+ }
2359
+
2360
+ /**
2361
+ * Returns a copy of the collection with the value at the key path set to the
2362
+ * provided value.
2363
+ *
2364
+ * A functional alternative to `collection.setIn(keypath)` which will also
2365
+ * work with plain Objects and Arrays.
2366
+ */
2367
+ function setIn$1(collection, keyPath, value) {
2368
+ return updateIn(collection, keyPath, NOT_SET, function () { return value; });
2369
+ }
2370
+
2371
+ function setIn(keyPath, v) {
2372
+ return setIn$1(this, keyPath, v);
2373
+ }
2374
+
2375
+ function update(key, notSetValue, updater) {
2376
+ return arguments.length === 1
2377
+ ? key(this)
2378
+ : update$1(this, key, notSetValue, updater);
2379
+ }
2380
+
2381
+ function updateIn$1(keyPath, notSetValue, updater) {
2382
+ return updateIn(this, keyPath, notSetValue, updater);
2383
+ }
2384
+
2385
+ function wasAltered() {
2386
+ return this.__altered;
2558
2387
  }
2559
2388
 
2560
2389
  function withMutations(fn) {
@@ -2563,16 +2392,25 @@ function withMutations(fn) {
2563
2392
  return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
2564
2393
  }
2565
2394
 
2566
- function asMutable() {
2567
- return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
2395
+ var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
2396
+ /**
2397
+ * True if `maybeMap` is a Map.
2398
+ *
2399
+ * Also true for OrderedMaps.
2400
+ */
2401
+ function isMap(maybeMap) {
2402
+ return Boolean(maybeMap &&
2403
+ // @ts-expect-error: maybeMap is typed as `{}`, need to change in 6.0 to `maybeMap && typeof maybeMap === 'object' && IS_MAP_SYMBOL in maybeMap`
2404
+ maybeMap[IS_MAP_SYMBOL]);
2568
2405
  }
2569
2406
 
2570
- function asImmutable() {
2571
- return this.__ensureOwner();
2407
+ function invariant(condition, error) {
2408
+ if (!condition)
2409
+ { throw new Error(error); }
2572
2410
  }
2573
2411
 
2574
- function wasAltered() {
2575
- return this.__altered;
2412
+ function assertNotInfinite(size) {
2413
+ invariant(size !== Infinity, 'Cannot perform this action with an infinite size.');
2576
2414
  }
2577
2415
 
2578
2416
  var Map = /*@__PURE__*/(function (KeyedCollection) {
@@ -2709,7 +2547,7 @@ MapPrototype.removeAll = MapPrototype.deleteAll;
2709
2547
  MapPrototype.setIn = setIn;
2710
2548
  MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
2711
2549
  MapPrototype.update = update;
2712
- MapPrototype.updateIn = updateIn;
2550
+ MapPrototype.updateIn = updateIn$1;
2713
2551
  MapPrototype.merge = MapPrototype.concat = merge$1;
2714
2552
  MapPrototype.mergeWith = mergeWith$1;
2715
2553
  MapPrototype.mergeDeep = mergeDeep;
@@ -3326,30 +3164,188 @@ function spliceIn(array, idx, val, canEdit) {
3326
3164
  } else {
3327
3165
  newArray[ii] = array[ii + after];
3328
3166
  }
3329
- }
3330
- return newArray;
3167
+ }
3168
+ return newArray;
3169
+ }
3170
+
3171
+ function spliceOut(array, idx, canEdit) {
3172
+ var newLen = array.length - 1;
3173
+ if (canEdit && idx === newLen) {
3174
+ array.pop();
3175
+ return array;
3176
+ }
3177
+ var newArray = new Array(newLen);
3178
+ var after = 0;
3179
+ for (var ii = 0; ii < newLen; ii++) {
3180
+ if (ii === idx) {
3181
+ after = 1;
3182
+ }
3183
+ newArray[ii] = array[ii + after];
3184
+ }
3185
+ return newArray;
3186
+ }
3187
+
3188
+ var MAX_ARRAY_MAP_SIZE = SIZE / 4;
3189
+ var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
3190
+ var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
3191
+
3192
+ function coerceKeyPath(keyPath) {
3193
+ if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
3194
+ return keyPath;
3195
+ }
3196
+ if (isOrdered(keyPath)) {
3197
+ return keyPath.toArray();
3198
+ }
3199
+ throw new TypeError('Invalid keyPath: expected Ordered Collection or Array: ' + keyPath);
3200
+ }
3201
+
3202
+ /**
3203
+ * Converts a value to a string, adding quotes if a string was provided.
3204
+ */
3205
+ function quoteString(value) {
3206
+ try {
3207
+ return typeof value === 'string' ? JSON.stringify(value) : String(value);
3208
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3209
+ }
3210
+ catch (_ignoreError) {
3211
+ return JSON.stringify(value);
3212
+ }
3213
+ }
3214
+
3215
+ /**
3216
+ * Returns true if the key is defined in the provided collection.
3217
+ *
3218
+ * A functional alternative to `collection.has(key)` which will also work with
3219
+ * plain Objects and Arrays as an alternative for
3220
+ * `collection.hasOwnProperty(key)`.
3221
+ */
3222
+ function has(collection, key) {
3223
+ return isImmutable(collection)
3224
+ ? // @ts-expect-error key might be a number or symbol, which is not handled be Record key type
3225
+ collection.has(key)
3226
+ : // @ts-expect-error key might be anything else than PropertyKey, and will return false in that case but runtime is OK
3227
+ isDataStructure(collection) && hasOwnProperty.call(collection, key);
3228
+ }
3229
+
3230
+ function get(collection, key, notSetValue) {
3231
+ return isImmutable(collection)
3232
+ ? collection.get(key, notSetValue)
3233
+ : !has(collection, key)
3234
+ ? notSetValue
3235
+ : // @ts-expect-error weird "get" here,
3236
+ typeof collection.get === 'function'
3237
+ ? // @ts-expect-error weird "get" here,
3238
+ collection.get(key)
3239
+ : // @ts-expect-error key is unknown here,
3240
+ collection[key];
3241
+ }
3242
+
3243
+ function remove(collection, key) {
3244
+ if (!isDataStructure(collection)) {
3245
+ throw new TypeError('Cannot update non-data-structure value: ' + collection);
3246
+ }
3247
+ if (isImmutable(collection)) {
3248
+ // @ts-expect-error weird "remove" here,
3249
+ if (!collection.remove) {
3250
+ throw new TypeError('Cannot update immutable value without .remove() method: ' + collection);
3251
+ }
3252
+ // @ts-expect-error weird "remove" here,
3253
+ return collection.remove(key);
3254
+ }
3255
+ // @ts-expect-error assert that key is a string, a number or a symbol here
3256
+ if (!hasOwnProperty.call(collection, key)) {
3257
+ return collection;
3258
+ }
3259
+ var collectionCopy = shallowCopy(collection);
3260
+ if (Array.isArray(collectionCopy)) {
3261
+ // @ts-expect-error assert that key is a number here
3262
+ collectionCopy.splice(key, 1);
3263
+ }
3264
+ else {
3265
+ // @ts-expect-error assert that key is a string, a number or a symbol here
3266
+ delete collectionCopy[key];
3267
+ }
3268
+ return collectionCopy;
3269
+ }
3270
+
3271
+ function set(collection, key, value) {
3272
+ if (typeof key === 'string' && isProtoKey(key)) {
3273
+ return collection;
3274
+ }
3275
+ if (!isDataStructure(collection)) {
3276
+ throw new TypeError('Cannot update non-data-structure value: ' + collection);
3277
+ }
3278
+ if (isImmutable(collection)) {
3279
+ // @ts-expect-error weird "set" here,
3280
+ if (!collection.set) {
3281
+ throw new TypeError('Cannot update immutable value without .set() method: ' + collection);
3282
+ }
3283
+ // @ts-expect-error weird "set" here,
3284
+ return collection.set(key, value);
3285
+ }
3286
+ // @ts-expect-error mix of key and string here. Probably need a more fine type here
3287
+ if (hasOwnProperty.call(collection, key) && value === collection[key]) {
3288
+ return collection;
3289
+ }
3290
+ var collectionCopy = shallowCopy(collection);
3291
+ // @ts-expect-error mix of key and string here. Probably need a more fine type here
3292
+ collectionCopy[key] = value;
3293
+ return collectionCopy;
3331
3294
  }
3332
3295
 
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;
3296
+ function updateIn(collection, keyPath, notSetValue, updater) {
3297
+ if (!updater) {
3298
+ // handle the fact that `notSetValue` is optional here, in that case `updater` is the updater function
3299
+ // @ts-expect-error updater is a function here
3300
+ updater = notSetValue;
3301
+ notSetValue = undefined;
3344
3302
  }
3345
- newArray[ii] = array[ii + after];
3346
- }
3347
- return newArray;
3303
+ var updatedValue = updateInDeeply(isImmutable(collection),
3304
+ // @ts-expect-error type issues with Record and mixed types
3305
+ collection, coerceKeyPath(keyPath), 0, notSetValue, updater);
3306
+ // @ts-expect-error mixed return type
3307
+ return updatedValue === NOT_SET ? notSetValue : updatedValue;
3308
+ }
3309
+ function updateInDeeply(inImmutable, existing, keyPath, i, notSetValue, updater) {
3310
+ var wasNotSet = existing === NOT_SET;
3311
+ if (i === keyPath.length) {
3312
+ var existingValue = wasNotSet ? notSetValue : existing;
3313
+ // @ts-expect-error mixed type with optional value
3314
+ var newValue = updater(existingValue);
3315
+ // @ts-expect-error mixed type
3316
+ return newValue === existingValue ? existing : newValue;
3317
+ }
3318
+ if (!wasNotSet && !isDataStructure(existing)) {
3319
+ throw new TypeError('Cannot update within non-data-structure value in path [' +
3320
+ Array.from(keyPath).slice(0, i).map(quoteString) +
3321
+ ']: ' +
3322
+ existing);
3323
+ }
3324
+ var key = keyPath[i];
3325
+ var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
3326
+ var nextUpdated = updateInDeeply(nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
3327
+ // @ts-expect-error mixed type
3328
+ nextExisting, keyPath, i + 1, notSetValue, updater);
3329
+ return nextUpdated === nextExisting
3330
+ ? existing
3331
+ : nextUpdated === NOT_SET
3332
+ ? remove(existing, key)
3333
+ : set(wasNotSet ? (inImmutable ? emptyMap() : {}) : existing, key, nextUpdated);
3348
3334
  }
3349
3335
 
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;
3336
+ /**
3337
+ * Returns a copy of the collection with the value at the key path removed.
3338
+ *
3339
+ * A functional alternative to `collection.removeIn(keypath)` which will also
3340
+ * work with plain Objects and Arrays.
3341
+ */
3342
+ function removeIn(collection, keyPath) {
3343
+ return updateIn(collection, keyPath, function () { return NOT_SET; });
3344
+ }
3345
+
3346
+ function deleteIn(keyPath) {
3347
+ return removeIn(this, keyPath);
3348
+ }
3353
3349
 
3354
3350
  var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
3355
3351
  /**
@@ -3610,7 +3606,7 @@ ListPrototype.merge = ListPrototype.concat;
3610
3606
  ListPrototype.setIn = setIn;
3611
3607
  ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
3612
3608
  ListPrototype.update = update;
3613
- ListPrototype.updateIn = updateIn;
3609
+ ListPrototype.updateIn = updateIn$1;
3614
3610
  ListPrototype.mergeIn = mergeIn;
3615
3611
  ListPrototype.mergeDeepIn = mergeDeepIn;
3616
3612
  ListPrototype.withMutations = withMutations;
@@ -4042,6 +4038,13 @@ function getTailOffset(size) {
4042
4038
  return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
4043
4039
  }
4044
4040
 
4041
+ /**
4042
+ * True if `maybeOrderedMap` is an OrderedMap.
4043
+ */
4044
+ function isOrderedMap(maybeOrderedMap) {
4045
+ return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
4046
+ }
4047
+
4045
4048
  var OrderedMap = /*@__PURE__*/(function (Map) {
4046
4049
  function OrderedMap(value) {
4047
4050
  // eslint-disable-next-line no-constructor-return
@@ -4440,23 +4443,45 @@ function emptyStack() {
4440
4443
  return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
4441
4444
  }
4442
4445
 
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]);
4446
+ function reduce(collection, reducer, reduction, context, useFirst, reverse) {
4447
+ // @ts-expect-error Migrate to CollectionImpl in v6
4448
+ assertNotInfinite(collection.size);
4449
+ // @ts-expect-error Migrate to CollectionImpl in v6
4450
+ collection.__iterate(function (v, k, c) {
4451
+ if (useFirst) {
4452
+ useFirst = false;
4453
+ reduction = v;
4454
+ }
4455
+ else {
4456
+ reduction = reducer.call(context, reduction, v, k, c);
4457
+ }
4458
+ }, reverse);
4459
+ return reduction;
4460
+ }
4461
+ function keyMapper(v, k) {
4462
+ return k;
4463
+ }
4464
+ function entryMapper(v, k) {
4465
+ return [k, v];
4453
4466
  }
4467
+ function not(predicate) {
4468
+ return function () {
4469
+ var args = [], len = arguments.length;
4470
+ while ( len-- ) args[ len ] = arguments[ len ];
4454
4471
 
4455
- /**
4456
- * True if `maybeOrderedSet` is an OrderedSet.
4457
- */
4458
- function isOrderedSet(maybeOrderedSet) {
4459
- return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
4472
+ return !predicate.apply(this, args);
4473
+ };
4474
+ }
4475
+ function neg(predicate) {
4476
+ return function () {
4477
+ var args = [], len = arguments.length;
4478
+ while ( len-- ) args[ len ] = arguments[ len ];
4479
+
4480
+ return -predicate.apply(this, args);
4481
+ };
4482
+ }
4483
+ function defaultNegComparator(a, b) {
4484
+ return a < b ? 1 : a > b ? -1 : 0;
4460
4485
  }
4461
4486
 
4462
4487
  function deepEqual(a, b) {
@@ -4529,44 +4554,154 @@ function deepEqual(a, b) {
4529
4554
  }
4530
4555
 
4531
4556
  /**
4532
- * Contributes additional methods to a constructor
4557
+ * Returns a lazy seq of nums from start (inclusive) to end
4558
+ * (exclusive), by step, where start defaults to 0, step to 1, and end to
4559
+ * infinity. When start is equal to end, returns empty list.
4560
+ */
4561
+ var Range = /*@__PURE__*/(function (IndexedSeq) {
4562
+ function Range(start, end, step) {
4563
+ if ( step === void 0 ) step = 1;
4564
+
4565
+ if (!(this instanceof Range)) {
4566
+ // eslint-disable-next-line no-constructor-return
4567
+ return new Range(start, end, step);
4568
+ }
4569
+ invariant(step !== 0, 'Cannot step a Range by 0');
4570
+ invariant(
4571
+ start !== undefined,
4572
+ 'You must define a start value when using Range'
4573
+ );
4574
+ invariant(
4575
+ end !== undefined,
4576
+ 'You must define an end value when using Range'
4577
+ );
4578
+
4579
+ step = Math.abs(step);
4580
+ if (end < start) {
4581
+ step = -step;
4582
+ }
4583
+ this._start = start;
4584
+ this._end = end;
4585
+ this._step = step;
4586
+ this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
4587
+ if (this.size === 0) {
4588
+ if (EMPTY_RANGE) {
4589
+ // eslint-disable-next-line no-constructor-return
4590
+ return EMPTY_RANGE;
4591
+ }
4592
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
4593
+ EMPTY_RANGE = this;
4594
+ }
4595
+ }
4596
+
4597
+ if ( IndexedSeq ) Range.__proto__ = IndexedSeq;
4598
+ Range.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
4599
+ Range.prototype.constructor = Range;
4600
+
4601
+ Range.prototype.toString = function toString () {
4602
+ return this.size === 0
4603
+ ? 'Range []'
4604
+ : ("Range [ " + (this._start) + "..." + (this._end) + (this._step !== 1 ? ' by ' + this._step : '') + " ]");
4605
+ };
4606
+
4607
+ Range.prototype.get = function get (index, notSetValue) {
4608
+ return this.has(index)
4609
+ ? this._start + wrapIndex(this, index) * this._step
4610
+ : notSetValue;
4611
+ };
4612
+
4613
+ Range.prototype.includes = function includes (searchValue) {
4614
+ var possibleIndex = (searchValue - this._start) / this._step;
4615
+ return (
4616
+ possibleIndex >= 0 &&
4617
+ possibleIndex < this.size &&
4618
+ possibleIndex === Math.floor(possibleIndex)
4619
+ );
4620
+ };
4621
+
4622
+ Range.prototype.slice = function slice (begin, end) {
4623
+ if (wholeSlice(begin, end, this.size)) {
4624
+ return this;
4625
+ }
4626
+ begin = resolveBegin(begin, this.size);
4627
+ end = resolveEnd(end, this.size);
4628
+ if (end <= begin) {
4629
+ return new Range(0, 0);
4630
+ }
4631
+ return new Range(
4632
+ this.get(begin, this._end),
4633
+ this.get(end, this._end),
4634
+ this._step
4635
+ );
4636
+ };
4637
+
4638
+ Range.prototype.indexOf = function indexOf (searchValue) {
4639
+ var offsetValue = searchValue - this._start;
4640
+ if (offsetValue % this._step === 0) {
4641
+ var index = offsetValue / this._step;
4642
+ if (index >= 0 && index < this.size) {
4643
+ return index;
4644
+ }
4645
+ }
4646
+ return -1;
4647
+ };
4648
+
4649
+ Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
4650
+ return this.indexOf(searchValue);
4651
+ };
4652
+
4653
+ Range.prototype.__iterate = function __iterate (fn, 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
+ while (i !== size) {
4659
+ if (fn(value, reverse ? size - ++i : i++, this) === false) {
4660
+ break;
4661
+ }
4662
+ value += reverse ? -step : step;
4663
+ }
4664
+ return i;
4665
+ };
4666
+
4667
+ Range.prototype.__iterator = function __iterator (type, reverse) {
4668
+ var size = this.size;
4669
+ var step = this._step;
4670
+ var value = reverse ? this._start + (size - 1) * step : this._start;
4671
+ var i = 0;
4672
+ return new Iterator(function () {
4673
+ if (i === size) {
4674
+ return iteratorDone();
4675
+ }
4676
+ var v = value;
4677
+ value += reverse ? -step : step;
4678
+ return iteratorValue(type, reverse ? size - ++i : i++, v);
4679
+ });
4680
+ };
4681
+
4682
+ Range.prototype.equals = function equals (other) {
4683
+ return other instanceof Range
4684
+ ? this._start === other._start &&
4685
+ this._end === other._end &&
4686
+ this._step === other._step
4687
+ : deepEqual(this, other);
4688
+ };
4689
+
4690
+ return Range;
4691
+ }(IndexedSeq));
4692
+
4693
+ var EMPTY_RANGE;
4694
+
4695
+ var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
4696
+ /**
4697
+ * True if `maybeSet` is a Set.
4698
+ *
4699
+ * Also true for OrderedSets.
4533
4700
  */
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;
4701
+ function isSet(maybeSet) {
4702
+ return Boolean(maybeSet &&
4703
+ // @ts-expect-error: maybeSet is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSet === 'object' && MAYBE_SET_SYMBOL in maybeSet`
4704
+ maybeSet[IS_SET_SYMBOL]);
4570
4705
  }
4571
4706
 
4572
4707
  var Set = /*@__PURE__*/(function (SetCollection) {
@@ -4811,145 +4946,6 @@ function emptySet() {
4811
4946
  return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
4812
4947
  }
4813
4948
 
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
4949
  /**
4954
4950
  * Returns the value at the provided key path starting at the provided
4955
4951
  * collection, or notSetValue if the key path is not defined.
@@ -4992,11 +4988,103 @@ function toObject() {
4992
4988
  assertNotInfinite(this.size);
4993
4989
  var object = {};
4994
4990
  this.__iterate(function (v, k) {
4991
+ if (isProtoKey(k)) {
4992
+ return;
4993
+ }
4994
+
4995
4995
  object[k] = v;
4996
4996
  });
4997
4997
  return object;
4998
4998
  }
4999
4999
 
5000
+ function toJS(value) {
5001
+ if (!value || typeof value !== 'object') {
5002
+ return value;
5003
+ }
5004
+ if (!isCollection(value)) {
5005
+ if (!isDataStructure(value)) {
5006
+ return value;
5007
+ }
5008
+ // @ts-expect-error until Seq has been migrated to TypeScript
5009
+ value = Seq(value);
5010
+ }
5011
+ if (isKeyed(value)) {
5012
+ var result$1 = {};
5013
+ // @ts-expect-error `__iterate` exists on all Keyed collections but method is not defined in the type
5014
+ value.__iterate(function (v, k) {
5015
+ if (isProtoKey(k)) {
5016
+ return;
5017
+ }
5018
+ result$1[k] = toJS(v);
5019
+ });
5020
+ return result$1;
5021
+ }
5022
+ var result = [];
5023
+ // @ts-expect-error value "should" be a non-keyed collection, but we may need to assert for stricter types
5024
+ value.__iterate(function (v) {
5025
+ result.push(toJS(v));
5026
+ });
5027
+ return result;
5028
+ }
5029
+
5030
+ function hashCollection(collection) {
5031
+ // @ts-expect-error Migrate to CollectionImpl in v6
5032
+ if (collection.size === Infinity) {
5033
+ return 0;
5034
+ }
5035
+ var ordered = isOrdered(collection);
5036
+ var keyed = isKeyed(collection);
5037
+ var h = ordered ? 1 : 0;
5038
+ // @ts-expect-error Migrate to CollectionImpl in v6
5039
+ collection.__iterate(keyed
5040
+ ? ordered
5041
+ ? function (v, k) {
5042
+ h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
5043
+ }
5044
+ : function (v, k) {
5045
+ h = (h + hashMerge(hash(v), hash(k))) | 0;
5046
+ }
5047
+ : ordered
5048
+ ? function (v) {
5049
+ h = (31 * h + hash(v)) | 0;
5050
+ }
5051
+ : function (v) {
5052
+ h = (h + hash(v)) | 0;
5053
+ });
5054
+ // @ts-expect-error Migrate to CollectionImpl in v6
5055
+ return murmurHashOfSize(collection.size, h);
5056
+ }
5057
+ function murmurHashOfSize(size, h) {
5058
+ h = imul(h, 0xcc9e2d51);
5059
+ h = imul((h << 15) | (h >>> -15), 0x1b873593);
5060
+ h = imul((h << 13) | (h >>> -13), 5);
5061
+ h = ((h + 0xe6546b64) | 0) ^ size;
5062
+ h = imul(h ^ (h >>> 16), 0x85ebca6b);
5063
+ h = imul(h ^ (h >>> 13), 0xc2b2ae35);
5064
+ h = smi(h ^ (h >>> 16));
5065
+ return h;
5066
+ }
5067
+ function hashMerge(a, b) {
5068
+ return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
5069
+ }
5070
+
5071
+ /**
5072
+ * Contributes additional methods to a constructor
5073
+ */
5074
+ function mixin(ctor,
5075
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
5076
+ methods) {
5077
+ var keyCopier = function (key) {
5078
+ // @ts-expect-error how to handle symbol ?
5079
+ ctor.prototype[key] = methods[key];
5080
+ };
5081
+ Object.keys(methods).forEach(keyCopier);
5082
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
5083
+ Object.getOwnPropertySymbols &&
5084
+ Object.getOwnPropertySymbols(methods).forEach(keyCopier);
5085
+ return ctor;
5086
+ }
5087
+
5000
5088
  Collection.Iterator = Iterator;
5001
5089
 
5002
5090
  mixin(Collection, {
@@ -5635,89 +5723,15 @@ mixin(SetSeq, SetCollectionPrototype);
5635
5723
 
5636
5724
  // #pragma Helper functions
5637
5725
 
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
5726
  function defaultZipper() {
5672
5727
  return arrCopy(arguments);
5673
5728
  }
5674
5729
 
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
5730
+ /**
5731
+ * True if `maybeOrderedSet` is an OrderedSet.
5732
+ */
5733
+ function isOrderedSet(maybeOrderedSet) {
5734
+ return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
5721
5735
  }
5722
5736
 
5723
5737
  var OrderedSet = /*@__PURE__*/(function (Set) {
@@ -5779,9 +5793,12 @@ function emptyOrderedSet() {
5779
5793
  );
5780
5794
  }
5781
5795
 
5796
+ /**
5797
+ * Describes which item in a pair should be placed first when sorting
5798
+ */
5782
5799
  var PairSorting = {
5783
- LeftThenRight: -1,
5784
- RightThenLeft: 1,
5800
+ LeftThenRight: -1,
5801
+ RightThenLeft: 1,
5785
5802
  };
5786
5803
 
5787
5804
  function throwOnInvalidDefaultValues(defaultValues) {
@@ -5986,7 +6003,7 @@ RecordPrototype.mergeDeepWith = mergeDeepWith;
5986
6003
  RecordPrototype.mergeDeepIn = mergeDeepIn;
5987
6004
  RecordPrototype.setIn = setIn;
5988
6005
  RecordPrototype.update = update;
5989
- RecordPrototype.updateIn = updateIn;
6006
+ RecordPrototype.updateIn = updateIn$1;
5990
6007
  RecordPrototype.withMutations = withMutations;
5991
6008
  RecordPrototype.asMutable = asMutable;
5992
6009
  RecordPrototype.asImmutable = asImmutable;
@@ -6174,9 +6191,11 @@ function defaultConverter(k, v) {
6174
6191
  return isIndexed(v) ? v.toList() : isKeyed(v) ? v.toMap() : v.toSet();
6175
6192
  }
6176
6193
 
6177
- var version = "5.1.3";
6194
+ var version = "5.1.5";
6195
+
6196
+ /* eslint-disable import/order */
6178
6197
 
6179
6198
  // Note: Iterable is deprecated
6180
6199
  var Iterable = Collection;
6181
6200
 
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 };
6201
+ 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 };