main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
766 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var callBound = require('call-bind/callBound');
|
---|
4 |
|
---|
5 | var $TypeError = require('es-errors/type');
|
---|
6 |
|
---|
7 | var StringToCodePoints = require('./StringToCodePoints');
|
---|
8 |
|
---|
9 | var isInteger = require('../helpers/isInteger');
|
---|
10 |
|
---|
11 | var $indexOf = callBound('String.prototype.indexOf');
|
---|
12 |
|
---|
13 | // https://262.ecma-international.org/13.0/#sec-getstringindex
|
---|
14 |
|
---|
15 | module.exports = function GetStringIndex(S, e) {
|
---|
16 | if (typeof S !== 'string') {
|
---|
17 | throw new $TypeError('Assertion failed: `S` must be a String');
|
---|
18 | }
|
---|
19 | if (!isInteger(e) || e < 0) {
|
---|
20 | throw new $TypeError('Assertion failed: `e` must be a non-negative integer');
|
---|
21 | }
|
---|
22 |
|
---|
23 | if (S === '') {
|
---|
24 | return 0;
|
---|
25 | }
|
---|
26 | var codepoints = StringToCodePoints(S);
|
---|
27 | var eUTF = e >= codepoints.length ? S.length : $indexOf(S, codepoints[e]);
|
---|
28 | return eUTF;
|
---|
29 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.