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 IsInteger = require('./IsInteger');
|
---|
11 | var WordCharacters = require('./WordCharacters');
|
---|
12 |
|
---|
13 | var every = require('../helpers/every');
|
---|
14 |
|
---|
15 | var isChar = function isChar(c) {
|
---|
16 | return typeof c === 'string';
|
---|
17 | };
|
---|
18 |
|
---|
19 | // https://262.ecma-international.org/8.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(e, InputLength, Input, IgnoreCase, Unicode) {
|
---|
23 | if (!IsInteger(e)) {
|
---|
24 | throw new $TypeError('Assertion failed: `e` must be an integer');
|
---|
25 | }
|
---|
26 | if (!IsInteger(InputLength)) {
|
---|
27 | throw new $TypeError('Assertion failed: `InputLength` must be an integer');
|
---|
28 | }
|
---|
29 | if (!IsArray(Input) || !every(Input, isChar)) {
|
---|
30 | throw new $TypeError('Assertion failed: `Input` must be a List of characters');
|
---|
31 | }
|
---|
32 | if (typeof IgnoreCase !== 'boolean' || typeof Unicode !== 'boolean') {
|
---|
33 | throw new $TypeError('Assertion failed: `IgnoreCase` and `Unicode` must be booleans');
|
---|
34 | }
|
---|
35 |
|
---|
36 | if (e === -1 || e === InputLength) {
|
---|
37 | return false; // step 1
|
---|
38 | }
|
---|
39 |
|
---|
40 | var c = Input[e]; // step 2
|
---|
41 |
|
---|
42 | var wordChars = WordCharacters(IgnoreCase, Unicode);
|
---|
43 |
|
---|
44 | return $indexOf(wordChars, c) > -1; // steps 3-4
|
---|
45 | };
|
---|