source: imaps-frontend/node_modules/es-abstract/2022/StringIndexOf.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.0 KB
Line 
1'use strict';
2
3var callBound = require('call-bound');
4
5var $TypeError = require('es-errors/type');
6var isInteger = require('math-intrinsics/isInteger');
7
8var $slice = callBound('String.prototype.slice');
9
10// https://262.ecma-international.org/12.0/#sec-stringindexof
11
12module.exports = function StringIndexOf(string, searchValue, fromIndex) {
13 if (typeof string !== 'string') {
14 throw new $TypeError('Assertion failed: `string` must be a String');
15 }
16 if (typeof searchValue !== 'string') {
17 throw new $TypeError('Assertion failed: `searchValue` must be a String');
18 }
19 if (!isInteger(fromIndex) || fromIndex < 0) {
20 throw new $TypeError('Assertion failed: `fromIndex` must be a non-negative integer');
21 }
22
23 var len = string.length;
24 if (searchValue === '' && fromIndex <= len) {
25 return fromIndex;
26 }
27
28 var searchLen = searchValue.length;
29 for (var i = fromIndex; i <= (len - searchLen); i += 1) {
30 var candidate = $slice(string, i, i + searchLen);
31 if (candidate === searchValue) {
32 return i;
33 }
34 }
35 return -1;
36};
Note: See TracBrowser for help on using the repository browser.