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:
854 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var callBound = require('call-bind/callBound');
|
---|
| 6 |
|
---|
| 7 | var $charCodeAt = callBound('String.prototype.charCodeAt');
|
---|
| 8 | var $toUpperCase = callBound('String.prototype.toUpperCase');
|
---|
| 9 |
|
---|
| 10 | // https://262.ecma-international.org/5.1/#sec-15.10.2.8
|
---|
| 11 |
|
---|
| 12 | module.exports = function Canonicalize(ch, IgnoreCase) {
|
---|
| 13 | if (typeof ch !== 'string' || ch.length !== 1) {
|
---|
| 14 | throw new $TypeError('Assertion failed: `ch` must be a character');
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | if (typeof IgnoreCase !== 'boolean') {
|
---|
| 18 | throw new $TypeError('Assertion failed: `IgnoreCase` must be a Boolean');
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | if (!IgnoreCase) {
|
---|
| 22 | return ch; // step 1
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | var u = $toUpperCase(ch); // step 2
|
---|
| 26 |
|
---|
| 27 | if (u.length !== 1) {
|
---|
| 28 | return ch; // step 3
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | var cu = u; // step 4
|
---|
| 32 |
|
---|
| 33 | if ($charCodeAt(ch, 0) >= 128 && $charCodeAt(cu, 0) < 128) {
|
---|
| 34 | return ch; // step 5
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | return cu;
|
---|
| 38 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.