web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
839 B

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