1 | 'use strict';
|
---|
2 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 | var callBound = require('call-bound');
|
---|
5 | var isInteger = require('math-intrinsics/isInteger');
|
---|
6 |
|
---|
7 | var $indexOf = callBound('String.prototype.indexOf');
|
---|
8 |
|
---|
9 | var IsArray = require('./IsArray');
|
---|
10 | var WordCharacters = require('./WordCharacters');
|
---|
11 |
|
---|
12 | var every = require('../helpers/every');
|
---|
13 | var isRegExpRecord = require('../helpers/records/regexp-record');
|
---|
14 |
|
---|
15 | var isChar = function isChar(c) {
|
---|
16 | return typeof c === 'string';
|
---|
17 | };
|
---|
18 |
|
---|
19 | // https://262.ecma-international.org/14.0/#sec-runtime-semantics-iswordchar-abstract-operation
|
---|
20 |
|
---|
21 | // note: prior to ES2023, this AO erroneously omitted the latter of its arguments.
|
---|
22 | module.exports = function IsWordChar(rer, Input, e) {
|
---|
23 | if (!isRegExpRecord(rer)) {
|
---|
24 | throw new $TypeError('Assertion failed: `rer` must be a RegExp Record');
|
---|
25 | }
|
---|
26 | if (!IsArray(Input) || !every(Input, isChar)) {
|
---|
27 | throw new $TypeError('Assertion failed: `Input` must be a List of characters');
|
---|
28 | }
|
---|
29 |
|
---|
30 | if (!isInteger(e)) {
|
---|
31 | throw new $TypeError('Assertion failed: `e` must be an integer');
|
---|
32 | }
|
---|
33 |
|
---|
34 | var InputLength = Input.length; // step 1
|
---|
35 |
|
---|
36 | if (e === -1 || e === InputLength) {
|
---|
37 | return false; // step 2
|
---|
38 | }
|
---|
39 |
|
---|
40 | var c = Input[e]; // step 3
|
---|
41 |
|
---|
42 | return $indexOf(WordCharacters(rer), c) > -1; // steps 4-5
|
---|
43 | };
|
---|