source: imaps-frontend/node_modules/es-abstract/2023/RegExpHasFlag.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

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