source: imaps-frontend/node_modules/es-abstract/2018/IsWordChar.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var callBound = require('call-bind/callBound');
6
7var $indexOf = callBound('String.prototype.indexOf');
8
9var IsArray = require('./IsArray');
10var IsInteger = require('./IsInteger');
11var WordCharacters = require('./WordCharacters');
12
13var every = require('../helpers/every');
14
15var 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.
22module.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};
Note: See TracBrowser for help on using the repository browser.