1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.encode = encode;
|
---|
7 |
|
---|
8 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
---|
9 |
|
---|
10 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
---|
11 |
|
---|
12 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
---|
13 |
|
---|
14 | function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
---|
15 |
|
---|
16 | function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
---|
17 |
|
---|
18 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
---|
19 |
|
---|
20 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
---|
21 |
|
---|
22 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
---|
23 |
|
---|
24 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
---|
25 |
|
---|
26 | function con(n) {
|
---|
27 | return 0x80 | n & 0x3f;
|
---|
28 | }
|
---|
29 |
|
---|
30 | function encode(str) {
|
---|
31 | var arr = str.split("").map(function (x) {
|
---|
32 | return x.charCodeAt(0);
|
---|
33 | });
|
---|
34 | return _encode(arr);
|
---|
35 | }
|
---|
36 |
|
---|
37 | function _encode(arr) {
|
---|
38 | if (arr.length === 0) {
|
---|
39 | return [];
|
---|
40 | }
|
---|
41 |
|
---|
42 | var _arr = _toArray(arr),
|
---|
43 | n = _arr[0],
|
---|
44 | ns = _arr.slice(1);
|
---|
45 |
|
---|
46 | if (n < 0) {
|
---|
47 | throw new Error("utf8");
|
---|
48 | }
|
---|
49 |
|
---|
50 | if (n < 0x80) {
|
---|
51 | return [n].concat(_toConsumableArray(_encode(ns)));
|
---|
52 | }
|
---|
53 |
|
---|
54 | if (n < 0x800) {
|
---|
55 | return [0xc0 | n >>> 6, con(n)].concat(_toConsumableArray(_encode(ns)));
|
---|
56 | }
|
---|
57 |
|
---|
58 | if (n < 0x10000) {
|
---|
59 | return [0xe0 | n >>> 12, con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
|
---|
60 | }
|
---|
61 |
|
---|
62 | if (n < 0x110000) {
|
---|
63 | return [0xf0 | n >>> 18, con(n >>> 12), con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
|
---|
64 | }
|
---|
65 |
|
---|
66 | throw new Error("utf8");
|
---|
67 | } |
---|