UTF16SurrogatePairToCodePoint.js 765 B

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