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

24 lines
865 B
JavaScript
Executable file

// TODO: disabled by default because of the conflict with another proposal
'use strict';
var $ = require('../internals/export');
var requireObjectCoercible = require('../internals/require-object-coercible');
var toLength = require('../internals/to-length');
var toInteger = require('../internals/to-integer');
var fails = require('../internals/fails');
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 = String(requireObjectCoercible(this));
var len = toLength(S.length);
var relativeIndex = toInteger(index);
var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
return (k < 0 || k >= len) ? undefined : S.charAt(k);
}
});