From 46e43f4bde4a35785b4997b81e86cd19f046b69b Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 21 Dec 2021 16:52:28 +0100 Subject: Commit --- src/node_modules/es-abstract/2018/UnicodeEscape.js | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/node_modules/es-abstract/2018/UnicodeEscape.js (limited to 'src/node_modules/es-abstract/2018/UnicodeEscape.js') diff --git a/src/node_modules/es-abstract/2018/UnicodeEscape.js b/src/node_modules/es-abstract/2018/UnicodeEscape.js new file mode 100644 index 0000000..aeca437 --- /dev/null +++ b/src/node_modules/es-abstract/2018/UnicodeEscape.js @@ -0,0 +1,26 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var callBound = require('../helpers/callBound'); + +var $charCodeAt = callBound('String.prototype.charCodeAt'); +var $numberToString = callBound('Number.prototype.toString'); +var $toLowerCase = callBound('String.prototype.toLowerCase'); +var $strSlice = callBound('String.prototype.slice'); + +// https://tc39.es/ecma262/2020/#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' + $strSlice('0000' + $toLowerCase($numberToString(n, 16)), -4); +}; -- cgit