Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename methods from the Array grouping proposal #1082

Merged
merged 4 commits into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions CHANGELOG.md
@@ -1,12 +1,15 @@
## Changelog
##### Unreleased
- [`Array` find from last](https://github.com/tc39/proposal-array-find-from-last) moved to the stable ES, per June 2022 TC39 meeting
- [`Array` find from last](https://github.com/tc39/proposal-array-find-from-last) moved to the stable ES, according to June 2022 TC39 meeting:
- `Array.prototype.findLast`
- `Array.prototype.findLastIndex`
- `%TypedArray%.prototype.findLast`
- `%TypedArray%.prototype.findLastIndex`
- Changed the order of operations in `%TypedArray%.prototype.with` following [proposal-change-array-by-copy/86](https://github.com/tc39/proposal-change-array-by-copy/issues/86), per June 2022 TC39 meeting
- [Decorator Metadata proposal](https://github.com/tc39/proposal-decorator-metadata) extracted from [Decorators proposal](https://github.com/tc39/proposal-decorators) as a separate stage 2 proposal, `Symbol.metadataKey` replaces `Symbol.metadata`
- Methods from [the `Array` grouping proposal](https://github.com/tc39/proposal-array-grouping) [renamed](https://github.com/tc39/proposal-array-grouping/pull/39), according to June 2022 TC39 meeting:
- `Array.prototype.groupBy` -> `Array.prototype.group`
- `Array.prototype.groupByToMap` -> `Array.prototype.groupToMap`
- Changed the order of operations in `%TypedArray%.prototype.with` following [proposal-change-array-by-copy/86](https://github.com/tc39/proposal-change-array-by-copy/issues/86), according to June 2022 TC39 meeting
- [Decorator Metadata proposal](https://github.com/tc39/proposal-decorator-metadata) extracted from [Decorators proposal](https://github.com/tc39/proposal-decorators) as a separate stage 2 proposal, according to March 2022 TC39 meeting, `Symbol.metadataKey` replaces `Symbol.metadata`
- Added `Array.prototype.push` polyfill with some fixes for modern engines
- Added `Array.prototype.unshift` polyfill with some fixes for modern engines
- Fixed a bug in the order of getting flags in `RegExp.prototype.flags` in the actual version of V8
Expand Down
30 changes: 15 additions & 15 deletions README.md
Expand Up @@ -28,12 +28,12 @@

---

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

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
[1, 2, 3, 4, 5].group(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 @@ -42,14 +42,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/group-by'; // <- at the top of your entry point
import 'core-js/actual/array/group'; // <- 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, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
[1, 2, 3, 4, 5].group(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 @@ -58,14 +58,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 groupBy from 'core-js-pure/actual/array/group-by';
import group from 'core-js-pure/actual/array/group';
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]
groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
group([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 Expand Up @@ -2105,24 +2105,24 @@ core-js/proposals/well-formed-stringify
core-js(-pure)/stage/3
```
##### [`Array` grouping](https://github.com/tc39/proposal-array-grouping)[⬆](#index)
Modules [`esnext.array.group-by`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.group-by.js), [`esnext.array.group-by-to-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.group-by-to-map.js).
Modules [`esnext.array.group`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.group.js), [`esnext.array.group-to-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.group-to-map.js).
```js
class Array {
groupBy(callbackfn: (value: any, index: number, target: any) => key, thisArg?: any): { [key]: Array<mixed> };
groupByToMap(callbackfn: (value: any, index: number, target: any) => key, thisArg?: any): Map<key, Array<mixed>>;
group(callbackfn: (value: any, index: number, target: any) => key, thisArg?: any): { [key]: Array<mixed> };
groupToMap(callbackfn: (value: any, index: number, target: any) => key, thisArg?: any): Map<key, Array<mixed>>;
}
```
[*CommonJS entry points:*](#commonjs-api)
```
core-js/proposals/array-grouping-stage-3
core-js(-pure)/actual|full/array(/virtual)/group-by
core-js(-pure)/actual|full/array(/virtual)/group-by-to-map
core-js/proposals/array-grouping-stage-3-2
core-js(-pure)/actual|full/array(/virtual)/group
core-js(-pure)/actual|full/array(/virtual)/group-to-map
```
[*Examples*](https://t.ly/xEqc):
[*Examples*](https://is.gd/3a0PbH):
```js
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
[1, 2, 3, 4, 5].group(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }

const map = [1, 2, 3, 4, 5].groupByToMap(it => it % 2);
const map = [1, 2, 3, 4, 5].groupToMap(it => it % 2);
map.get(1); // => [1, 3, 5]
map.get(0); // => [2, 4]
````
Expand Down
12 changes: 6 additions & 6 deletions packages/core-js-bundle/README.md
Expand Up @@ -22,12 +22,12 @@

---

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

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
[1, 2, 3, 4, 5].group(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/group-by'; // <- at the top of your entry point
import 'core-js/actual/array/group'; // <- 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, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
[1, 2, 3, 4, 5].group(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 groupBy from 'core-js-pure/actual/array/group-by';
import group from 'core-js-pure/actual/array/group';
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]
groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
group([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
49 changes: 27 additions & 22 deletions packages/core-js-compat/README.md
Expand Up @@ -24,31 +24,36 @@ const {
console.log(targets);
/* =>
{
'es.error.cause': { ios: '14.5-14.8', samsung: '16.0' },
'es.aggregate-error.cause': { ios: '14.5-14.8', samsung: '16.0' },
'es.error.cause': { ios: '14.5-14.8' },
'es.aggregate-error.cause': { ios: '14.5-14.8' },
'es.array.at': { ios: '14.5-14.8' },
'es.array.find-last': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'es.array.find-last-index': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'es.object.has-own': { ios: '14.5-14.8', samsung: '16.0' },
'es.array.find-last': { firefox: '100', ios: '14.5-14.8' },
'es.array.find-last-index': { firefox: '100', ios: '14.5-14.8' },
'es.array.includes': { firefox: '100' },
'es.array.push': { chrome: '100', edge: '101', ios: '14.5-14.8', safari: '15.4' },
'es.array.unshift': { ios: '14.5-14.8', safari: '15.4' },
'es.object.has-own': { ios: '14.5-14.8' },
'es.regexp.flags': { chrome: '100', edge: '101' },
'es.string.at-alternative': { ios: '14.5-14.8' },
'es.typed-array.at': { ios: '14.5-14.8' },
'es.typed-array.find-last': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'es.typed-array.find-last-index': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'es.typed-array.set': { samsung: '16.0' },
'esnext.array.group-by': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.array.group-by-to-map': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.array.to-reversed': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.array.to-sorted': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.array.to-spliced': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.array.unique-by': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.array.with': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.typed-array.to-reversed': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.typed-array.to-sorted': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.typed-array.to-spliced': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'esnext.typed-array.with': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'web.dom-exception.stack': { chrome: '98', edge: '99', ios: '14.5-14.8', samsung: '16.0' },
'web.immediate': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' },
'web.structured-clone': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }
'es.typed-array.find-last': { firefox: '100', ios: '14.5-14.8' },
'es.typed-array.find-last-index': { firefox: '100', ios: '14.5-14.8' },
'esnext.array.group': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.array.group-by': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.array.group-by-to-map': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.array.group-to-map': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.array.to-reversed': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.array.to-sorted': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.array.to-spliced': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.array.unique-by': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.array.with': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.typed-array.to-reversed': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.typed-array.to-sorted': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.typed-array.to-spliced': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'esnext.typed-array.with': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'web.dom-exception.stack': { chrome: '100', edge: '101', ios: '14.5-14.8', safari: '15.4' },
'web.immediate': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
'web.structured-clone': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' }
}
*/
```
Expand Down
6 changes: 6 additions & 0 deletions packages/core-js-compat/src/data.mjs
Expand Up @@ -1606,10 +1606,16 @@ export const data = {
'esnext.array.find-last': null,
// TODO: Remove from `core-js@4`
'esnext.array.find-last-index': null,
'esnext.array.group': {
},
// TODO: Remove from `core-js@4`
'esnext.array.group-by': {
},
// TODO: Remove from `core-js@4`
'esnext.array.group-by-to-map': {
},
'esnext.array.group-to-map': {
},
'esnext.array.is-template-object': {
},
// TODO: Remove from `core-js@4`
Expand Down
2 changes: 2 additions & 0 deletions packages/core-js-compat/src/modules-by-versions.mjs
Expand Up @@ -146,6 +146,8 @@ export default {
'es.array.unshift',
'es.typed-array.find-last',
'es.typed-array.find-last-index',
'esnext.array.group',
'esnext.array.group-to-map',
'esnext.symbol.metadata-key',
],
};
12 changes: 6 additions & 6 deletions packages/core-js-pure/README.md
Expand Up @@ -22,12 +22,12 @@

---

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

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
[1, 2, 3, 4, 5].group(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/group-by'; // <- at the top of your entry point
import 'core-js/actual/array/group'; // <- 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, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
[1, 2, 3, 4, 5].group(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 groupBy from 'core-js-pure/actual/array/group-by';
import group from 'core-js-pure/actual/array/group';
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]
groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
group([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/XD4mRe):
[*Example of usage*](https://tinyurl.com/2aj9lkwf):
```js
import 'core-js/actual'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, 2, 3, 4, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
[1, 2, 3, 4, 5].group(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/group-by'; // <- at the top of your entry point
import 'core-js/actual/array/group'; // <- 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, 5].groupBy(it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
[1, 2, 3, 4, 5].group(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 groupBy from 'core-js-pure/actual/array/group-by';
import group from 'core-js-pure/actual/array/group';
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]
groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
group([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
6 changes: 6 additions & 0 deletions packages/core-js/actual/array/group-to-map.js
@@ -0,0 +1,6 @@
require('../../modules/es.map');
require('../../modules/es.object.to-string');
require('../../modules/esnext.array.group-to-map');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Array', 'groupToMap');