main
Last change
on this file since d565449 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 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 |
|
---|
5 | var $TypeError = require('es-errors/type');
|
---|
6 | var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
|
---|
7 |
|
---|
8 | var floor = require('./floor');
|
---|
9 | var modulo = require('./modulo');
|
---|
10 |
|
---|
11 | var isCodePoint = require('../helpers/isCodePoint');
|
---|
12 |
|
---|
13 | // https://262.ecma-international.org/7.0/#sec-utf16encoding
|
---|
14 |
|
---|
15 | module.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.