source: imaps-frontend/node_modules/es-abstract/2015/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: 1.2 KB
Line 
1'use strict';
2
3var isInteger = require('math-intrinsics/isInteger');
4var MAX_SAFE_INTEGER = require('math-intrinsics/constants/maxSafeInteger');
5
6var isLeadingSurrogate = require('../helpers/isLeadingSurrogate');
7var isTrailingSurrogate = require('../helpers/isTrailingSurrogate');
8
9var $TypeError = require('es-errors/type');
10
11var $charCodeAt = require('call-bound')('String.prototype.charCodeAt');
12
13// https://262.ecma-international.org/6.0/#sec-advancestringindex
14
15module.exports = function AdvanceStringIndex(S, index, unicode) {
16 if (typeof S !== 'string') {
17 throw new $TypeError('Assertion failed: `S` must be a String');
18 }
19 if (!isInteger(index) || index < 0 || index > MAX_SAFE_INTEGER) {
20 throw new $TypeError('Assertion failed: `length` must be an integer >= 0 and <= 2**53');
21 }
22 if (typeof unicode !== 'boolean') {
23 throw new $TypeError('Assertion failed: `unicode` must be a Boolean');
24 }
25 if (!unicode) {
26 return index + 1;
27 }
28 var length = S.length;
29 if ((index + 1) >= length) {
30 return index + 1;
31 }
32
33 var first = $charCodeAt(S, index);
34 if (!isLeadingSurrogate(first)) {
35 return index + 1;
36 }
37
38 var second = $charCodeAt(S, index + 1);
39 if (!isTrailingSurrogate(second)) {
40 return index + 1;
41 }
42
43 return index + 2;
44};
Note: See TracBrowser for help on using the repository browser.