|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
760 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var callBound = require('call-bound');
|
|---|
| 4 | var $TypeError = require('es-errors/type');
|
|---|
| 5 | var isInteger = require('math-intrinsics/isInteger');
|
|---|
| 6 |
|
|---|
| 7 | var StringToCodePoints = require('./StringToCodePoints');
|
|---|
| 8 |
|
|---|
| 9 | var $indexOf = callBound('String.prototype.indexOf');
|
|---|
| 10 |
|
|---|
| 11 | // https://262.ecma-international.org/13.0/#sec-getstringindex
|
|---|
| 12 |
|
|---|
| 13 | module.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.