12345678910111213141516171819 |
- 'use strict';
- // TODO: Remove from `core-js@4`
- var $ = require('../internals/export');
- var charAt = require('../internals/string-multibyte').charAt;
- var requireObjectCoercible = require('../internals/require-object-coercible');
- var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
- var toString = require('../internals/to-string');
- // `String.prototype.at` method
- // https://github.com/mathiasbynens/String.prototype.at
- $({ target: 'String', proto: true, forced: true }, {
- at: function at(index) {
- var S = toString(requireObjectCoercible(this));
- var len = S.length;
- var relativeIndex = toIntegerOrInfinity(index);
- var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
- return (k < 0 || k >= len) ? undefined : charAt(S, k);
- }
- });
|