source: imaps-frontend/node_modules/es-abstract/2022/WordCharacters.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
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 OwnPropertyKeys = require('../helpers/OwnPropertyKeys');
13
14var A = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'; // step 1
15
16// https://262.ecma-international.org/8.0/#sec-runtime-semantics-wordcharacters-abstract-operation
17
18module.exports = function WordCharacters(IgnoreCase, Unicode) {
19 if (typeof IgnoreCase !== 'boolean' || typeof Unicode !== 'boolean') {
20 throw new $TypeError('Assertion failed: `IgnoreCase` and `Unicode` must be booleans');
21 }
22
23 var U = '';
24 forEach(OwnPropertyKeys(caseFolding.C), function (c) {
25 if (
26 $indexOf(A, c) === -1 // c not in A
27 && $indexOf(A, Canonicalize(c, IgnoreCase, Unicode)) > -1 // canonicalized c IS in A
28 ) {
29 U += caseFolding.C[c]; // step 3
30 }
31 });
32 forEach(OwnPropertyKeys(caseFolding.S), function (c) {
33 if (
34 $indexOf(A, c) === -1 // c not in A
35 && $indexOf(A, Canonicalize(c, IgnoreCase, Unicode)) > -1 // canonicalized c IS in A
36 ) {
37 U += caseFolding.S[c]; // step 3
38 }
39 });
40
41 if ((!Unicode || !IgnoreCase) && U.length > 0) {
42 throw new $TypeError('Assertion failed: `U` must be empty when `IgnoreCase` and `Unicode` are not both true'); // step 4
43 }
44
45 return A + U; // step 5, 6
46};
Note: See TracBrowser for help on using the repository browser.