UTF16Decode.js 821 B

123456789101112131415161718192021
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = require('es-errors/type');
  4. var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
  5. // https://262.ecma-international.org/7.0/#sec-utf16decode
  6. var isLeadingSurrogate = require('../helpers/isLeadingSurrogate');
  7. var isTrailingSurrogate = require('../helpers/isTrailingSurrogate');
  8. // https://262.ecma-international.org/11.0/#sec-utf16decodesurrogatepair
  9. module.exports = function UTF16Decode(lead, trail) {
  10. if (!isLeadingSurrogate(lead) || !isTrailingSurrogate(trail)) {
  11. throw new $TypeError('Assertion failed: `lead` must be a leading surrogate char code, and `trail` must be a trailing surrogate char code');
  12. }
  13. // var cp = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  14. return $fromCharCode(lead) + $fromCharCode(trail);
  15. };