Skip to content

Commit

Permalink
update .groupBy
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 15, 2021
1 parent cafdde7 commit 9d9833c
Show file tree
Hide file tree
Showing 23 changed files with 100 additions and 81 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -30,12 +30,12 @@ The maintainers of `core-js` and thousands of other packages are working with Ti

---

[*Example of usage*](https://is.gd/FdIG6n):
[*Example of usage*](https://is.gd/XD4mRe):
```js
import 'core-js'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4].findLast(it => it % 2); // => 3
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand All @@ -44,14 +44,14 @@ queueMicrotask(() => console.log('called as microtask'));
*You can load only required features*:
```js
import 'core-js/actual/array/from'; // <- at the top of your entry point
import 'core-js/actual/array/find-last'; // <- at the top of your entry point
import 'core-js/actual/array/group-by'; // <- at the top of your entry point
import 'core-js/actual/set'; // <- at the top of your entry point
import 'core-js/actual/promise'; // <- at the top of your entry point
import 'core-js/actual/structured-clone'; // <- at the top of your entry point
import 'core-js/actual/queue-microtask'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4].findLast(it => it % 2); // => 3
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand All @@ -60,14 +60,14 @@ queueMicrotask(() => console.log('called as microtask'));
*Or use it without global namespace pollution*:
```js
import from from 'core-js-pure/actual/array/from';
import findLast from 'core-js-pure/actual/array/find-last';
import groupBy from 'core-js-pure/actual/array/group-by';
import Set from 'core-js-pure/actual/set';
import Promise from 'core-js-pure/actual/promise';
import structuredClone from 'core-js-pure/actual/structured-clone';
import queueMicrotask from 'core-js-pure/actual/queue-microtask';

from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
findLast([1, 2, 3, 4], it => it % 2); // => 3
groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand Down
10 changes: 6 additions & 4 deletions deno/corejs/README.md
Expand Up @@ -26,22 +26,24 @@
```js
import 'https://deno.land/x/corejs@v3.19.3/index.js'; // <- at the top of your entry point

Object.hasOwn({ foo: 42 }, 'foo'); // => true
Object.hasOwn({ foo: 42 }, 'foo'); // => true

[1, 2, 3, 4, 5, 6, 7].at(-3); // => 5
[1, 2, 3, 4, 5, 6, 7].at(-3); // => 5

[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }

Promise.any([
Promise.resolve(1),
Promise.reject(2),
Promise.resolve(3),
]).then(console.log); // => 1
]).then(console.log); // => 1

[1, 2, 3, 4, 5, 6, 7].values()
.drop(1)
.take(5)
.filter(it => it % 2)
.map(it => it ** 2)
.toArray(); // => [9, 25]
.toArray(); // => [9, 25]
```

**It's a bundled global version for Deno 1.0+, for more info see [`core-js` documentation](https://github.com/zloirock/core-js/blob/master/README.md).**
12 changes: 6 additions & 6 deletions packages/core-js-bundle/README.md
Expand Up @@ -22,12 +22,12 @@

---

[*Example of usage*](https://is.gd/FdIG6n):
[*Example of usage*](https://is.gd/XD4mRe):
```js
import 'core-js'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4].findLast(it => it % 2); // => 3
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand All @@ -36,14 +36,14 @@ queueMicrotask(() => console.log('called as microtask'));
*You can load only required features*:
```js
import 'core-js/actual/array/from'; // <- at the top of your entry point
import 'core-js/actual/array/find-last'; // <- at the top of your entry point
import 'core-js/actual/array/group-by'; // <- at the top of your entry point
import 'core-js/actual/set'; // <- at the top of your entry point
import 'core-js/actual/promise'; // <- at the top of your entry point
import 'core-js/actual/structured-clone'; // <- at the top of your entry point
import 'core-js/actual/queue-microtask'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4].findLast(it => it % 2); // => 3
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand All @@ -52,14 +52,14 @@ queueMicrotask(() => console.log('called as microtask'));
*Or use it without global namespace pollution*:
```js
import from from 'core-js-pure/actual/array/from';
import findLast from 'core-js-pure/actual/array/find-last';
import groupBy from 'core-js-pure/actual/array/group-by';
import Set from 'core-js-pure/actual/set';
import Promise from 'core-js-pure/actual/promise';
import structuredClone from 'core-js-pure/actual/structured-clone';
import queueMicrotask from 'core-js-pure/actual/queue-microtask';

from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
findLast([1, 2, 3, 4], it => it % 2); // => 3
groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand Down
12 changes: 6 additions & 6 deletions packages/core-js-pure/README.md
Expand Up @@ -22,12 +22,12 @@

---

