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:
791 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 $numberToString = callBound('Number.prototype.toString');
|
---|
| 9 | var $toLowerCase = callBound('String.prototype.toLowerCase');
|
---|
| 10 |
|
---|
| 11 | var StringPad = require('./StringPad');
|
---|
| 12 |
|
---|
| 13 | // https://262.ecma-international.org/11.0/#sec-unicodeescape
|
---|
| 14 |
|
---|
| 15 | module.exports = function UnicodeEscape(C) {
|
---|
| 16 | if (typeof C !== 'string' || C.length !== 1) {
|
---|
| 17 | throw new $TypeError('Assertion failed: `C` must be a single code unit');
|
---|
| 18 | }
|
---|
| 19 | var n = $charCodeAt(C, 0);
|
---|
| 20 | if (n > 0xFFFF) {
|
---|
| 21 | throw new $TypeError('`Assertion failed: numeric value of `C` must be <= 0xFFFF');
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | return '\\u' + StringPad($toLowerCase($numberToString(n, 16)), 4, '0', 'start');
|
---|
| 25 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.