source: imaps-frontend/node_modules/es-abstract/2022/UnicodeEscape.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: 791 bytes
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var callBound = require('call-bind/callBound');
6
7var $charCodeAt = callBound('String.prototype.charCodeAt');
8var $numberToString = callBound('Number.prototype.toString');
9var $toLowerCase = callBound('String.prototype.toLowerCase');
10
11var StringPad = require('./StringPad');
12
13// https://262.ecma-international.org/11.0/#sec-unicodeescape
14
15module.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.