source: imaps-frontend/node_modules/es-abstract/2015/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.1 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var IsArray = require('./IsArray');
6var IsInteger = require('./IsInteger');
7
8var every = require('../helpers/every');
9var regexTester = require('safe-regex-test');
10
11var isChar = function isChar(c) {
12 return typeof c === 'string' && c.length === 1;
13};
14
15var 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.
20module.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.