Urara-Blog/node_modules/.pnpm-store/v3/files/f3/1c26c41de052f351fe1ff34e0c812bb5b11616031d92404e27a9744806288e8ac3688041978a368de44c7aceda8d87343af7b1d0fbc75bfdef44395880ec79
2022-08-14 01:14:53 +08:00

27 lines
839 B
Text

'use strict';
var GetIntrinsic = require('get-intrinsic');
var $TypeError = GetIntrinsic('%TypeError%');
var callBound = require('call-bind/callBound');
var $charCodeAt = callBound('String.prototype.charCodeAt');
var $numberToString = callBound('Number.prototype.toString');
var $toLowerCase = callBound('String.prototype.toLowerCase');
var StringPad = require('./StringPad');
// https://262.ecma-international.org/11.0/#sec-unicodeescape
module.exports = function UnicodeEscape(C) {
if (typeof C !== 'string' || C.length !== 1) {
throw new $TypeError('Assertion failed: `C` must be a single code unit');
}
var n = $charCodeAt(C, 0);
if (n > 0xFFFF) {
throw new $TypeError('`Assertion failed: numeric value of `C` must be <= 0xFFFF');
}
return '\\u' + StringPad($toLowerCase($numberToString(n, 16)), 4, '0', 'start');
};