source: imaps-frontend/node_modules/es-abstract/2024/WordCharacters.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.6 KB
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var callBound = require('call-bind/callBound');
6var $indexOf = callBound('String.prototype.indexOf', true);
7
8var Canonicalize = require('./Canonicalize');
9
10var caseFolding = require('../helpers/caseFolding.json');
11var forEach = require('../helpers/forEach');
12var isRegExpRecord = require('../helpers/records/regexp-record');
13var OwnPropertyKeys = require('../helpers/OwnPropertyKeys');
14
15var basicWordChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'; // step 1
16
17// https://262.ecma-international.org/14.0/#sec-runtime-semantics-wordcharacters-abstract-operation
18
19module.exports = function WordCharacters(rer) {
20 if (!isRegExpRecord(rer)) {
21 throw new $TypeError('Assertion failed: `rer` must be a RegExp Record');
22 }
23
24 var extraWordChars = '';
25 forEach(OwnPropertyKeys(caseFolding.C), function (c) {
26 if (
27 $indexOf(basicWordChars, c) === -1 // c not in A
28 && $indexOf(basicWordChars, Canonicalize(rer, c)) > -1 // canonicalized c IS in A
29 ) {
30 extraWordChars += caseFolding.C[c]; // step 3
31 }
32 });
33 forEach(OwnPropertyKeys(caseFolding.S), function (c) {
34 if (
35 $indexOf(basicWordChars, c) === -1 // c not in A
36 && $indexOf(basicWordChars, Canonicalize(rer, c)) > -1 // canonicalized c IS in A
37 ) {
38 extraWordChars += caseFolding.S[c]; // step 3
39 }
40 });
41
42 if ((!rer['[[Unicode]]'] || !rer['[[IgnoreCase]]']) && extraWordChars.length > 0) {
43 throw new $TypeError('Assertion failed: `extraWordChars` must be empty when `rer.[[IgnoreCase]]` and `rer.[[Unicode]]` are not both true'); // step 3
44 }
45
46 return basicWordChars + extraWordChars; // step 4
47};
Note: See TracBrowser for help on using the repository browser.