core-js-pure 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/es/array/virtual/filter-out.js +4 -0
- package/es/instance/replace-all.js +9 -0
- package/features/array/at.js +4 -0
- package/features/array/filter-out.js +4 -0
- package/features/array/index.js +4 -0
- package/features/array/unique-by.js +5 -0
- package/features/array/virtual/at.js +4 -0
- package/features/array/virtual/filter-out.js +4 -0
- package/features/array/virtual/index.js +3 -0
- package/features/array/virtual/unique-by.js +5 -0
- package/features/bigint/index.js +4 -0
- package/features/bigint/range.js +4 -0
- package/features/instance/at.js +7 -3
- package/features/instance/filter-out.js +8 -0
- package/features/instance/replace-all.js +2 -8
- package/features/instance/unique-by.js +8 -0
- package/features/number/index.js +1 -0
- package/features/number/range.js +4 -0
- package/features/string/index.js +2 -0
- package/features/string/virtual/index.js +2 -0
- package/features/typed-array/at.js +1 -0
- package/features/typed-array/filter-out.js +1 -0
- package/features/typed-array/index.js +2 -0
- package/internals/array-iteration.js +11 -4
- package/internals/range-iterator.js +102 -0
- package/internals/shared.js +1 -1
- package/modules/esnext.array.at.js +20 -0
- package/modules/esnext.array.filter-out.js +14 -0
- package/modules/esnext.array.unique-by.js +38 -0
- package/modules/esnext.bigint.range.js +14 -0
- package/modules/esnext.number.range.js +11 -0
- package/modules/esnext.string.at-alternative.js +23 -0
- package/modules/esnext.string.at.js +6 -1
- package/modules/esnext.typed-array.at.js +1 -0
- package/modules/esnext.typed-array.filter-out.js +1 -0
- package/package.json +1 -1
- package/proposals/array-filtering.js +3 -0
- package/proposals/array-unique.js +3 -0
- package/proposals/number-range.js +3 -0
- package/proposals/relative-indexing-method.js +5 -0
- package/stable/instance/replace-all.js +3 -0
- package/stage/1.js +3 -0
- package/stage/3.js +1 -0
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# core-js-pure
|
|
2
2
|
|
|
3
|
-
[](#sponsors) [](#backers) [](https://gitter.im/zloirock/core-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://www.npmjs.com/package/core-js-pure) [](http://npm-stat.com/charts.html?package=core-js-pure&author=&from=2019-03-18) [](#sponsors) [](#backers) [](https://gitter.im/zloirock/core-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://www.npmjs.com/package/core-js-pure) [](http://npm-stat.com/charts.html?package=core-js-pure&author=&from=2019-03-18) [](https://github.com/zloirock/core-js/actions)
|
|
4
|
+
[](https://github.com/zloirock/core-js/actions)
|
|
4
5
|
|
|
5
|
-
> Modular standard library for JavaScript. Includes polyfills for [ECMAScript up to
|
|
6
|
+
> Modular standard library for JavaScript. Includes polyfills for [ECMAScript up to 2021](https://github.com/zloirock/core-js#ecmascript): [promises](https://github.com/zloirock/core-js#ecmascript-promise), [symbols](https://github.com/zloirock/core-js#ecmascript-symbol), [collections](https://github.com/zloirock/core-js#ecmascript-collections), iterators, [typed arrays](https://github.com/zloirock/core-js#ecmascript-typed-arrays), many other features, [ECMAScript proposals](https://github.com/zloirock/core-js#ecmascript-proposals), [some cross-platform WHATWG / W3C features and proposals](#web-standards) like [`URL`](https://github.com/zloirock/core-js#url-and-urlsearchparams). You can load only required features or use it without global namespace pollution.
|
|
6
7
|
|
|
7
8
|
## As advertising: the author is looking for a good job -)
|
|
8
9
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var replaceAll = require('../string/virtual/replace-all');
|
|
2
|
+
|
|
3
|
+
var StringPrototype = String.prototype;
|
|
4
|
+
|
|
5
|
+
module.exports = function (it) {
|
|
6
|
+
var own = it.replaceAll;
|
|
7
|
+
return typeof it === 'string' || it === StringPrototype
|
|
8
|
+
|| (it instanceof String && own === StringPrototype.replaceAll) ? replaceAll : own;
|
|
9
|
+
};
|
package/features/array/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
var parent = require('../../es/array');
|
|
2
|
+
require('../../modules/es.map');
|
|
3
|
+
require('../../modules/esnext.array.at');
|
|
4
|
+
require('../../modules/esnext.array.filter-out');
|
|
2
5
|
require('../../modules/esnext.array.is-template-object');
|
|
3
6
|
require('../../modules/esnext.array.last-item');
|
|
4
7
|
require('../../modules/esnext.array.last-index');
|
|
8
|
+
require('../../modules/esnext.array.unique-by');
|
|
5
9
|
|
|
6
10
|
module.exports = parent;
|
package/features/instance/at.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
var
|
|
1
|
+
var arrayAt = require('../array/virtual/at');
|
|
2
|
+
var stringAt = require('../string/virtual/at');
|
|
2
3
|
|
|
4
|
+
var ArrayPrototype = Array.prototype;
|
|
3
5
|
var StringPrototype = String.prototype;
|
|
4
6
|
|
|
5
7
|
module.exports = function (it) {
|
|
6
8
|
var own = it.at;
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
13
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var filterOut = require('../array/virtual/filter-out');
|
|
2
|
+
|
|
3
|
+
var ArrayPrototype = Array.prototype;
|
|
4
|
+
|
|
5
|
+
module.exports = function (it) {
|
|
6
|
+
var own = it.filterOut;
|
|
7
|
+
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.filterOut) ? filterOut : own;
|
|
8
|
+
};
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var parent = require('../../stable/instance/replace-all');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports = function (it) {
|
|
6
|
-
var own = it.replaceAll;
|
|
7
|
-
return typeof it === 'string' || it === StringPrototype
|
|
8
|
-
|| (it instanceof String && own === StringPrototype.replaceAll) ? replaceAll : own;
|
|
9
|
-
};
|
|
3
|
+
module.exports = parent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var uniqueBy = require('../array/virtual/unique-by');
|
|
2
|
+
|
|
3
|
+
var ArrayPrototype = Array.prototype;
|
|
4
|
+
|
|
5
|
+
module.exports = function (it) {
|
|
6
|
+
var own = it.uniqueBy;
|
|
7
|
+
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.uniqueBy) ? uniqueBy : own;
|
|
8
|
+
};
|
package/features/number/index.js
CHANGED
package/features/string/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
var parent = require('../../es/string');
|
|
2
2
|
require('../../modules/esnext.string.at');
|
|
3
|
+
// TODO: disabled by default because of the conflict with another proposal
|
|
4
|
+
// require('../../modules/esnext.string.at-alternative');
|
|
3
5
|
require('../../modules/esnext.string.code-points');
|
|
4
6
|
// TODO: remove from `core-js@4`
|
|
5
7
|
require('../../modules/esnext.string.match-all');
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
var parent = require('../../../es/string/virtual');
|
|
2
2
|
require('../../../modules/esnext.string.at');
|
|
3
|
+
// TODO: disabled by default because of the conflict with another proposal
|
|
4
|
+
// require('../../../modules/esnext.string.at-alternative');
|
|
3
5
|
require('../../../modules/esnext.string.code-points');
|
|
4
6
|
// TODO: remove from `core-js@4`
|
|
5
7
|
require('../../../modules/esnext.string.match-all');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require('../../modules/esnext.typed-array.at');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require('../../modules/esnext.typed-array.filter-out');
|
|
@@ -6,13 +6,14 @@ var arraySpeciesCreate = require('../internals/array-species-create');
|
|
|
6
6
|
|
|
7
7
|
var push = [].push;
|
|
8
8
|
|
|
9
|
-
// `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation
|
|
9
|
+
// `Array.prototype.{ forEach, map, filter, some, every, find, findIndex, filterOut }` methods implementation
|
|
10
10
|
var createMethod = function (TYPE) {
|
|
11
11
|
var IS_MAP = TYPE == 1;
|
|
12
12
|
var IS_FILTER = TYPE == 2;
|
|
13
13
|
var IS_SOME = TYPE == 3;
|
|
14
14
|
var IS_EVERY = TYPE == 4;
|
|
15
15
|
var IS_FIND_INDEX = TYPE == 6;
|
|
16
|
+
var IS_FILTER_OUT = TYPE == 7;
|
|
16
17
|
var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
|
|
17
18
|
return function ($this, callbackfn, that, specificCreate) {
|
|
18
19
|
var O = toObject($this);
|
|
@@ -21,7 +22,7 @@ var createMethod = function (TYPE) {
|
|
|
21
22
|
var length = toLength(self.length);
|
|
22
23
|
var index = 0;
|
|
23
24
|
var create = specificCreate || arraySpeciesCreate;
|
|
24
|
-
var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
|
|
25
|
+
var target = IS_MAP ? create($this, length) : IS_FILTER || IS_FILTER_OUT ? create($this, 0) : undefined;
|
|
25
26
|
var value, result;
|
|
26
27
|
for (;length > index; index++) if (NO_HOLES || index in self) {
|
|
27
28
|
value = self[index];
|
|
@@ -33,7 +34,10 @@ var createMethod = function (TYPE) {
|
|
|
33
34
|
case 5: return value; // find
|
|
34
35
|
case 6: return index; // findIndex
|
|
35
36
|
case 2: push.call(target, value); // filter
|
|
36
|
-
} else
|
|
37
|
+
} else switch (TYPE) {
|
|
38
|
+
case 4: return false; // every
|
|
39
|
+
case 7: push.call(target, value); // filterOut
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
|
|
@@ -61,5 +65,8 @@ module.exports = {
|
|
|
61
65
|
find: createMethod(5),
|
|
62
66
|
// `Array.prototype.findIndex` method
|
|
63
67
|
// https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
|
|
64
|
-
findIndex: createMethod(6)
|
|
68
|
+
findIndex: createMethod(6),
|
|
69
|
+
// `Array.prototype.filterOut` method
|
|
70
|
+
// https://github.com/tc39/proposal-array-filtering
|
|
71
|
+
filterOut: createMethod(7)
|
|
65
72
|
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var InternalStateModule = require('../internals/internal-state');
|
|
3
|
+
var createIteratorConstructor = require('../internals/create-iterator-constructor');
|
|
4
|
+
var isObject = require('../internals/is-object');
|
|
5
|
+
var defineProperties = require('../internals/object-define-properties');
|
|
6
|
+
var DESCRIPTORS = require('../internals/descriptors');
|
|
7
|
+
|
|
8
|
+
var INCORRECT_RANGE = 'Incorrect Number.range arguments';
|
|
9
|
+
var RANGE_ITERATOR = 'RangeIterator';
|
|
10
|
+
|
|
11
|
+
var setInternalState = InternalStateModule.set;
|
|
12
|
+
var getInternalState = InternalStateModule.getterFor(RANGE_ITERATOR);
|
|
13
|
+
|
|
14
|
+
var $RangeIterator = createIteratorConstructor(function RangeIterator(start, end, option, type, zero, one) {
|
|
15
|
+
if (typeof start != type || (end !== Infinity && end !== -Infinity && typeof end != type)) {
|
|
16
|
+
throw new TypeError(INCORRECT_RANGE);
|
|
17
|
+
}
|
|
18
|
+
if (start === Infinity || start === -Infinity) {
|
|
19
|
+
throw new RangeError(INCORRECT_RANGE);
|
|
20
|
+
}
|
|
21
|
+
var ifIncrease = end > start;
|
|
22
|
+
var inclusiveEnd = false;
|
|
23
|
+
var step;
|
|
24
|
+
if (option === undefined) {
|
|
25
|
+
step = undefined;
|
|
26
|
+
} else if (isObject(option)) {
|
|
27
|
+
step = option.step;
|
|
28
|
+
inclusiveEnd = !!option.inclusive;
|
|
29
|
+
} else if (typeof option == type) {
|
|
30
|
+
step = option;
|
|
31
|
+
} else {
|
|
32
|
+
throw new TypeError(INCORRECT_RANGE);
|
|
33
|
+
}
|
|
34
|
+
if (step == null) {
|
|
35
|
+
step = ifIncrease ? one : -one;
|
|
36
|
+
}
|
|
37
|
+
if (typeof step != type) {
|
|
38
|
+
throw new TypeError(INCORRECT_RANGE);
|
|
39
|
+
}
|
|
40
|
+
if (step === Infinity || step === -Infinity || (step === zero && start !== end)) {
|
|
41
|
+
throw new RangeError(INCORRECT_RANGE);
|
|
42
|
+
}
|
|
43
|
+
// eslint-disable-next-line no-self-compare
|
|
44
|
+
var hitsEnd = start != start || end != end || step != step || (end > start) !== (step > zero);
|
|
45
|
+
setInternalState(this, {
|
|
46
|
+
type: RANGE_ITERATOR,
|
|
47
|
+
start: start,
|
|
48
|
+
end: end,
|
|
49
|
+
step: step,
|
|
50
|
+
inclusiveEnd: inclusiveEnd,
|
|
51
|
+
hitsEnd: hitsEnd,
|
|
52
|
+
currentCount: zero,
|
|
53
|
+
zero: zero
|
|
54
|
+
});
|
|
55
|
+
if (!DESCRIPTORS) {
|
|
56
|
+
this.start = start;
|
|
57
|
+
this.end = end;
|
|
58
|
+
this.step = step;
|
|
59
|
+
this.inclusive = inclusiveEnd;
|
|
60
|
+
}
|
|
61
|
+
}, RANGE_ITERATOR, function next() {
|
|
62
|
+
var state = getInternalState(this);
|
|
63
|
+
if (state.hitsEnd) return { value: undefined, done: true };
|
|
64
|
+
var start = state.start;
|
|
65
|
+
var end = state.end;
|
|
66
|
+
var step = state.step;
|
|
67
|
+
var currentYieldingValue = start + (step * state.currentCount++);
|
|
68
|
+
if (currentYieldingValue === end) state.hitsEnd = true;
|
|
69
|
+
var inclusiveEnd = state.inclusiveEnd;
|
|
70
|
+
var endCondition;
|
|
71
|
+
if (end > start) {
|
|
72
|
+
endCondition = inclusiveEnd ? currentYieldingValue > end : currentYieldingValue >= end;
|
|
73
|
+
} else {
|
|
74
|
+
endCondition = inclusiveEnd ? end > currentYieldingValue : end >= currentYieldingValue;
|
|
75
|
+
}
|
|
76
|
+
if (endCondition) {
|
|
77
|
+
return { value: undefined, done: state.hitsEnd = true };
|
|
78
|
+
} return { value: currentYieldingValue, done: false };
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
var getter = function (fn) {
|
|
82
|
+
return { get: fn, set: function () { /* empty */ }, configurable: true, enumerable: false };
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
if (DESCRIPTORS) {
|
|
86
|
+
defineProperties($RangeIterator.prototype, {
|
|
87
|
+
start: getter(function () {
|
|
88
|
+
return getInternalState(this).start;
|
|
89
|
+
}),
|
|
90
|
+
end: getter(function () {
|
|
91
|
+
return getInternalState(this).end;
|
|
92
|
+
}),
|
|
93
|
+
inclusive: getter(function () {
|
|
94
|
+
return getInternalState(this).inclusiveEnd;
|
|
95
|
+
}),
|
|
96
|
+
step: getter(function () {
|
|
97
|
+
return getInternalState(this).step;
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = $RangeIterator;
|
package/internals/shared.js
CHANGED
|
@@ -4,7 +4,7 @@ var store = require('../internals/shared-store');
|
|
|
4
4
|
(module.exports = function (key, value) {
|
|
5
5
|
return store[key] || (store[key] = value !== undefined ? value : {});
|
|
6
6
|
})('versions', []).push({
|
|
7
|
-
version: '3.
|
|
7
|
+
version: '3.8.0',
|
|
8
8
|
mode: IS_PURE ? 'pure' : 'global',
|
|
9
9
|
copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
|
|
10
10
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var $ = require('../internals/export');
|
|
3
|
+
var toObject = require('../internals/to-object');
|
|
4
|
+
var toLength = require('../internals/to-length');
|
|
5
|
+
var toInteger = require('../internals/to-integer');
|
|
6
|
+
var addToUnscopables = require('../internals/add-to-unscopables');
|
|
7
|
+
|
|
8
|
+
// `Array.prototype.at` method
|
|
9
|
+
// https://github.com/tc39/proposal-relative-indexing-method
|
|
10
|
+
$({ target: 'Array', proto: true }, {
|
|
11
|
+
at: function at(index) {
|
|
12
|
+
var O = toObject(this);
|
|
13
|
+
var len = toLength(O.length);
|
|
14
|
+
var relativeIndex = toInteger(index);
|
|
15
|
+
var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
|
|
16
|
+
return (k < 0 || k >= len) ? undefined : O[k];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
addToUnscopables('at');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var $ = require('../internals/export');
|
|
3
|
+
var $filterOut = require('../internals/array-iteration').filterOut;
|
|
4
|
+
var addToUnscopables = require('../internals/add-to-unscopables');
|
|
5
|
+
|
|
6
|
+
// `Array.prototype.filterOut` method
|
|
7
|
+
// https://github.com/tc39/proposal-array-filtering
|
|
8
|
+
$({ target: 'Array', proto: true }, {
|
|
9
|
+
filterOut: function filterOut(callbackfn /* , thisArg */) {
|
|
10
|
+
return $filterOut(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
addToUnscopables('filterOut');
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var $ = require('../internals/export');
|
|
3
|
+
var toLength = require('../internals/to-length');
|
|
4
|
+
var toObject = require('../internals/to-object');
|
|
5
|
+
var getBuiltIn = require('../internals/get-built-in');
|
|
6
|
+
var arraySpeciesCreate = require('../internals/array-species-create');
|
|
7
|
+
var addToUnscopables = require('../internals/add-to-unscopables');
|
|
8
|
+
|
|
9
|
+
var push = [].push;
|
|
10
|
+
|
|
11
|
+
// `Array.prototype.uniqueBy` method
|
|
12
|
+
// https://github.com/tc39/proposal-array-unique
|
|
13
|
+
$({ target: 'Array', proto: true }, {
|
|
14
|
+
uniqueBy: function uniqueBy(resolver) {
|
|
15
|
+
var that = toObject(this);
|
|
16
|
+
var length = toLength(that.length);
|
|
17
|
+
var result = arraySpeciesCreate(that, 0);
|
|
18
|
+
var Map = getBuiltIn('Map');
|
|
19
|
+
var map = new Map();
|
|
20
|
+
var resolverFunction, index, item, key;
|
|
21
|
+
if (typeof resolver == 'function') resolverFunction = resolver;
|
|
22
|
+
else if (resolver == null) resolverFunction = function (value) {
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
else throw new TypeError('Incorrect resolver!');
|
|
26
|
+
for (index = 0; index < length; index++) {
|
|
27
|
+
item = that[index];
|
|
28
|
+
key = resolverFunction(item);
|
|
29
|
+
if (!map.has(key)) map.set(key, item);
|
|
30
|
+
}
|
|
31
|
+
map.forEach(function (value) {
|
|
32
|
+
push.call(result, value);
|
|
33
|
+
});
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
addToUnscopables('uniqueBy');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var $ = require('../internals/export');
|
|
3
|
+
var RangeIterator = require('../internals/range-iterator');
|
|
4
|
+
|
|
5
|
+
// `BigInt.range` method
|
|
6
|
+
// https://github.com/tc39/proposal-Number.range
|
|
7
|
+
if (typeof BigInt == 'function') {
|
|
8
|
+
$({ target: 'BigInt', stat: true }, {
|
|
9
|
+
range: function range(start, end, option) {
|
|
10
|
+
// eslint-disable-next-line no-undef
|
|
11
|
+
return new RangeIterator(start, end, option, 'bigint', BigInt(0), BigInt(1));
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var $ = require('../internals/export');
|
|
3
|
+
var RangeIterator = require('../internals/range-iterator');
|
|
4
|
+
|
|
5
|
+
// `Number.range` method
|
|
6
|
+
// https://github.com/tc39/proposal-Number.range
|
|
7
|
+
$({ target: 'Number', stat: true }, {
|
|
8
|
+
range: function range(start, end, option) {
|
|
9
|
+
return new RangeIterator(start, end, option, 'number', 0, 1);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// TODO: disabled by default because of the conflict with another proposal
|
|
2
|
+
'use strict';
|
|
3
|
+
var $ = require('../internals/export');
|
|
4
|
+
var requireObjectCoercible = require('../internals/require-object-coercible');
|
|
5
|
+
var toLength = require('../internals/to-length');
|
|
6
|
+
var toInteger = require('../internals/to-integer');
|
|
7
|
+
var fails = require('../internals/fails');
|
|
8
|
+
|
|
9
|
+
var FORCED = fails(function () {
|
|
10
|
+
return '𠮷'.at(0) !== '\uD842';
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// `String.prototype.at` method
|
|
14
|
+
// https://github.com/tc39/proposal-relative-indexing-method
|
|
15
|
+
$({ target: 'String', proto: true, forced: FORCED }, {
|
|
16
|
+
at: function at(index) {
|
|
17
|
+
var S = String(requireObjectCoercible(this));
|
|
18
|
+
var len = toLength(S.length);
|
|
19
|
+
var relativeIndex = toInteger(index);
|
|
20
|
+
var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
|
|
21
|
+
return (k < 0 || k >= len) ? undefined : S.charAt(k);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
var $ = require('../internals/export');
|
|
3
3
|
var charAt = require('../internals/string-multibyte').charAt;
|
|
4
|
+
var fails = require('../internals/fails');
|
|
5
|
+
|
|
6
|
+
var FORCED = fails(function () {
|
|
7
|
+
return '𠮷'.at(0) !== '𠮷';
|
|
8
|
+
});
|
|
4
9
|
|
|
5
10
|
// `String.prototype.at` method
|
|
6
11
|
// https://github.com/mathiasbynens/String.prototype.at
|
|
7
|
-
$({ target: 'String', proto: true }, {
|
|
12
|
+
$({ target: 'String', proto: true, forced: FORCED }, {
|
|
8
13
|
at: function at(pos) {
|
|
9
14
|
return charAt(this, pos);
|
|
10
15
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// empty
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// empty
|
package/package.json
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// https://github.com/tc39/proposal-relative-indexing-method
|
|
2
|
+
require('../modules/esnext.array.at');
|
|
3
|
+
// TODO: disabled by default because of the conflict with another proposal
|
|
4
|
+
// require('../modules/esnext.string.at-alternative');
|
|
5
|
+
require('../modules/esnext.typed-array.at');
|
package/stage/1.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
require('../proposals/array-filtering');
|
|
1
2
|
require('../proposals/array-last');
|
|
3
|
+
require('../proposals/array-unique');
|
|
2
4
|
require('../proposals/collection-methods');
|
|
3
5
|
require('../proposals/collection-of-from');
|
|
4
6
|
require('../proposals/keys-composition');
|
|
5
7
|
require('../proposals/math-extensions');
|
|
6
8
|
require('../proposals/math-signbit');
|
|
7
9
|
require('../proposals/number-from-string');
|
|
10
|
+
require('../proposals/number-range');
|
|
8
11
|
require('../proposals/object-iteration');
|
|
9
12
|
require('../proposals/observable');
|
|
10
13
|
require('../proposals/pattern-matching');
|
package/stage/3.js
CHANGED