GetMatchIndexPair.js 837 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var isMatchRecord = require('../helpers/records/match-record');
  4. // https://262.ecma-international.org/13.0/#sec-getmatchindexpair
  5. module.exports = function GetMatchIndexPair(S, match) {
  6. if (typeof S !== 'string') {
  7. throw new $TypeError('Assertion failed: `S` must be a String');
  8. }
  9. if (!isMatchRecord(match)) {
  10. throw new $TypeError('Assertion failed: `match` must be a Match Record');
  11. }
  12. if (!(match['[[StartIndex]]'] <= S.length)) {
  13. throw new $TypeError('`match` [[StartIndex]] must be a non-negative integer <= the length of S');
  14. }
  15. if (!(match['[[EndIndex]]'] <= S.length)) {
  16. throw new $TypeError('`match` [[EndIndex]] must be an integer between [[StartIndex]] and the length of S, inclusive');
  17. }
  18. return [match['[[StartIndex]]'], match['[[EndIndex]]']];
  19. };