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