@shgysk8zer0/polyfills 0.2.8 → 0.3.0
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/CHANGELOG.md +14 -0
- package/Record.js +12 -2
- package/Tuple.js +90 -51
- package/all.min.js +13 -13
- package/all.min.js.map +1 -1
- package/iterator.js +276 -160
- package/legacy/set.js +72 -0
- package/package.json +1 -1
- package/set.js +73 -59
package/set.js
CHANGED
|
@@ -1,73 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @see https://github.com/tc39/proposal-set-methods
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
const TYPE_ERR_MSG = 'Expected a set-like object.';
|
|
7
|
+
const SET_METHODS = ['has', 'keys'];
|
|
8
|
+
const SET_PROPS = ['size'];
|
|
9
|
+
const isSet = thing => thing instanceof Set;
|
|
10
|
+
const isSetLike = thing => isSet(thing) || (
|
|
11
|
+
typeof thing === 'object'
|
|
12
|
+
&& thing !== null
|
|
13
|
+
&& SET_METHODS.every(method => thing[method] instanceof Function)
|
|
14
|
+
&& SET_PROPS.every(prop => prop in thing)
|
|
15
|
+
);
|
|
7
16
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
if (! (Set.prototype.intersection instanceof Function)) {
|
|
18
|
+
Set.prototype.intersection = function intersection(set) {
|
|
19
|
+
if (! isSetLike(set)) {
|
|
20
|
+
throw new TypeError(TYPE_ERR_MSG);
|
|
21
|
+
}
|
|
13
22
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
return new Set([...this].filter(item => set.has(item)));
|
|
24
|
+
};
|
|
25
|
+
}
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
if (! (Set.prototype.difference instanceof Function)) {
|
|
28
|
+
Set.prototype.difference = function difference(set) {
|
|
29
|
+
if (! isSetLike(set)) {
|
|
30
|
+
throw new TypeError(TYPE_ERR_MSG);
|
|
31
|
+
}
|
|
23
32
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
return new Set([...this].filter(item => ! set.has(item)));
|
|
34
|
+
};
|
|
35
|
+
}
|
|
27
36
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
if (! (Set.prototype.union instanceof Function)) {
|
|
38
|
+
Set.prototype.union = function union(set) {
|
|
39
|
+
return new Set([...this, ...set]);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
if (! (Set.prototype.isSubsetOf instanceof Function)) {
|
|
44
|
+
Set.prototype.isSubsetOf = function isSubsetOf(set) {
|
|
45
|
+
if (! isSetLike(set)) {
|
|
46
|
+
throw new TypeError(TYPE_ERR_MSG);
|
|
47
|
+
}
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
return [...this].every(item => set.has(item));
|
|
50
|
+
};
|
|
51
|
+
}
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
if (! (Set.prototype.isSupersetOf instanceof Function)) {
|
|
54
|
+
Set.prototype.isSupersetOf = function isSupersetOf(set) {
|
|
55
|
+
if (! isSetLike(set)) {
|
|
56
|
+
throw new TypeError(TYPE_ERR_MSG);
|
|
57
|
+
}
|
|
49
58
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
// @TODO Handle when `set` is set-like
|
|
60
|
+
return isSet(set)
|
|
61
|
+
? set.isSubsetOf(this)
|
|
62
|
+
: new Set(set.keys()).isSubsetOf(this);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
53
65
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
if (! (Set.prototype.symmetricDifference instanceof Function)) {
|
|
67
|
+
Set.prototype.symmetricDifference = function symmetricDifference(set) {
|
|
68
|
+
if (! isSetLike(set)) {
|
|
69
|
+
throw new TypeError(TYPE_ERR_MSG);
|
|
70
|
+
}
|
|
59
71
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
// @TODO Handle when `set` is set-like
|
|
73
|
+
return isSet(set)
|
|
74
|
+
? new Set([...this.difference(set), ...set.difference(this)])
|
|
75
|
+
: new Set([...this.difference(set), ...new Set(set.keys()).difference(this)]);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
63
78
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
if (! (Set.prototype.isDisjointFrom instanceof Function)) {
|
|
80
|
+
Set.prototype.isDisjointFrom = function isDisjointFrom(set) {
|
|
81
|
+
if (! isSetLike(set)) {
|
|
82
|
+
throw new TypeError(TYPE_ERR_MSG);
|
|
83
|
+
}
|
|
69
84
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})();
|
|
85
|
+
return new Set([...this, ...set]).size === this.size + set.size;
|
|
86
|
+
};
|
|
87
|
+
}
|