source: imaps-frontend/node_modules/es-abstract/2019/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: 798 bytes
Line 
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');
10var $strSlice = callBound('String.prototype.slice');
11
12// https://262.ecma-international.org/9.0/#sec-unicodeescape
13
14module.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.