@shgysk8zer0/polyfills 0.2.4 → 0.2.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.
- package/CHANGELOG.md +11 -1
- package/all.js +1 -0
- package/all.min.js +11 -11
- package/all.min.js.map +1 -1
- package/array.js +22 -36
- package/map.js +16 -0
- package/object.js +15 -0
- package/package.json +1 -1
package/array.js
CHANGED
|
@@ -85,59 +85,45 @@
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
+
* @deprecated [moved to `Object.groupBy()`]
|
|
88
89
|
* @see https://github.com/tc39/proposal-array-grouping
|
|
89
90
|
*/
|
|
90
|
-
if (! (Array.prototype.group instanceof Function)) {
|
|
91
|
-
Array.prototype.group = function group(callback
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (! groups.hasOwnProperty(key)) {
|
|
96
|
-
groups[key] = [item];
|
|
97
|
-
} else {
|
|
98
|
-
groups[key].push(item);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return groups;
|
|
102
|
-
}, {});
|
|
91
|
+
if (! (Array.prototype.group instanceof Function) && Object.groupBy instanceof Function) {
|
|
92
|
+
Array.prototype.group = function group(callback) {
|
|
93
|
+
console.warn('`Array.group()` is deprecated. Please use `Object.groupBy()` instead.');
|
|
94
|
+
return Object.groupBy(this, callback);
|
|
103
95
|
};
|
|
104
96
|
}
|
|
105
97
|
|
|
106
98
|
/**
|
|
107
|
-
* @deprecated [
|
|
99
|
+
* @deprecated [moved to `Object.groupBy()`]
|
|
108
100
|
*/
|
|
109
|
-
Array.prototype.groupBy
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
101
|
+
if (! (Array.prototype.groupBy instanceof Function) && Object.groupBy instanceof Function) {
|
|
102
|
+
Array.prototype.groupBy = function groupBy(callback) {
|
|
103
|
+
console.warn('`Array.goupBy()` is deprecated. Please use `Object.groupBy()` instead.');
|
|
104
|
+
return Object.groupBy(this, callback);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
113
107
|
|
|
114
108
|
/**
|
|
115
109
|
* @see https://github.com/tc39/proposal-array-grouping
|
|
110
|
+
* @deprecated [moved to `Map.groupBy()`]
|
|
116
111
|
* @requires `Map.prototype.emplace`
|
|
117
112
|
*/
|
|
118
|
-
if (! (Array.prototype.groupToMap instanceof Function) && (Map.
|
|
119
|
-
Array.prototype.groupToMap = function groupToMap(callback
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
insert: () => [item],
|
|
123
|
-
update: existing => {
|
|
124
|
-
existing.push(item);
|
|
125
|
-
return existing;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
return map;
|
|
130
|
-
}, new Map());
|
|
113
|
+
if (! (Array.prototype.groupToMap instanceof Function) && (Map.groupBy instanceof Function)) {
|
|
114
|
+
Array.prototype.groupToMap = function groupToMap(callback) {
|
|
115
|
+
console.warn('`Array.groupToMap()` is deprecated. Please use `Map.groupBy()` instead.');
|
|
116
|
+
return Map.groupBy(this, callback);
|
|
131
117
|
};
|
|
132
118
|
}
|
|
133
119
|
|
|
134
120
|
/**
|
|
135
|
-
* @deprecated [
|
|
121
|
+
* @deprecated [moved to `Map.groupBy()`]
|
|
136
122
|
*/
|
|
137
|
-
if (Map.
|
|
138
|
-
Array.prototype.groupByToMap = function groupByToMap(
|
|
139
|
-
console.warn('`
|
|
140
|
-
return
|
|
123
|
+
if (Map.groupBy instanceof Function) {
|
|
124
|
+
Array.prototype.groupByToMap = function groupByToMap(callback) {
|
|
125
|
+
console.warn('`Array.groupByToMap()` is deprecated. Please use `Map.groupBy()` instead.');
|
|
126
|
+
return Map.groupBy(this, callback);
|
|
141
127
|
};
|
|
142
128
|
}
|
|
143
129
|
|
package/map.js
CHANGED
|
@@ -29,4 +29,20 @@
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
if (! (Map.groupBy instanceof Function)) {
|
|
34
|
+
Map.groupBy = function groupTo(items, callbackFn) {
|
|
35
|
+
return Array.from(items).reduce((map, element, index) => {
|
|
36
|
+
map.emplace(callbackFn.call(map, element, index), {
|
|
37
|
+
insert: () => [element],
|
|
38
|
+
update: existing => {
|
|
39
|
+
existing.push(element);
|
|
40
|
+
return existing;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return map;
|
|
45
|
+
}, new Map());
|
|
46
|
+
};
|
|
47
|
+
}
|
|
32
48
|
})();
|
package/object.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
if (! (Object.groupBy instanceof Function)) {
|
|
2
|
+
Object.groupBy = function(items, callbackFn) {
|
|
3
|
+
return Array.from(items).reduce((groups, element, index) => {
|
|
4
|
+
const key = callbackFn.call(groups, element, index);
|
|
5
|
+
|
|
6
|
+
if (! groups.hasOwnProperty(key)) {
|
|
7
|
+
groups[key] = [element];
|
|
8
|
+
} else {
|
|
9
|
+
groups[key].push(element);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return groups;
|
|
13
|
+
}, {});
|
|
14
|
+
};
|
|
15
|
+
}
|