source: imaps-frontend/node_modules/es-abstract/2017/UTF16Encoding.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: 698 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/7.0/#sec-utf16encoding
14
15module.exports = function UTF16Encoding(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 = floor((cp - 65536) / 1024) + 0xD800;
23 var cu2 = modulo(cp - 65536, 1024) + 0xDC00;
24 return $fromCharCode(cu1) + $fromCharCode(cu2);
25};
Note: See TracBrowser for help on using the repository browser.