main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
917 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var CodePointAt = require('./CodePointAt');
|
---|
4 |
|
---|
5 | var isInteger = require('../helpers/isInteger');
|
---|
6 | var MAX_SAFE_INTEGER = require('../helpers/maxSafeInteger');
|
---|
7 |
|
---|
8 | var $TypeError = require('es-errors/type');
|
---|
9 |
|
---|
10 | // https://262.ecma-international.org/12.0/#sec-advancestringindex
|
---|
11 |
|
---|
12 | module.exports = function AdvanceStringIndex(S, index, unicode) {
|
---|
13 | if (typeof S !== 'string') {
|
---|
14 | throw new $TypeError('Assertion failed: `S` must be a String');
|
---|
15 | }
|
---|
16 | if (!isInteger(index) || index < 0 || index > MAX_SAFE_INTEGER) {
|
---|
17 | throw new $TypeError('Assertion failed: `length` must be an integer >= 0 and <= 2**53');
|
---|
18 | }
|
---|
19 | if (typeof unicode !== 'boolean') {
|
---|
20 | throw new $TypeError('Assertion failed: `unicode` must be a Boolean');
|
---|
21 | }
|
---|
22 | if (!unicode) {
|
---|
23 | return index + 1;
|
---|
24 | }
|
---|
25 | var length = S.length;
|
---|
26 | if ((index + 1) >= length) {
|
---|
27 | return index + 1;
|
---|
28 | }
|
---|
29 | var cp = CodePointAt(S, index);
|
---|
30 | return index + cp['[[CodeUnitCount]]'];
|
---|
31 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.