-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #889 from zloirock/item-method
- Loading branch information
Showing
29 changed files
with
310 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/modules/esnext.typed-array.at.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require('../../modules/esnext.array.at'); | ||
var entryUnbind = require('../../internals/entry-unbind'); | ||
|
||
module.exports = entryUnbind('Array', 'at'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require('../../../modules/esnext.array.at'); | ||
var entryVirtual = require('../../../internals/entry-virtual'); | ||
|
||
module.exports = entryVirtual('Array').at; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
var parent = require('../../../es/array/virtual'); | ||
require('../../../modules/esnext.array.at'); | ||
require('../../../modules/esnext.array.filter-out'); | ||
require('../../../modules/esnext.array.unique-by'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
var at = require('../string/virtual/at'); | ||
var arrayAt = require('../array/virtual/at'); | ||
var stringAt = require('../string/virtual/at'); | ||
|
||
var ArrayPrototype = Array.prototype; | ||
var StringPrototype = String.prototype; | ||
|
||
module.exports = function (it) { | ||
var own = it.at; | ||
return typeof it === 'string' || it === StringPrototype | ||
|| (it instanceof String && own === StringPrototype.at) ? at : own; | ||
if (it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.at)) return arrayAt; | ||
if (typeof it === 'string' || it === StringPrototype || (it instanceof String && own === StringPrototype.at)) { | ||
return stringAt; | ||
} return own; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('../../modules/esnext.typed-array.at'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
var parent = require('../../es/typed-array'); | ||
require('../../modules/esnext.typed-array.at'); | ||
require('../../modules/esnext.typed-array.filter-out'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var toObject = require('../internals/to-object'); | ||
var toLength = require('../internals/to-length'); | ||
var toInteger = require('../internals/to-integer'); | ||
var addToUnscopables = require('../internals/add-to-unscopables'); | ||
|
||
// `Array.prototype.at` method | ||
// https://github.com/tc39/proposal-relative-indexing-method | ||
$({ target: 'Array', proto: true }, { | ||
at: function at(index) { | ||
var O = toObject(this); | ||
var len = toLength(O.length); | ||
var relativeIndex = toInteger(index); | ||
var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex; | ||
return (k < 0 || k >= len) ? undefined : O[k]; | ||
} | ||
}); | ||
|
||
addToUnscopables('at'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// TODO: disabled by default because of the conflict with another proposal | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var requireObjectCoercible = require('../internals/require-object-coercible'); | ||
var toLength = require('../internals/to-length'); | ||
var toInteger = require('../internals/to-integer'); | ||
var fails = require('../internals/fails'); | ||
|
||
var FORCED = fails(function () { | ||
return '𠮷'.at(0) !== '\uD842'; | ||
}); | ||
|
||
// `String.prototype.at` method | ||
// https://github.com/tc39/proposal-relative-indexing-method | ||
$({ target: 'String', proto: true, forced: FORCED }, { | ||
at: function at(index) { | ||
var S = String(requireObjectCoercible(this)); | ||
var len = toLength(S.length); | ||
var relativeIndex = toInteger(index); | ||
var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex; | ||
return (k < 0 || k >= len) ? undefined : S.charAt(k); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); | ||
var toLength = require('../internals/to-length'); | ||
var toInteger = require('../internals/to-integer'); | ||
|
||
var aTypedArray = ArrayBufferViewCore.aTypedArray; | ||
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; | ||
|
||
// `%TypedArray%.prototype.at` method | ||
// https://github.com/tc39/proposal-relative-indexing-method | ||
exportTypedArrayMethod('at', function at(index) { | ||
var O = aTypedArray(this); | ||
var len = toLength(O.length); | ||
var relativeIndex = toInteger(index); | ||
var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex; | ||
return (k < 0 || k >= len) ? undefined : O[k]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// https://github.com/tc39/proposal-relative-indexing-method | ||
require('../modules/esnext.array.at'); | ||
// TODO: disabled by default because of the conflict with another proposal | ||
// require('../modules/esnext.string.at-alternative'); | ||
require('../modules/esnext.typed-array.at'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require('../proposals/relative-indexing-method'); | ||
var parent = require('./4'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { STRICT } from '../helpers/constants'; | ||
|
||
import at from 'core-js-pure/features/array/at'; | ||
|
||
QUnit.test('Array#at', assert => { | ||
assert.isFunction(at); | ||
assert.same(1, at([1, 2, 3], 0)); | ||
assert.same(2, at([1, 2, 3], 1)); | ||
assert.same(3, at([1, 2, 3], 2)); | ||
assert.same(undefined, at([1, 2, 3], 3)); | ||
assert.same(3, at([1, 2, 3], -1)); | ||
assert.same(2, at([1, 2, 3], -2)); | ||
assert.same(1, at([1, 2, 3], -3)); | ||
assert.same(undefined, at([1, 2, 3], -4)); | ||
assert.same(1, at([1, 2, 3], 0.4)); | ||
assert.same(1, at([1, 2, 3], 0.5)); | ||
assert.same(1, at([1, 2, 3], 0.6)); | ||
assert.same(1, at([1], NaN)); | ||
assert.same(1, at([1])); | ||
assert.same(1, at([1, 2, 3], -0)); | ||
assert.same(undefined, at(Array(1), 0)); | ||
assert.same(1, at({ 0: 1, length: 1 }, 0)); | ||
if (STRICT) { | ||
assert.throws(() => at(null, 0), TypeError); | ||
assert.throws(() => at(undefined, 0), TypeError); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// TODO: disabled by default because of the conflict with another proposal | ||
import { STRICT } from '../helpers/constants'; | ||
|
||
import at from 'core-js-pure/features/string/at'; | ||
|
||
QUnit.test('String#at', assert => { | ||
assert.isFunction(at); | ||
assert.same('1', at('123', 0)); | ||
assert.same('2', at('123', 1)); | ||
assert.same('3', at('123', 2)); | ||
assert.same(undefined, at('123', 3)); | ||
assert.same('3', at('123', -1)); | ||
assert.same('2', at('123', -2)); | ||
assert.same('1', at('123', -3)); | ||
assert.same(undefined, at('123', -4)); | ||
assert.same('1', at('123', 0.4)); | ||
assert.same('1', at('123', 0.5)); | ||
assert.same('1', at('123', 0.6)); | ||
assert.same('1', at('1', NaN)); | ||
assert.same('1', at('1')); | ||
assert.same('1', at('123', -0)); | ||
assert.same('\uD842', at('𠮷')); | ||
assert.same('1', at({ toString() { return '123'; } }, 0)); | ||
if (STRICT) { | ||
assert.throws(() => at(null, 0), TypeError); | ||
assert.throws(() => at(undefined, 0), TypeError); | ||
} | ||
}); |
Oops, something went wrong.