source: imaps-frontend/node_modules/es-abstract/2022/AdvanceStringIndex.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: 936 bytes
RevLine 
[d565449]1'use strict';
2
3var CodePointAt = require('./CodePointAt');
4
5var $TypeError = require('es-errors/type');
[79a0317]6var isInteger = require('math-intrinsics/isInteger');
7var MAX_SAFE_INTEGER = require('math-intrinsics/constants/maxSafeInteger');
[d565449]8
9// https://262.ecma-international.org/12.0/#sec-advancestringindex
10
11module.exports = function AdvanceStringIndex(S, index, unicode) {
12 if (typeof S !== 'string') {
13 throw new $TypeError('Assertion failed: `S` must be a String');
14 }
15 if (!isInteger(index) || index < 0 || index > MAX_SAFE_INTEGER) {
16 throw new $TypeError('Assertion failed: `length` must be an integer >= 0 and <= 2**53');
17 }
18 if (typeof unicode !== 'boolean') {
19 throw new $TypeError('Assertion failed: `unicode` must be a Boolean');
20 }
21 if (!unicode) {
22 return index + 1;
23 }
24 var length = S.length;
25 if ((index + 1) >= length) {
26 return index + 1;
27 }
28 var cp = CodePointAt(S, index);
29 return index + cp['[[CodeUnitCount]]'];
30};
Note: See TracBrowser for help on using the repository browser.