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.2 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var callBound = require('call-bind/callBound');
|
---|
| 6 | var hasOwn = require('hasown');
|
---|
| 7 |
|
---|
| 8 | var $charCodeAt = callBound('String.prototype.charCodeAt');
|
---|
| 9 | var $toUpperCase = callBound('String.prototype.toUpperCase');
|
---|
| 10 |
|
---|
| 11 | var isRegExpRecord = require('../helpers/records/regexp-record');
|
---|
| 12 | var caseFolding = require('../helpers/caseFolding.json');
|
---|
| 13 |
|
---|
| 14 | // https://262.ecma-international.org/14.0/#sec-runtime-semantics-canonicalize-ch
|
---|
| 15 |
|
---|
| 16 | module.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.