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:
884 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 |
|
---|
5 | var substring = require('./substring');
|
---|
6 |
|
---|
7 | var isMatchRecord = require('../helpers/records/match-record');
|
---|
8 |
|
---|
9 | // https://262.ecma-international.org/13.0/#sec-getmatchstring
|
---|
10 |
|
---|
11 | module.exports = function GetMatchString(S, match) {
|
---|
12 | if (typeof S !== 'string') {
|
---|
13 | throw new $TypeError('Assertion failed: `S` must be a String');
|
---|
14 | }
|
---|
15 | if (!isMatchRecord(match)) {
|
---|
16 | throw new $TypeError('Assertion failed: `match` must be a Match Record');
|
---|
17 | }
|
---|
18 |
|
---|
19 | if (!(match['[[StartIndex]]'] <= S.length)) {
|
---|
20 | throw new $TypeError('`match` [[StartIndex]] must be a non-negative integer <= the length of S');
|
---|
21 | }
|
---|
22 | if (!(match['[[EndIndex]]'] <= S.length)) {
|
---|
23 | throw new $TypeError('`match` [[EndIndex]] must be an integer between [[StartIndex]] and the length of S, inclusive');
|
---|
24 | }
|
---|
25 | return substring(S, match['[[StartIndex]]'], match['[[EndIndex]]']);
|
---|
26 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.