immutable 5.0.0-beta.3 → 5.0.0-beta.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.
Files changed (82) hide show
  1. package/README.md +4 -4
  2. package/dist/es/Collection.js +75 -0
  3. package/dist/es/CollectionImpl.js +781 -0
  4. package/dist/es/Hash.js +260 -0
  5. package/dist/es/Immutable.js +73 -0
  6. package/dist/es/Iterator.js +106 -0
  7. package/dist/es/List.js +692 -0
  8. package/dist/es/Map.js +833 -0
  9. package/dist/es/Math.js +45 -0
  10. package/dist/es/Operations.js +953 -0
  11. package/dist/es/OrderedMap.js +195 -0
  12. package/dist/es/OrderedSet.js +91 -0
  13. package/dist/es/PairSorting.js +30 -0
  14. package/dist/es/Range.js +175 -0
  15. package/dist/es/Record.js +291 -0
  16. package/dist/es/Repeat.js +130 -0
  17. package/dist/es/Seq.js +397 -0
  18. package/dist/es/Set.js +278 -0
  19. package/dist/es/Stack.js +260 -0
  20. package/dist/es/TrieUtils.js +117 -0
  21. package/dist/es/fromJS.js +74 -0
  22. package/dist/es/functional/get.js +38 -0
  23. package/dist/es/functional/getIn.js +41 -0
  24. package/dist/es/functional/has.js +35 -0
  25. package/dist/es/functional/hasIn.js +32 -0
  26. package/dist/es/functional/merge.js +137 -0
  27. package/dist/es/functional/remove.js +56 -0
  28. package/dist/es/functional/removeIn.js +32 -0
  29. package/dist/es/functional/set.js +52 -0
  30. package/dist/es/functional/setIn.js +32 -0
  31. package/dist/es/functional/update.js +31 -0
  32. package/dist/es/functional/updateIn.js +94 -0
  33. package/dist/es/is.js +108 -0
  34. package/dist/es/methods/asImmutable.js +29 -0
  35. package/dist/es/methods/asMutable.js +31 -0
  36. package/dist/es/methods/deleteIn.js +31 -0
  37. package/dist/es/methods/getIn.js +31 -0
  38. package/dist/es/methods/hasIn.js +31 -0
  39. package/dist/es/methods/merge.js +79 -0
  40. package/dist/es/methods/mergeDeep.js +41 -0
  41. package/dist/es/methods/mergeDeepIn.js +37 -0
  42. package/dist/es/methods/mergeIn.js +36 -0
  43. package/dist/es/methods/setIn.js +31 -0
  44. package/dist/es/methods/toObject.js +36 -0
  45. package/dist/es/methods/update.js +33 -0
  46. package/dist/es/methods/updateIn.js +31 -0
  47. package/dist/es/methods/wasAltered.js +29 -0
  48. package/dist/es/methods/withMutations.js +31 -0
  49. package/dist/es/package.json.js +27 -0
  50. package/dist/es/predicates/isAssociative.js +32 -0
  51. package/dist/es/predicates/isCollection.js +32 -0
  52. package/dist/es/predicates/isImmutable.js +32 -0
  53. package/dist/es/predicates/isIndexed.js +31 -0
  54. package/dist/es/predicates/isKeyed.js +31 -0
  55. package/dist/es/predicates/isList.js +31 -0
  56. package/dist/es/predicates/isMap.js +31 -0
  57. package/dist/es/predicates/isOrdered.js +31 -0
  58. package/dist/es/predicates/isOrderedMap.js +32 -0
  59. package/dist/es/predicates/isOrderedSet.js +32 -0
  60. package/dist/es/predicates/isRecord.js +31 -0
  61. package/dist/es/predicates/isSeq.js +31 -0
  62. package/dist/es/predicates/isSet.js +31 -0
  63. package/dist/es/predicates/isStack.js +31 -0
  64. package/dist/es/predicates/isValueObject.js +33 -0
  65. package/dist/es/toJS.js +54 -0
  66. package/dist/es/utils/arrCopy.js +36 -0
  67. package/dist/es/utils/assertNotInfinite.js +34 -0
  68. package/dist/es/utils/coerceKeyPath.js +40 -0
  69. package/dist/es/utils/deepEqual.js +99 -0
  70. package/dist/es/utils/hasOwnProperty.js +27 -0
  71. package/dist/es/utils/invariant.js +29 -0
  72. package/dist/es/utils/isArrayLike.js +44 -0
  73. package/dist/es/utils/isDataStructure.js +39 -0
  74. package/dist/es/utils/isPlainObj.js +52 -0
  75. package/dist/es/utils/mixin.js +38 -0
  76. package/dist/es/utils/quoteString.js +36 -0
  77. package/dist/es/utils/shallowCopy.js +41 -0
  78. package/dist/immutable.d.ts +137 -16
  79. package/dist/immutable.js +25 -68
  80. package/dist/immutable.min.js +2 -32
  81. package/package.json +2 -3
  82. package/dist/immutable.es.js +0 -5965
