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