[*Example of usage*](https://is.gd/FdIG6n):
[*Example of usage*](https://is.gd/XD4mRe):
```js
import 'core-js'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4].findLast(it => it % 2); // => 3
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand All @@ -36,14 +36,14 @@ queueMicrotask(() => console.log('called as microtask'));
*You can load only required features*:
```js
import 'core-js/actual/array/from'; // <- at the top of your entry point
import 'core-js/actual/array/find-last'; // <- at the top of your entry point
import 'core-js/actual/array/group-by'; // <- at the top of your entry point
import 'core-js/actual/set'; // <- at the top of your entry point
import 'core-js/actual/promise'; // <- at the top of your entry point
import 'core-js/actual/structured-clone'; // <- at the top of your entry point
import 'core-js/actual/queue-microtask'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4].findLast(it => it % 2); // => 3
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand All @@ -52,14 +52,14 @@ queueMicrotask(() => console.log('called as microtask'));
*Or use it without global namespace pollution*:
```js
import from from 'core-js-pure/actual/array/from';
import findLast from 'core-js-pure/actual/array/find-last';
import groupBy from 'core-js-pure/actual/array/group-by';
import Set from 'core-js-pure/actual/set';
import Promise from 'core-js-pure/actual/promise';
import structuredClone from 'core-js-pure/actual/structured-clone';
import queueMicrotask from 'core-js-pure/actual/queue-microtask';

from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
findLast([1, 2, 3, 4], it => it % 2); // => 3
groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand Down
12 changes: 6 additions & 6 deletions packages/core-js/README.md
Expand Up @@ -22,12 +22,12 @@

---

[*Example of usage*](https://is.gd/FdIG6n):
[*Example of usage*](https://is.gd/XD4mRe):
```js
import 'core-js'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4].findLast(it => it % 2); // => 3
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand All @@ -36,14 +36,14 @@ queueMicrotask(() => console.log('called as microtask'));
*You can load only required features*:
```js
import 'core-js/actual/array/from'; // <- at the top of your entry point
import 'core-js/actual/array/find-last'; // <- at the top of your entry point
import 'core-js/actual/array/group-by'; // <- at the top of your entry point
import 'core-js/actual/set'; // <- at the top of your entry point
import 'core-js/actual/promise'; // <- at the top of your entry point
import 'core-js/actual/structured-clone'; // <- at the top of your entry point
import 'core-js/actual/queue-microtask'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4].findLast(it => it % 2); // => 3
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand All @@ -52,14 +52,14 @@ queueMicrotask(() => console.log('called as microtask'));
*Or use it without global namespace pollution*:
```js
import from from 'core-js-pure/actual/array/from';
import findLast from 'core-js-pure/actual/array/find-last';
import groupBy from 'core-js-pure/actual/array/group-by';
import Set from 'core-js-pure/actual/set';
import Promise from 'core-js-pure/actual/promise';
import structuredClone from 'core-js-pure/actual/structured-clone';
import queueMicrotask from 'core-js-pure/actual/queue-microtask';

from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
findLast([1, 2, 3, 4], it => it % 2); // => 3
groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));
Expand Down
5 changes: 5 additions & 0 deletions packages/core-js/actual/array/group-by-to-map.js
@@ -0,0 +1,5 @@
require('../../modules/es.map');
require('../../modules/esnext.array.group-by-to-map');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Array', 'groupByToMap');
4 changes: 4 additions & 0 deletions packages/core-js/actual/array/group-by.js
@@ -0,0 +1,4 @@
require('../../modules/esnext.array.group-by');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Array', 'groupBy');
3 changes: 3 additions & 0 deletions packages/core-js/actual/array/index.js
@@ -1,5 +1,8 @@
var parent = require('../../stable/array');
require('../../modules/es.map');
require('../../modules/esnext.array.find-last');
require('../../modules/esnext.array.find-last-index');
require('../../modules/esnext.array.group-by');
require('../../modules/esnext.array.group-by-to-map');

module.exports = parent;
5 changes: 5 additions & 0 deletions packages/core-js/actual/array/virtual/group-by-to-map.js
@@ -0,0 +1,5 @@
require('../../../modules/es.map');
require('../../../modules/esnext.array.group-by-to-map');
var entryVirtual = require('../../../internals/entry-virtual');

module.exports = entryVirtual('Array').groupByToMap;
4 changes: 4 additions & 0 deletions packages/core-js/actual/array/virtual/group-by.js
@@ -0,0 +1,4 @@
require('../../../modules/esnext.array.group-by');
var entryVirtual = require('../../../internals/entry-virtual');

module.exports = entryVirtual('Array').groupBy;
3 changes: 3 additions & 0 deletions packages/core-js/actual/array/virtual/index.js
@@ -1,5 +1,8 @@
var parent = require('../../../stable/array/virtual');
require('../../../modules/es.map');
require('../../../modules/esnext.array.find-last');
require('../../../modules/esnext.array.find-last-index');
require('../../../modules/esnext.array.group-by');
require('../../../modules/esnext.array.group-by-to-map');

