|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var $TypeError = require('es-errors/type');
|
|---|
| 4 |
|
|---|
| 5 | var IsArray = require('./IsArray');
|
|---|
| 6 | var IsInteger = require('./IsInteger');
|
|---|
| 7 |
|
|---|
| 8 | var every = require('../helpers/every');
|
|---|
| 9 | var regexTester = require('safe-regex-test');
|
|---|
| 10 |
|
|---|
| 11 | var isChar = function isChar(c) {
|
|---|
| 12 | return typeof c === 'string' && c.length === 1;
|
|---|
| 13 | };
|
|---|
| 14 |
|
|---|
| 15 | var isWordCharacter = regexTester(/^[a-zA-Z0-9_]$/);
|
|---|
| 16 |
|
|---|
| 17 | // https://262.ecma-international.org/6.0/#sec-runtime-semantics-iswordchar-abstract-operation
|
|---|
| 18 |
|
|---|
| 19 | // note: prior to ES2023, this AO erroneously omitted the latter of its arguments.
|
|---|
| 20 | module.exports = function IsWordChar(e, InputLength, Input) {
|
|---|
| 21 | if (!IsInteger(e)) {
|
|---|
| 22 | throw new $TypeError('Assertion failed: `e` must be an integer');
|
|---|
| 23 | }
|
|---|
| 24 | if (!IsInteger(InputLength)) {
|
|---|
| 25 | throw new $TypeError('Assertion failed: `InputLength` must be an integer');
|
|---|
| 26 | }
|
|---|
| 27 | if (!IsArray(Input) || !every(Input, isChar)) {
|
|---|
| 28 | throw new $TypeError('Assertion failed: `Input` must be a List of characters');
|
|---|
| 29 | }
|
|---|
| 30 | if (e === -1 || e === InputLength) {
|
|---|
| 31 | return false; // step 1
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | var c = Input[e]; // step 2
|
|---|
| 35 |
|
|---|
| 36 | return isWordCharacter(c); // steps 3-4
|
|---|
| 37 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.