- Complete React app with 7 developer tools - JSON Tool with visual structured editor - Serialize Tool with visual structured editor - URL, Base64, CSV/JSON, Beautifier, Diff tools - Responsive navigation with dropdown menu - Dark/light mode toggle - Mobile-responsive design with sticky header - All tools working with copy/paste functionality
26 lines
698 B
JavaScript
26 lines
698 B
JavaScript
'use strict';
|
|
|
|
var GetIntrinsic = require('get-intrinsic');
|
|
|
|
var $TypeError = require('es-errors/type');
|
|
var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
|
|
|
|
var floor = require('./floor');
|
|
var modulo = require('./modulo');
|
|
|
|
var isCodePoint = require('../helpers/isCodePoint');
|
|
|
|
// https://262.ecma-international.org/7.0/#sec-utf16encoding
|
|
|
|
module.exports = function UTF16Encoding(cp) {
|
|
if (!isCodePoint(cp)) {
|
|
throw new $TypeError('Assertion failed: `cp` must be >= 0 and <= 0x10FFFF');
|
|
}
|
|
if (cp <= 65535) {
|
|
return $fromCharCode(cp);
|
|
}
|
|
var cu1 = $fromCharCode(floor((cp - 65536) / 1024) + 0xD800);
|
|
var cu2 = $fromCharCode(modulo(cp - 65536, 1024) + 0xDC00);
|
|
return cu1 + cu2;
|
|
};
|