@@ -0,0 +1,260 @@
1
+ /**
2
+ * @license
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2014-present, Lee Byron and other contributors.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ import { smi } from './Math.js';
26
+
27
+ var defaultValueOf = Object.prototype.valueOf;
28
+
29
+ function hash(o) {
30
+ if (o == null) {
31
+ return hashNullish(o);
32
+ }
33
+
34
+ if (typeof o.hashCode === 'function') {
35
+ // Drop any high bits from accidentally long hash codes.
36
+ return smi(o.hashCode(o));
37
+ }
38
+
39
+ var v = valueOf(o);
40
+
41
+ if (v == null) {
42
+ return hashNullish(v);
43
+ }
44
+
45
+ switch (typeof v) {
46
+ case 'boolean':
47
+ // The hash values for built-in constants are a 1 value for each 5-byte
48
+ // shift region expect for the first, which encodes the value. This
49
+ // reduces the odds of a hash collision for these common values.
50
+ return v ? 0x42108421 : 0x42108420;
51
+ case 'number':
52
+ return hashNumber(v);
53
+ case 'string':
54
+ return v.length > STRING_HASH_CACHE_MIN_STRLEN
55
+ ? cachedHashString(v)
56
+ : hashString(v);
57
+ case 'object':
58
+ case 'function':
59
+ return hashJSObj(v);
60
+ case 'symbol':
61
+ return hashSymbol(v);
62
+ default:
63
+ if (typeof v.toString === 'function') {
64
+ return hashString(v.toString());
65
+ }
66
+ throw new Error('Value type ' + typeof v + ' cannot be hashed.');
67
+ }
68
+ }
69
+
70
+ function hashNullish(nullish) {
71
+ return nullish === null ? 0x42108422 : /* undefined */ 0x42108423;
72
+ }
73
+
74
+ // Compress arbitrarily large numbers into smi hashes.
75
+ function hashNumber(n) {
76
+ if (n !== n || n === Infinity) {
77
+ return 0;
78
+ }
79
+ var hash = n | 0;
80
+ if (hash !== n) {
81
+ hash ^= n * 0xffffffff;
82
+ }
83
+ while (n > 0xffffffff) {
84
+ n /= 0xffffffff;
85
+ hash ^= n;
86
+ }
87
+ return smi(hash);
88
+ }
89
+
90
+ function cachedHashString(string) {
91
+ var hashed = stringHashCache[string];
92
+ if (hashed === undefined) {
93
+ hashed = hashString(string);
94
+ if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
95
+ STRING_HASH_CACHE_SIZE = 0;
96
+ stringHashCache = {};
97
+ }
98
+ STRING_HASH_CACHE_SIZE++;
99
+ stringHashCache[string] = hashed;
100
+ }
101
+ return hashed;
102
+ }
103
+
104
+ // http://jsperf.com/hashing-strings
105
+ function hashString(string) {
106
+ // This is the hash from JVM
107
+ // The hash code for a string is computed as
108
+ // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
109
+ // where s[i] is the ith character of the string and n is the length of
110
+ // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
111
+ // (exclusive) by dropping high bits.
112
+ var hashed = 0;
113
+ for (var ii = 0; ii < string.length; ii++) {
114
+ hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
115
+ }
116
+ return smi(hashed);
117
+ }
118
+
119
+ function hashSymbol(sym) {
120
+ var hashed = symbolMap[sym];
121
+ if (hashed !== undefined) {
122
+ return hashed;
123
+ }
124
+
125
+ hashed = nextHash();
126
+
127
+ symbolMap[sym] = hashed;
128
+
129
+ return hashed;
130
+ }
131
+
132
+ function hashJSObj(obj) {
133
+ var hashed;
134
+ if (usingWeakMap) {
135
+ hashed = weakMap.get(obj);
136
+ if (hashed !== undefined) {
137
+ return hashed;
138
+ }
139
+ }
140
+
141
+ hashed = obj[UID_HASH_KEY];
142
+ if (hashed !== undefined) {
143
+ return hashed;
144
+ }
145
+
146
+ if (!canDefineProperty) {
147
+ hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
148
+ if (hashed !== undefined) {
149
+ return hashed;
150
+ }
151
+
152
+ hashed = getIENodeHash(obj);
153
+ if (hashed !== undefined) {
154
+ return hashed;
155
+ }
156
+ }
157
+
158
+ hashed = nextHash();
159
+
160
+ if (usingWeakMap) {
161
+ weakMap.set(obj, hashed);
162
+ } else if (isExtensible !== undefined && isExtensible(obj) === false) {
163
+ throw new Error('Non-extensible objects are not allowed as keys.');
164
+ } else if (canDefineProperty) {
165
+ Object.defineProperty(obj, UID_HASH_KEY, {
166
+ enumerable: false,
167
+ configurable: false,
168
+ writable: false,
169
+ value: hashed,
170
+ });
171
+ } else if (
172
+ obj.propertyIsEnumerable !== undefined &&
173
+ obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable
174
+ ) {
175
+ // Since we can't define a non-enumerable property on the object
176
+ // we'll hijack one of the less-used non-enumerable properties to
177
+ // save our hash on it. Since this is a function it will not show up in
178
+ // `JSON.stringify` which is what we want.
179
+ obj.propertyIsEnumerable = function () {
180
+ return this.constructor.prototype.propertyIsEnumerable.apply(
181
+ this,
182
+ arguments
183
+ );
184
+ };
185
+ obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
186
+ } else if (obj.nodeType !== undefined) {
187
+ // At this point we couldn't get the IE `uniqueID` to use as a hash
188
+ // and we couldn't use a non-enumerable property to exploit the
189
+ // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
190
+ // itself.
191
+ obj[UID_HASH_KEY] = hashed;
192
+ } else {
193
+ throw new Error('Unable to set a non-enumerable property on object.');
194
+ }
195
+
196
+ return hashed;
197
+ }
198
+
199
+ // Get references to ES5 object methods.
200
+ var isExtensible = Object.isExtensible;
201
+
202
+ // True if Object.defineProperty works as expected. IE8 fails this test.
203
+ var canDefineProperty = (function () {
204
+ try {
205
+ Object.defineProperty({}, '@', {});
206
+ return true;
207
+ } catch (e) {
208
+ return false;
209
+ }
210
+ })();
211
+
212
+ // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
213
+ // and avoid memory leaks from the IE cloneNode bug.
214
+ function getIENodeHash(node) {
215
+ if (node && node.nodeType > 0) {
216
+ switch (node.nodeType) {
217
+ case 1: // Element
218
+ return node.uniqueID;
219
+ case 9: // Document
220
+ return node.documentElement && node.documentElement.uniqueID;
221
+ }
222
+ }
223
+ }
224
+
225
+ function valueOf(obj) {
226
+ return obj.valueOf !== defaultValueOf && typeof obj.valueOf === 'function'
227
+ ? obj.valueOf(obj)
228
+ : obj;
229
+ }
230
+
231
+ function nextHash() {
232
+ var nextHash = ++_objHashUID;
233
+ if (_objHashUID & 0x40000000) {
234
+ _objHashUID = 0;
235
+ }
236
+ return nextHash;
237
+ }
238
+
239
+ // If possible, use a WeakMap.
240
+ var usingWeakMap = typeof WeakMap === 'function';
241
+ var weakMap;
242
+ if (usingWeakMap) {
243
+ weakMap = new WeakMap();
244
+ }
245
+
246
+ var symbolMap = Object.create(null);
247
+
248
+ var _objHashUID = 0;
249
+
250
+ var UID_HASH_KEY = '__immutablehash__';
251
+ if (typeof Symbol === 'function') {
252
+ UID_HASH_KEY = Symbol(UID_HASH_KEY);
253
+ }
254
+
255
+ var STRING_HASH_CACHE_MIN_STRLEN = 16;
256
+ var STRING_HASH_CACHE_MAX_SIZE = 255;
257
+ var STRING_HASH_CACHE_SIZE = 0;
258
+ var stringHashCache = {};
259
+
260
+ export { hash };
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @license
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2014-present, Lee Byron and other contributors.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ export { Seq } from './Seq.js';
26
+ export { OrderedMap } from './OrderedMap.js';
27
+ export { List } from './List.js';
28
+ export { Map } from './Map.js';
29
+ export { Stack } from './Stack.js';
30
+ export { OrderedSet } from './OrderedSet.js';
31
+ export { PairSorting } from './PairSorting.js';
32
+ export { Set } from './Set.js';
33
+ export { Record } from './Record.js';
34
+ export { Range } from './Range.js';
35
+ export { Repeat } from './Repeat.js';
36
+ export { is } from './is.js';
37
+ export { fromJS } from './fromJS.js';
38
+ export { default as isPlainObject } from './utils/isPlainObj.js';
39
+ export { isImmutable } from './predicates/isImmutable.js';
40
+ export { isCollection } from './predicates/isCollection.js';
41
+ export { isKeyed } from './predicates/isKeyed.js';
42
+ export { isIndexed } from './predicates/isIndexed.js';
43
+ export { isAssociative } from './predicates/isAssociative.js';
44
+ export { isOrdered } from './predicates/isOrdered.js';
45
+ export { isValueObject } from './predicates/isValueObject.js';
46
+ export { isSeq } from './predicates/isSeq.js';
47
+ export { isList } from './predicates/isList.js';
48
+ export { isMap } from './predicates/isMap.js';
49
+ export { isOrderedMap } from './predicates/isOrderedMap.js';
50
+ export { isStack } from './predicates/isStack.js';
51
+ export { isSet } from './predicates/isSet.js';
52
+ export { isOrderedSet } from './predicates/isOrderedSet.js';
53
+ export { isRecord } from './predicates/isRecord.js';
54
+ import './CollectionImpl.js';
55
+ export { hash } from './Hash.js';
56
+ export { get } from './functional/get.js';
57
+ export { getIn } from './functional/getIn.js';
58
+ export { has } from './functional/has.js';
59
+ export { hasIn } from './functional/hasIn.js';
60
+ export { merge, mergeDeep, mergeDeepWith, mergeWith } from './functional/merge.js';
61
+ export { remove } from './functional/remove.js';
62
+ export { removeIn } from './functional/removeIn.js';
63
+ export { set } from './functional/set.js';
64
+ export { setIn } from './functional/setIn.js';
65
+ export { update } from './functional/update.js';
66
+ export { updateIn } from './functional/updateIn.js';
67
+ export { version } from './package.json.js';
68
+ import { Collection } from './Collection.js';
69
+
70
+ // Note: Iterable is deprecated
71
+ var Iterable = Collection;
72
+
73
+ export { Collection, Iterable };
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @license
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2014-present, Lee Byron and other contributors.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ var ITERATE_KEYS = 0;
26
+ var ITERATE_VALUES = 1;
27
+ var ITERATE_ENTRIES = 2;
28
+
29
+ var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
30
+ var FAUX_ITERATOR_SYMBOL = '@@iterator';
31
+
32
+ var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
33
+
34
+ var Iterator = function Iterator(next) {
35
+ this.next = next;
36
+ };
37
+
38
+ Iterator.prototype.toString = function toString () {
39
+ return '[Iterator]';
40
+ };
41
+
42
+ Iterator.KEYS = ITERATE_KEYS;
43
+ Iterator.VALUES = ITERATE_VALUES;
44
+ Iterator.ENTRIES = ITERATE_ENTRIES;
45
+
46
+ Iterator.prototype.inspect = Iterator.prototype.toSource = function () {
47
+ return this.toString();
48
+ };
49
+ Iterator.prototype[ITERATOR_SYMBOL] = function () {
50
+ return this;
51
+ };
52
+
53
+ function iteratorValue(type, k, v, iteratorResult) {
54
+ var value = type === 0 ? k : type === 1 ? v : [k, v];
55
+ iteratorResult
56
+ ? (iteratorResult.value = value)
57
+ : (iteratorResult = {
58
+ value: value,
59
+ done: false,
60
+ });
61
+ return iteratorResult;
62
+ }
63
+
64
+ function iteratorDone() {
65
+ return { value: undefined, done: true };
66
+ }
67
+
68
+ function hasIterator(maybeIterable) {
69
+ if (Array.isArray(maybeIterable)) {
70
+ // IE11 trick as it does not support `Symbol.iterator`
71
+ return true;
72
+ }
73
+
74
+ return !!getIteratorFn(maybeIterable);
75
+ }
76
+
77
+ function isIterator(maybeIterator) {
78
+ return maybeIterator && typeof maybeIterator.next === 'function';
79
+ }
80
+
81
+ function getIterator(iterable) {
82
+ var iteratorFn = getIteratorFn(iterable);
83
+ return iteratorFn && iteratorFn.call(iterable);
84
+ }
85
+
86
+ function getIteratorFn(iterable) {
87
+ var iteratorFn =
88
+ iterable &&
89
+ ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
90
+ iterable[FAUX_ITERATOR_SYMBOL]);
91
+ if (typeof iteratorFn === 'function') {
92
+ return iteratorFn;
93
+ }
94
+ }
95
+
96
+ function isEntriesIterable(maybeIterable) {
97
+ var iteratorFn = getIteratorFn(maybeIterable);
98
+ return iteratorFn && iteratorFn === maybeIterable.entries;
99
+ }
100
+
101
+ function isKeysIterable(maybeIterable) {
102
+ var iteratorFn = getIteratorFn(maybeIterable);
103
+ return iteratorFn && iteratorFn === maybeIterable.keys;
104
+ }
105
+
106
+ export { ITERATE_ENTRIES, ITERATE_KEYS, ITERATE_VALUES, ITERATOR_SYMBOL, Iterator, getIterator, hasIterator, isEntriesIterable, isIterator, isKeysIterable, iteratorDone, iteratorValue };