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