source: imaps-frontend/node_modules/es-abstract/2022/RegExpHasFlag.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4var callBound = require('call-bind/callBound');
5
6var $TypeError = require('es-errors/type');
7var $RegExpPrototype = GetIntrinsic('%RegExp.prototype%');
8
9var SameValue = require('./SameValue');
10var Type = require('./Type');
11
12var $indexOf = callBound('String.prototype.indexOf');
13
14var hasRegExpMatcher = require('is-regex');
15var getFlags = require('regexp.prototype.flags');
16
17// https://262.ecma-international.org/13.0/#sec-regexphasflag
18
19module.exports = function RegExpHasFlag(R, codeUnit) {
20 if (typeof codeUnit !== 'string' || codeUnit.length !== 1) {
21 throw new $TypeError('Assertion failed: `string` must be a code unit - a String of length 1');
22 }
23
24 if (Type(R) !== 'Object') {
25 throw new $TypeError('Assertion failed: Type(R) is not Object');
26 }
27
28 if (!hasRegExpMatcher(R)) { // step 2
29 if (SameValue(R, $RegExpPrototype)) {
30 return void undefined; // step 2.a
31 }
32 throw new $TypeError('`R` must be a RegExp object'); // step 2.b
33 }
34
35 var flags = getFlags(R); // step 3
36
37 return $indexOf(flags, codeUnit) > -1; // steps 4-5
38};
Note: See TracBrowser for help on using the repository browser.