Urara-Blog/node_modules/.pnpm-store/v3/files/6c/bff7613f6a9ebd063f1669a0cb09a057464d981b583bf940a3cb47f2ed46c9938afbe65466f8345b2c3c1b60f4cac4f9de5b7521731d909b84a8c7439d7e9c
2022-08-14 01:14:53 +08:00

27 lines
901 B
Text

'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]]']);
};