Skip to content

Commit 5a1efc1

Browse files
authored
Merge pull request #889 from zloirock/item-method
2 parents 744f617 + 9c07cee commit 5a1efc1

29 files changed

+310
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Changelog
22
##### Unreleased
3+
- Added [relative indexing method stage 3 proposal](https://github.com/tc39/proposal-relative-indexing-method)
4+
- `Array#at`
5+
- `%TypedArray%#at`
36
- Added [`Number.range` stage 1 proposal](https://github.com/tc39/proposal-Number.range)
47
- `Number.range`
58
- `BigInt.range`
@@ -8,6 +11,7 @@
811
- `%TypedArray%#filterOut`
912
- Added [array deduplication stage 1 proposal](https://github.com/tc39/proposal-array-unique)
1013
- `Array#uniqueBy`
14+
- Added code points / code units explicit feature detection in `String#at` for preventing breakage code which use obsolete `String#at` proposal polyfill
1115
- Added the missed `(es|stable)/instance/replace-all` entries
1216
- Updated compat data mapping for Opera - from Opera 69, the difference with Chrome versions increased to 14
1317
- Compat data mapping for modern Android WebView to Chrome moved from targets parser directly to compat data

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,40 @@ Promise.any([
17781778
core-js(-pure)/stage/3
17791779
```
17801780

1781-
None.
1781+
##### [Relative indexing method](https://github.com/tc39/proposal-relative-indexing-method)[⬆](#index)
1782+
Modules [`esnext.array.at`](https://github.com/zloirock/core-js/blob/v3.7.0/packages/core-js/modules/esnext.array.at.js) and [`esnext.typed-array.at`](https://github.com/zloirock/core-js/blob/v3.7.0/packages/core-js/modules/esnext.typed-array.at.js)
1783+
> **Warning! Because of the conflict with [another proposal](#stringat), this method is not available on `String.prototype` in this version.**
1784+
1785+
```js
1786+
class Array {
1787+
at(index: int): any;
1788+
}
1789+
1790+
class [
1791+
Int8Array,
1792+
Uint8Array,
1793+
Uint8ClampedArray,
1794+
Int16Array,
1795+
Uint16Array,
1796+
Int32Array,
1797+
Uint32Array,
1798+
Float32Array,
1799+
Float64Array,
1800+
] {
1801+
at(index: int): any;
1802+
}
1803+
```
1804+
[*CommonJS entry points:*](#commonjs-api)
1805+
```
1806+
core-js/proposals/relative-indexing-method
1807+
core-js(-pure)/features/array/at
1808+
core-js(-pure)/features/typed-array/at
1809+
```
1810+
[*Examples*](http://es6.zloirock.ru/#log(%5B1%2C%202%2C%203%5D.at(1))%3B%20%20%2F%2F%20%3D%3E%202%0Alog(%5B1%2C%202%2C%203%5D.at(-1))%3B%20%2F%2F%20%3D%3E%203):
1811+
```js
1812+
[1, 2, 3].at(1); // => 2
1813+
[1, 2, 3].at(-1); // => 3
1814+
```
17821815

17831816
#### Stage 2 proposals[⬆](#index)
17841817
[*CommonJS entry points:*](#commonjs-api)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,8 @@ const data = {
12581258
},
12591259
'esnext.array.is-template-object': {
12601260
},
1261+
'esnext.array.at': {
1262+
},
12611263
'esnext.array.last-index': {
12621264
},
12631265
'esnext.array.last-item': {
@@ -1492,6 +1494,8 @@ const data = {
14921494
// TODO: Remove from `core-js@4`
14931495
'esnext.symbol.replace-all': {
14941496
},
1497+
'esnext.typed-array.at': {
1498+
},
14951499
'esnext.typed-array.filter-out': {
14961500
},
14971501
'esnext.weak-map.delete-all': {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ module.exports = {
6565
'esnext.weak-map.emplace',
6666
],
6767
3.8: [
68+
'esnext.array.at',
6869
'esnext.array.filter-out',
6970
'esnext.array.unique-by',
7071
'esnext.bigint.range',
7172
'esnext.number.range',
73+
'esnext.typed-array.at',
7274
'esnext.typed-array.filter-out',
7375
],
7476
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// empty

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require('../../modules/esnext.array.at');
2+
var entryUnbind = require('../../internals/entry-unbind');
3+
4+
module.exports = entryUnbind('Array', 'at');

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var parent = require('../../es/array');
22
require('../../modules/es.map');
3+
require('../../modules/esnext.array.at');
34
require('../../modules/esnext.array.filter-out');
45
require('../../modules/esnext.array.is-template-object');
56
require('../../modules/esnext.array.last-item');
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require('../../../modules/esnext.array.at');
2+
var entryVirtual = require('../../../internals/entry-virtual');
3+
4+
module.exports = entryVirtual('Array').at;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var parent = require('../../../es/array/virtual');
2+
require('../../../modules/esnext.array.at');
23
require('../../../modules/esnext.array.filter-out');
4+
require('../../../modules/esnext.array.unique-by');
35

46
module.exports = parent;
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
var at = require('../string/virtual/at');
1+
var arrayAt = require('../array/virtual/at');
2+
var stringAt = require('../string/virtual/at');
23

4+
var ArrayPrototype = Array.prototype;
35
var StringPrototype = String.prototype;
46

57
module.exports = function (it) {
68
var own = it.at;
7-
return typeof it === 'string' || it === StringPrototype
8-
|| (it instanceof String && own === StringPrototype.at) ? at : own;
9+
if (it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.at)) return arrayAt;
10+
if (typeof it === 'string' || it === StringPrototype || (it instanceof String && own === StringPrototype.at)) {
11+
return stringAt;
12+
} return own;
913
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy