source: imaps-frontend/node_modules/es-abstract/2024/GetStringIndex.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 760 bytes
Line 
1'use strict';
2
3var callBound = require('call-bound');
4var $TypeError = require('es-errors/type');
5var isInteger = require('math-intrinsics/isInteger');
6
7var StringToCodePoints = require('./StringToCodePoints');
8
9var $indexOf = callBound('String.prototype.indexOf');
10
11// https://262.ecma-international.org/13.0/#sec-getstringindex
12
13module.exports = function GetStringIndex(S, e) {
14 if (typeof S !== 'string') {
15 throw new $TypeError('Assertion failed: `S` must be a String');
16 }
17 if (!isInteger(e) || e < 0) {
18 throw new $TypeError('Assertion failed: `e` must be a non-negative integer');
19 }
20
21 if (S === '') {
22 return 0;
23 }
24 var codepoints = StringToCodePoints(S);
25 var eUTF = e >= codepoints.length ? S.length : $indexOf(S, codepoints[e]);
26 return eUTF;
27};
Note: See TracBrowser for help on using the repository browser.