Skip to content
Permalink
Newer
Older
100644 26 lines (19 sloc) 846 Bytes
Ignoring revisions in .git-blame-ignore-revs.
September 14, 2020 10:42
1
'use strict';
2
July 27, 2021 16:54
3
var GetIntrinsic = require('get-intrinsic');
September 14, 2020 10:42
4
5
var $TypeError = GetIntrinsic('%TypeError%');
6
July 27, 2021 16:54
7
var callBound = require('call-bind/callBound');
September 14, 2020 10:42
8
9
var $charCodeAt = callBound('String.prototype.charCodeAt');
10
var $numberToString = callBound('Number.prototype.toString');
11
var $toLowerCase = callBound('String.prototype.toLowerCase');
12
var $strSlice = callBound('String.prototype.slice');
13
July 27, 2021 16:54
14
// https://262.ecma-international.org/9.0/#sec-unicodeescape
September 14, 2020 10:42
15
16
module.exports = function UnicodeEscape(C) {
17
if (typeof C !== 'string' || C.length !== 1) {
18
throw new $TypeError('Assertion failed: `C` must be a single code unit');
19
}
20
var n = $charCodeAt(C, 0);
21
if (n > 0xFFFF) {
22
throw new $TypeError('`Assertion failed: numeric value of `C` must be <= 0xFFFF');
23
}
24
25
return '\\u' + $strSlice('0000' + $toLowerCase($numberToString(n, 16)), -4);
26
};