1 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
---|
2 |
|
---|
3 | 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."); }
|
---|
4 |
|
---|
5 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
---|
6 |
|
---|
7 | function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
---|
8 |
|
---|
9 | 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."); }
|
---|
10 |
|
---|
11 | 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); }
|
---|
12 |
|
---|
13 | 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; }
|
---|
14 |
|
---|
15 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
---|
16 |
|
---|
17 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
---|
18 |
|
---|
19 | function con(n) {
|
---|
20 | return 0x80 | n & 0x3f;
|
---|
21 | }
|
---|
22 |
|
---|
23 | export function encode(str) {
|
---|
24 | var arr = str.split("").map(function (x) {
|
---|
25 | return x.charCodeAt(0);
|
---|
26 | });
|
---|
27 | return _encode(arr);
|
---|
28 | }
|
---|
29 |
|
---|
30 | function _encode(arr) {
|
---|
31 | if (arr.length === 0) {
|
---|
32 | return [];
|
---|
33 | }
|
---|
34 |
|
---|
35 | var _arr = _toArray(arr),
|
---|
36 | n = _arr[0],
|
---|
37 | ns = _arr.slice(1);
|
---|
38 |
|
---|
39 | if (n < 0) {
|
---|
40 | throw new Error("utf8");
|
---|
41 | }
|
---|
42 |
|
---|
43 | if (n < 0x80) {
|
---|
44 | return [n].concat(_toConsumableArray(_encode(ns)));
|
---|
45 | }
|
---|
46 |
|
---|
47 | if (n < 0x800) {
|
---|
48 | return [0xc0 | n >>> 6, con(n)].concat(_toConsumableArray(_encode(ns)));
|
---|
49 | }
|
---|
50 |
|
---|
51 | if (n < 0x10000) {
|
---|
52 | return [0xe0 | n >>> 12, con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
|
---|
53 | }
|
---|
54 |
|
---|
55 | if (n < 0x110000) {
|
---|
56 | return [0xf0 | n >>> 18, con(n >>> 12), con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
|
---|
57 | }
|
---|
58 |
|
---|
59 | throw new Error("utf8");
|
---|
60 | } |
---|