Skip to content

Commit ac93365

Browse files
authored
Merge pull request #959 from zloirock/array-grouping
2 parents 8b64ba5 + 0784656 commit ac93365

File tree

21 files changed

+246
-0
lines changed

21 files changed

+246
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
- [`Array` filtering stage 1 proposal](https://github.com/tc39/proposal-array-filtering):
55
- `Array.prototype.filterReject` replaces `Array.prototype.filterOut`
66
- `%TypedArray%.prototype.filterReject` replaces `%TypedArray%.prototype.filterOut`
7+
- Added [`Array` grouping stage 1 proposal](https://github.com/tc39/proposal-array-grouping):
8+
- `Array.prototype.groupBy`
9+
- `%TypedArray%.prototype.groupBy`
710
- Work with symbols made stricter: some missed before cases of methods that should throw an error on symbols now works as they should
811
- Handling `@@toPrimitive` in some cases of `ToPrimitive` internal logic made stricter
912
- Fixed work of `Request` with polyfilled `URLSearchParams`, [#965](https://github.com/zloirock/core-js/issues/965)

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Promise.resolve(32).then(x => console.log(x)); // => 32
112112
- [`.of` and `.from` methods on collection constructors](#of-and-from-methods-on-collection-constructors)
113113
- [`compositeKey` and `compositeSymbol`](#compositekey-and-compositesymbol)
114114
- [`Array` filtering](#array-filtering)
115+
- [`Array` grouping](#array-grouping)
115116
- [`Array` deduplication](#array-deduplication)
116117
- [Getting last item from `Array`](#getting-last-item-from-array)
117118
- [`Number.range`](#numberrange)
@@ -2292,6 +2293,27 @@ core-js/features/typed-array/filter-reject
22922293
```js
22932294
[1, 2, 3, 4, 5].filterReject(it => it % 2); // => [2, 4]
22942295
````
2296+
##### [`Array` grouping](#https://github.com/tc39/proposal-array-grouping)[⬆](#index)
2297+
Modules [`esnext.array.group-by`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.group-by.js) and [`esnext.typed-array.group-by`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.group-by.js).
2298+
```js
2299+
class Array {
2300+
groupBy(callbackfn: (value: any, index: number, target: any) => key, thisArg?: any): { [key]: Array<mixed> };
2301+
}
2302+
2303+
class %TypedArray% {
2304+
groupBy(callbackfn: (value: number, index: number, target: %TypedArray%) => key, thisArg?: any): { [key]: %TypedArray% };
2305+
}
2306+
```
2307+
[*CommonJS entry points:*](#commonjs-api)
2308+
```
2309+
core-js/proposals/array-grouping
2310+
core-js(-pure)/features/array(/virtual)/group-by
2311+
core-js/features/typed-array/group-by
2312+
```
2313+
[*Examples*](http://es6.zloirock.ru/#log(%5B1%2C%202%2C%203%2C%204%2C%205%5D.groupBy(it%20%3D%3E%20it%20%25%202))%3B%20%2F%2F%20%3D%3E%20%7B%201%3A%20%5B1%2C%203%2C%205%5D%2C%200%3A%20%5B2%2C%204%5D%20%7D):
2314+
```js
2315+
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
2316+
````
22952317
##### [Array deduplication](https://github.com/tc39/proposal-array-unique)[⬆](#index)
22962318
Modules [`esnext.array.unique-by`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.unique-by.js) and [`esnext.typed-array.unique-by`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.unique-by.js)
22972319
```js

packages/core-js-compat/src/data.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,8 @@ export const data = {
14251425
},
14261426
'esnext.array.find-last-index': {
14271427
},
1428+
'esnext.array.group-by': {
1429+
},
14281430
'esnext.array.is-template-object': {
14291431
},
14301432
'esnext.array.last-index': {
@@ -1683,6 +1685,8 @@ export const data = {
16831685
},
16841686
'esnext.typed-array.find-last-index': {
16851687
},
1688+
'esnext.typed-array.group-by': {
1689+
},
16861690
'esnext.typed-array.unique-by': {
16871691
},
16881692
'esnext.weak-map.delete-all': {

packages/core-js-compat/src/modules-by-versions.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export default {
9797
],
9898
3.16: [
9999
'esnext.array.filter-reject',
100+
'esnext.array.group-by',
100101
'esnext.typed-array.filter-reject',
102+
'esnext.typed-array.group-by',
101103
],
102104
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// empty
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require('../../modules/esnext.array.group-by');
2+
var entryUnbind = require('../../internals/entry-unbind');
3+
4+
module.exports = entryUnbind('Array', 'groupBy');

packages/core-js/features/array/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require('../../modules/esnext.array.filter-out');
66
require('../../modules/esnext.array.filter-reject');
77
require('../../modules/esnext.array.find-last');
88
require('../../modules/esnext.array.find-last-index');
9+
require('../../modules/esnext.array.group-by');
910
require('../../modules/esnext.array.is-template-object');
1011
require('../../modules/esnext.array.last-item');
1112
require('../../modules/esnext.array.last-index');
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require('../../../modules/esnext.array.group-by');
2+
var entryVirtual = require('../../../internals/entry-virtual');
3+
4+
module.exports = entryVirtual('Array').groupBy;

packages/core-js/features/array/virtual/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require('../../../modules/esnext.array.filter-out');
66
require('../../../modules/esnext.array.filter-reject');
77
require('../../../modules/esnext.array.find-last');
88
require('../../../modules/esnext.array.find-last-index');
9+
require('../../../modules/esnext.array.group-by');
910
require('../../../modules/esnext.array.unique-by');
1011

1112
module.exports = parent;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var groupBy = require('../array/virtual/group-by');
2+
3+
var ArrayPrototype = Array.prototype;
4+
5+
module.exports = function (it) {
6+
var own = it.groupBy;
7+
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.groupBy) ? groupBy : own;
8+
};

0 commit comments

Comments
 (0)