source: imaps-frontend/node_modules/es-abstract/2022/UTF16EncodeCodePoint.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 706 bytes
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = require('es-errors/type');
6var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
7
8var floor = require('./floor');
9var modulo = require('./modulo');
10
11var isCodePoint = require('../helpers/isCodePoint');
12
13// https://262.ecma-international.org/12.0/#sec-utf16encoding
14
15module.exports = function UTF16EncodeCodePoint(cp) {
16 if (!isCodePoint(cp)) {
17 throw new $TypeError('Assertion failed: `cp` must be >= 0 and <= 0x10FFFF');
18 }
19 if (cp <= 65535) {
20 return $fromCharCode(cp);
21 }
22 var cu1 = $fromCharCode(floor((cp - 65536) / 1024) + 0xD800);
23 var cu2 = $fromCharCode(modulo(cp - 65536, 1024) + 0xDC00);
24 return cu1 + cu2;
25};
Note: See TracBrowser for help on using the repository browser.