[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var callBound = require('call-bind/callBound');
|
---|
| 6 | var $indexOf = callBound('String.prototype.indexOf', true);
|
---|
| 7 |
|
---|
| 8 | var Canonicalize = require('./Canonicalize');
|
---|
| 9 |
|
---|
| 10 | var caseFolding = require('../helpers/caseFolding.json');
|
---|
| 11 | var forEach = require('../helpers/forEach');
|
---|
| 12 | var OwnPropertyKeys = require('../helpers/OwnPropertyKeys');
|
---|
| 13 |
|
---|
| 14 | var A = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'; // step 1
|
---|
| 15 |
|
---|
| 16 | // https://262.ecma-international.org/8.0/#sec-runtime-semantics-wordcharacters-abstract-operation
|
---|
| 17 |
|
---|
| 18 | module.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 | };
|
---|