source: imaps-frontend/node_modules/es-abstract/2024/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.2 KB
Line 
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 WordCharacters = require('./WordCharacters');
11
12var every = require('../helpers/every');
13var isInteger = require('../helpers/isInteger');
14var isRegExpRecord = require('../helpers/records/regexp-record');
15
16var 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.
23module.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};
Note: See TracBrowser for help on using the repository browser.