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:
760 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
[79a0317] | 3 | var callBound = require('call-bound');
|
---|
[d565449] | 4 | var $TypeError = require('es-errors/type');
|
---|
[79a0317] | 5 | var isInteger = require('math-intrinsics/isInteger');
|
---|
[d565449] | 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.