保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use strict';
 
var GetIntrinsic = require('get-intrinsic');
 
var $TypeError = GetIntrinsic('%TypeError%');
 
var substring = require('./substring');
var Type = require('./Type');
 
var assertRecord = require('../helpers/assertRecord');
 
// https://ecma-international.org/ecma-262/13.0/#sec-getmatchstring
 
module.exports = function GetMatchString(S, match) {
    if (Type(S) !== 'String') {
        throw new $TypeError('Assertion failed: `S` must be a String');
    }
    assertRecord(Type, 'Match Record', 'match', match);
 
    if (!(match['[[StartIndex]]'] <= S.length)) {
        throw new $TypeError('`match` [[StartIndex]] must be a non-negative integer <= the length of S');
    }
    if (!(match['[[EndIndex]]'] <= S.length)) {
        throw new $TypeError('`match` [[EndIndex]] must be an integer between [[StartIndex]] and the length of S, inclusive');
    }
    return substring(S, match['[[StartIndex]]'], match['[[EndIndex]]']);
};