main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
974 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
4 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
---|
5 | var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
---|
6 | var toString = require('../internals/to-string');
|
---|
7 | var fails = require('../internals/fails');
|
---|
8 |
|
---|
9 | var charAt = uncurryThis(''.charAt);
|
---|
10 |
|
---|
11 | var FORCED = fails(function () {
|
---|
12 | // eslint-disable-next-line es/no-string-prototype-at -- safe
|
---|
13 | return '𠮷'.at(-2) !== '\uD842';
|
---|
14 | });
|
---|
15 |
|
---|
16 | // `String.prototype.at` method
|
---|
17 | // https://tc39.es/ecma262/#sec-string.prototype.at
|
---|
18 | $({ target: 'String', proto: true, forced: FORCED }, {
|
---|
19 | at: function at(index) {
|
---|
20 | var S = toString(requireObjectCoercible(this));
|
---|
21 | var len = S.length;
|
---|
22 | var relativeIndex = toIntegerOrInfinity(index);
|
---|
23 | var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
|
---|
24 | return (k < 0 || k >= len) ? undefined : charAt(S, k);
|
---|
25 | }
|
---|
26 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.