source: imaps-frontend/node_modules/es-abstract/2024/Canonicalize.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
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var callBound = require('call-bind/callBound');
6var hasOwn = require('hasown');
7
8var $charCodeAt = callBound('String.prototype.charCodeAt');
9var $toUpperCase = callBound('String.prototype.toUpperCase');
10
11var isRegExpRecord = require('../helpers/records/regexp-record');
12var caseFolding = require('../helpers/caseFolding.json');
13
14// https://262.ecma-international.org/14.0/#sec-runtime-semantics-canonicalize-ch
15
16module.exports = function Canonicalize(rer, ch) {
17 if (!isRegExpRecord(rer)) {
18 throw new $TypeError('Assertion failed: `rer` must be a RegExp Record');
19 }
20
21 if (typeof ch !== 'string') {
22 throw new $TypeError('Assertion failed: `ch` must be a character');
23 }
24
25 if (rer['[[Unicode]]'] && rer['[[IgnoreCase]]']) { // step 1
26 if (hasOwn(caseFolding.C, ch)) {
27 return caseFolding.C[ch];
28 }
29 if (hasOwn(caseFolding.S, ch)) {
30 return caseFolding.S[ch];
31 }
32 return ch; // step 1.b
33 }
34
35 if (!rer['[[IgnoreCase]]']) {
36 return ch; // step 2
37 }
38
39 var u = $toUpperCase(ch); // step 5
40
41 if (u.length !== 1) {
42 return ch; // step 7
43 }
44
45 var cu = u; // step 8
46
47 if ($charCodeAt(ch, 0) >= 128 && $charCodeAt(cu, 0) < 128) {
48 return ch; // step 9
49 }
50
51 return cu; // step 10
52};
Note: See TracBrowser for help on using the repository browser.