Skip to content
Permalink
Newer
Older
100644 26 lines (19 sloc) 850 Bytes
Ignoring revisions in .git-blame-ignore-revs.
1
'use strict';
2
3
var GetIntrinsic = require('get-intrinsic');
4
5
var $TypeError = GetIntrinsic('%TypeError%');
6
7
var Type = require('./Type');
8
9
var assertRecord = require('../helpers/assertRecord');
10
11
// https://262.ecma-international.org/13.0/#sec-getmatchindexpair
12
13
module.exports = function GetMatchIndexPair(S, match) {
14
if (Type(S) !== 'String') {
15
throw new $TypeError('Assertion failed: `S` must be a String');
16
}
17
assertRecord(Type, 'Match Record', 'match', match);
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 [match['[[StartIndex]]'], match['[[EndIndex]]']];
26
};