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:
825 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var callBound = require('call-bind/callBound');
|
---|
4 |
|
---|
5 | var $TypeError = require('es-errors/type');
|
---|
6 |
|
---|
7 | var isInteger = require('../helpers/isInteger');
|
---|
8 |
|
---|
9 | var $charAt = callBound('String.prototype.charAt');
|
---|
10 |
|
---|
11 | // https://262.ecma-international.org/12.0/#sec-splitmatch
|
---|
12 |
|
---|
13 | module.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 'not-matched';
|
---|
27 | }
|
---|
28 |
|
---|
29 | for (var i = 0; i < r; i += 1) {
|
---|
30 | if ($charAt(S, q + i) !== $charAt(R, i)) {
|
---|
31 | return 'not-matched';
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | return q + r;
|
---|
36 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.