source: frontend/node_modules/es-abstract/2021/IsWordChar.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var callBound = require('call-bound');
6
7var $indexOf = callBound('String.prototype.indexOf');
8
9var IsArray = require('./IsArray');
10var WordCharacters = require('./WordCharacters');
11
12var every = require('../helpers/every');
13
14var isInteger = require('math-intrinsics/isInteger');
15
16var isChar = function isChar(c) {
17 return typeof c === 'string';
18};
19
20// https://262.ecma-international.org/12.0/#sec-runtime-semantics-iswordchar-abstract-operation
21
22// note: prior to ES2023, this AO erroneously omitted the latter of its arguments.
23module.exports = function IsWordChar(e, InputLength, Input, IgnoreCase, Unicode) {
24 if (!isInteger(e)) {
25 throw new $TypeError('Assertion failed: `e` must be an integer');
26 }
27 if (!isInteger(InputLength)) {
28 throw new $TypeError('Assertion failed: `InputLength` must be an integer');
29 }
30 if (!IsArray(Input) || !every(Input, isChar)) {
31 throw new $TypeError('Assertion failed: `Input` must be a List of characters');
32 }
33 if (typeof IgnoreCase !== 'boolean' || typeof Unicode !== 'boolean') {
34 throw new $TypeError('Assertion failed: `IgnoreCase` and `Unicode` must be booleans');
35 }
36
37 if (e === -1 || e === InputLength) {
38 return false; // step 1
39 }
40
41 var c = Input[e]; // step 2
42
43 var wordChars = WordCharacters(IgnoreCase, Unicode);
44
45 return $indexOf(wordChars, c) > -1; // steps 3-4
46};
Note: See TracBrowser for help on using the repository browser.