source: imaps-frontend/node_modules/es-abstract/2018/SplitMatch.js@ d565449

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: 808 bytes
Line 
1'use strict';
2
3var callBound = require('call-bind/callBound');
4
5var $TypeError = require('es-errors/type');
6
7var isInteger = require('../helpers/isInteger');
8
9var $charAt = callBound('String.prototype.charAt');
10
11// https://262.ecma-international.org/6.0/#sec-splitmatch
12
13module.exports = function SplitMatch(S, q, R) {
14 if (typeof S !== 'string') {
15 throw new $TypeError('Assertion failed: `S` must be a String');
16 }
17 if (!isInteger(q)) {
18 throw new $TypeError('Assertion failed: `q` must be an integer');
19 }
20 if (typeof R !== 'string') {
21 throw new $TypeError('Assertion failed: `R` must be a String');
22 }
23 var r = R.length;
24 var s = S.length;
25 if (q + r > s) {
26 return false;
27 }
28
29 for (var i = 0; i < r; i += 1) {
30 if ($charAt(S, q + i) !== $charAt(R, i)) {
31 return false;
32 }
33 }
34
35 return q + r;
36};
Note: See TracBrowser for help on using the repository browser.