projecte_ionic/node_modules/core-js-pure/modules/es.string.at-alternative.js
2022-02-09 18:30:03 +01:00

26 lines
918 B
JavaScript
Executable file

'use strict';
var $ = require('../internals/export');
var uncurryThis = require('../internals/function-uncurry-this');
var requireObjectCoercible = require('../internals/require-object-coercible');
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
var toString = require('../internals/to-string');
var fails = require('../internals/fails');
var charAt = uncurryThis(''.charAt);
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 = 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);
}
});