main
Last change
on this file 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 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 | var callBound = require('call-bind/callBound');
|
---|
5 |
|
---|
6 | var $TypeError = require('es-errors/type');
|
---|
7 | var $RegExpPrototype = GetIntrinsic('%RegExp.prototype%');
|
---|
8 |
|
---|
9 | var SameValue = require('./SameValue');
|
---|
10 | var Type = require('./Type');
|
---|
11 |
|
---|
12 | var $indexOf = callBound('String.prototype.indexOf');
|
---|
13 |
|
---|
14 | var hasRegExpMatcher = require('is-regex');
|
---|
15 | var getFlags = require('regexp.prototype.flags');
|
---|
16 |
|
---|
17 | // https://262.ecma-international.org/13.0/#sec-regexphasflag
|
---|
18 |
|
---|
19 | module.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.