module.exports = parent;
9 changes: 9 additions & 0 deletions packages/core-js/actual/instance/group-by-to-map.js
@@ -0,0 +1,9 @@
var isPrototypeOf = require('../../internals/object-is-prototype-of');
var method = require('../array/virtual/group-by-to-map');

var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.groupByToMap;
return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.groupByToMap) ? method : own;
};
9 changes: 9 additions & 0 deletions packages/core-js/actual/instance/group-by.js
@@ -0,0 +1,9 @@
var isPrototypeOf = require('../../internals/object-is-prototype-of');
var method = require('../array/virtual/group-by');

var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.groupBy;
return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.groupBy) ? method : own;
};
6 changes: 2 additions & 4 deletions packages/core-js/features/array/group-by-to-map.js
@@ -1,5 +1,3 @@
require('../../modules/es.map');
require('../../modules/esnext.array.group-by-to-map');
var entryUnbind = require('../../internals/entry-unbind');
var parent = require('../../actual/array/group-by-to-map');

module.exports = entryUnbind('Array', 'groupByToMap');
module.exports = parent;
5 changes: 2 additions & 3 deletions packages/core-js/features/array/group-by.js
@@ -1,4 +1,3 @@
require('../../modules/esnext.array.group-by');
var entryUnbind = require('../../internals/entry-unbind');
var parent = require('../../actual/array/group-by');

module.exports = entryUnbind('Array', 'groupBy');
module.exports = parent;
3 changes: 0 additions & 3 deletions packages/core-js/features/array/index.js
@@ -1,14 +1,11 @@
var parent = require('../../actual/array');
require('../../modules/es.map');
require('../../modules/es.promise');
require('../../modules/esnext.array.from-async');
// TODO: Remove from `core-js@4`
require('../../modules/esnext.array.at');
// TODO: Remove from `core-js@4`
require('../../modules/esnext.array.filter-out');
require('../../modules/esnext.array.filter-reject');
require('../../modules/esnext.array.group-by');
require('../../modules/esnext.array.group-by-to-map');
require('../../modules/esnext.array.is-template-object');
require('../../modules/esnext.array.last-item');
require('../../modules/esnext.array.last-index');
Expand Down
6 changes: 2 additions & 4 deletions packages/core-js/features/array/virtual/group-by-to-map.js
@@ -1,5 +1,3 @@
require('../../../modules/es.map');
require('../../../modules/esnext.array.group-by-to-map');
var entryVirtual = require('../../../internals/entry-virtual');
var parent = require('../../../actual/array/virtual/group-by-to-map');

module.exports = entryVirtual('Array').groupByToMap;
module.exports = parent;
5 changes: 2 additions & 3 deletions packages/core-js/features/array/virtual/group-by.js
@@ -1,4 +1,3 @@
require('../../../modules/esnext.array.group-by');
var entryVirtual = require('../../../internals/entry-virtual');
var parent = require('../../../actual/array/virtual/group-by');

module.exports = entryVirtual('Array').groupBy;
module.exports = parent;
3 changes: 0 additions & 3 deletions packages/core-js/features/array/virtual/index.js
@@ -1,12 +1,9 @@
var parent = require('../../../actual/array/virtual');
require('../../../modules/es.map');
// TODO: Remove from `core-js@4`
require('../../../modules/esnext.array.at');
// TODO: Remove from `core-js@4`
require('../../../modules/esnext.array.filter-out');
require('../../../modules/esnext.array.filter-reject');
require('../../../modules/esnext.array.group-by');
require('../../../modules/esnext.array.group-by-to-map');
require('../../../modules/esnext.array.to-reversed');
require('../../../modules/esnext.array.to-sorted');
require('../../../modules/esnext.array.to-spliced');
Expand Down
10 changes: 2 additions & 8 deletions packages/core-js/features/instance/group-by-to-map.js
@@ -1,9 +1,3 @@
var isPrototypeOf = require('../../internals/object-is-prototype-of');
var method = require('../array/virtual/group-by-to-map');
var parent = require('../../actual/instance/group-by-to-map');

var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.groupByToMap;
return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.groupByToMap) ? method : own;
};
module.exports = parent;
10 changes: 2 additions & 8 deletions packages/core-js/features/instance/group-by.js
@@ -1,9 +1,3 @@
var isPrototypeOf = require('../../internals/object-is-prototype-of');
var method = require('../array/virtual/group-by');
var parent = require('../../actual/instance/group-by');

var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.groupBy;
return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.groupBy) ? method : own;
};
module.exports = parent;

0 comments on commit 9d9833c

Please sign in to comment.