source: trip-planner-front/node_modules/@webassemblyjs/utf8/lib/encoder.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.encode = encode;
7
8function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
9
10function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
11
12function con(n) {
13 return 0x80 | n & 0x3f;
14}
15
16function encode(str) {
17 var arr = str.split("").map(function (x) {
18 return x.charCodeAt(0);
19 });
20 return _encode(arr);
21}
22
23function _encode(arr) {
24 if (arr.length === 0) {
25 return [];
26 }
27
28 var _arr = _toArray(arr),
29 n = _arr[0],
30 ns = _arr.slice(1);
31
32 if (n < 0) {
33 throw new Error("utf8");
34 }
35
36 if (n < 0x80) {
37 return [n].concat(_toConsumableArray(_encode(ns)));
38 }
39
40 if (n < 0x800) {
41 return [0xc0 | n >>> 6, con(n)].concat(_toConsumableArray(_encode(ns)));
42 }
43
44 if (n < 0x10000) {
45 return [0xe0 | n >>> 12, con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
46 }
47
48 if (n < 0x110000) {
49 return [0xf0 | n >>> 18, con(n >>> 12), con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
50 }
51
52 throw new Error("utf8");
53}
Note: See TracBrowser for help on using the repository browser.