Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
917 bytes
|
Rev | Line | |
---|
[6a3a178] | 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 toInteger = require('../internals/to-integer');
|
---|
| 6 | var toLength = require('../internals/to-length');
|
---|
| 7 | var toString = require('../internals/to-string');
|
---|
| 8 | var fails = require('../internals/fails');
|
---|
| 9 |
|
---|
| 10 | var FORCED = fails(function () {
|
---|
| 11 | return '𠮷'.at(0) !== '\uD842';
|
---|
| 12 | });
|
---|
| 13 |
|
---|
| 14 | // `String.prototype.at` method
|
---|
| 15 | // https://github.com/tc39/proposal-relative-indexing-method
|
---|
| 16 | $({ target: 'String', proto: true, forced: FORCED }, {
|
---|
| 17 | at: function at(index) {
|
---|
| 18 | var S = toString(requireObjectCoercible(this));
|
---|
| 19 | var len = toLength(S.length);
|
---|
| 20 | var relativeIndex = toInteger(index);
|
---|
| 21 | var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
|
---|
| 22 | return (k < 0 || k >= len) ? undefined : S.charAt(k);
|
---|
| 23 | }
|
---|
| 24 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.