@alterior/common 3.0.0 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base64.d.ts +4 -15
- package/dist/base64.d.ts.map +1 -1
- package/dist/base64.js +37 -107
- package/dist/base64.js.map +1 -1
- package/dist/base64.test.d.ts +2 -0
- package/dist/base64.test.d.ts.map +1 -0
- package/dist/base64.test.js.map +1 -0
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +15 -7
- package/dist/console.js.map +1 -1
- package/dist.esm/base64.d.ts +4 -15
- package/dist.esm/base64.d.ts.map +1 -1
- package/dist.esm/base64.js +37 -107
- package/dist.esm/base64.js.map +1 -1
- package/dist.esm/base64.test.d.ts +2 -0
- package/dist.esm/base64.test.d.ts.map +1 -0
- package/dist.esm/base64.test.js.map +1 -0
- package/dist.esm/console.d.ts.map +1 -1
- package/dist.esm/console.js +15 -7
- package/dist.esm/console.js.map +1 -1
- package/package.json +2 -2
- package/src/base64.test.ts +28 -0
- package/src/base64.ts +55 -145
- package/src/console.ts +16 -6
package/dist/base64.d.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight base64 encode / decode
|
|
3
|
-
*/
|
|
4
1
|
export declare class Base64 {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
static encode(input: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Decode a base64 encoded string to raw format.
|
|
12
|
-
* @param input The base64 encoded string
|
|
13
|
-
*/
|
|
14
|
-
static decode(input: string): string;
|
|
15
|
-
private static _utf8_encode;
|
|
16
|
-
private static _utf8_decode;
|
|
2
|
+
static encode(str: string): string;
|
|
3
|
+
static encodeBytes(bytes: Uint8Array): string;
|
|
4
|
+
static decode(str: string): string;
|
|
5
|
+
static decodeBytes(str: string): Uint8Array;
|
|
17
6
|
}
|
|
18
7
|
//# sourceMappingURL=base64.d.ts.map
|
package/dist/base64.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAEA,qBAAa,MAAM;IACf,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIlC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IA4B7C,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIlC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;CAqB9C"}
|
package/dist/base64.js
CHANGED
|
@@ -1,121 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Base64 = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @hidden
|
|
6
|
-
*/
|
|
7
4
|
const BASE64_KEY = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
8
|
-
/**
|
|
9
|
-
* Lightweight base64 encode / decode
|
|
10
|
-
*/
|
|
11
5
|
class Base64 {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @param input The string to encode
|
|
15
|
-
*/
|
|
16
|
-
static encode(input) {
|
|
17
|
-
input = input.replace(/ /g, ' ');
|
|
18
|
-
var output = "";
|
|
19
|
-
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
20
|
-
var i = 0;
|
|
21
|
-
input = Base64._utf8_encode(input);
|
|
22
|
-
while (i < input.length) {
|
|
23
|
-
chr1 = input.charCodeAt(i++);
|
|
24
|
-
chr2 = input.charCodeAt(i++);
|
|
25
|
-
chr3 = input.charCodeAt(i++);
|
|
26
|
-
enc1 = chr1 >> 2;
|
|
27
|
-
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
|
28
|
-
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
|
29
|
-
enc4 = chr3 & 63;
|
|
30
|
-
if (isNaN(chr2)) {
|
|
31
|
-
enc3 = enc4 = 64;
|
|
32
|
-
}
|
|
33
|
-
else if (isNaN(chr3)) {
|
|
34
|
-
enc4 = 64;
|
|
35
|
-
}
|
|
36
|
-
output = output +
|
|
37
|
-
BASE64_KEY.charAt(enc1) + BASE64_KEY.charAt(enc2) +
|
|
38
|
-
BASE64_KEY.charAt(enc3) + BASE64_KEY.charAt(enc4);
|
|
39
|
-
}
|
|
40
|
-
return output;
|
|
6
|
+
static encode(str) {
|
|
7
|
+
return this.encodeBytes(new TextEncoder().encode(str));
|
|
41
8
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
60
|
-
output = output + String.fromCharCode(chr1);
|
|
61
|
-
if (enc3 != 64) {
|
|
62
|
-
output = output + String.fromCharCode(chr2);
|
|
63
|
-
}
|
|
64
|
-
if (enc4 != 64) {
|
|
65
|
-
output = output + String.fromCharCode(chr3);
|
|
66
|
-
}
|
|
9
|
+
static encodeBytes(bytes) {
|
|
10
|
+
let output = '';
|
|
11
|
+
let inputPad = 3 - bytes.length % 3;
|
|
12
|
+
let buffer = new Uint8Array(bytes.length + inputPad);
|
|
13
|
+
buffer.set(bytes, 0);
|
|
14
|
+
for (let i = 0, max = buffer.length; i < max; i += 3) {
|
|
15
|
+
let value = buffer[i + 0] << 16
|
|
16
|
+
| buffer[i + 1] << 8
|
|
17
|
+
| buffer[i + 2];
|
|
18
|
+
let char1 = (value >> 18) & 0x3f;
|
|
19
|
+
let char2 = (value >> 12) & 0x3f;
|
|
20
|
+
let char3 = (value >> 6) & 0x3f;
|
|
21
|
+
let char4 = (value >> 0) & 0x3f;
|
|
22
|
+
output += BASE64_KEY[char1];
|
|
23
|
+
output += BASE64_KEY[char2];
|
|
24
|
+
output += BASE64_KEY[char3];
|
|
25
|
+
output += BASE64_KEY[char4];
|
|
67
26
|
}
|
|
68
|
-
|
|
27
|
+
let outputPad = Math.floor(inputPad * 8 / 6);
|
|
28
|
+
output = output.slice(0, -outputPad) + Array(outputPad + 1).join('=');
|
|
69
29
|
return output;
|
|
70
30
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
string = string.replace(/\r\n/g, "\n");
|
|
74
|
-
var utftext = "";
|
|
75
|
-
for (var n = 0; n < string.length; n++) {
|
|
76
|
-
var c = string.charCodeAt(n);
|
|
77
|
-
if (c < 128) {
|
|
78
|
-
utftext += String.fromCharCode(c);
|
|
79
|
-
}
|
|
80
|
-
else if ((c > 127) && (c < 2048)) {
|
|
81
|
-
utftext += String.fromCharCode((c >> 6) | 192);
|
|
82
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
utftext += String.fromCharCode((c >> 12) | 224);
|
|
86
|
-
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
87
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return utftext;
|
|
31
|
+
static decode(str) {
|
|
32
|
+
return new TextDecoder().decode(this.decodeBytes(str));
|
|
91
33
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
else if ((c > 191) && (c < 224)) {
|
|
107
|
-
c2 = utftext.charCodeAt(i + 1);
|
|
108
|
-
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
109
|
-
i += 2;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
c2 = utftext.charCodeAt(i + 1);
|
|
113
|
-
c3 = utftext.charCodeAt(i + 2);
|
|
114
|
-
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
115
|
-
i += 3;
|
|
116
|
-
}
|
|
34
|
+
static decodeBytes(str) {
|
|
35
|
+
str = str.replace(/=+$/g, '');
|
|
36
|
+
let paddingRequired = 4 - str.length % 4;
|
|
37
|
+
str += Array(paddingRequired + 1).join('=');
|
|
38
|
+
let decoded = new Uint8Array(str.length * 6 / 8);
|
|
39
|
+
for (let i = 0, max = str.length; i < max; i += 4) {
|
|
40
|
+
let value = BASE64_KEY.indexOf(str[i + 0]) << 18
|
|
41
|
+
| BASE64_KEY.indexOf(str[i + 1]) << 12
|
|
42
|
+
| BASE64_KEY.indexOf(str[i + 2]) << 6
|
|
43
|
+
| BASE64_KEY.indexOf(str[i + 3]) << 0;
|
|
44
|
+
decoded[i / 4 * 3 + 0] = value >> 16 & 0xFF;
|
|
45
|
+
decoded[i / 4 * 3 + 1] = value >> 8 & 0xFF;
|
|
46
|
+
decoded[i / 4 * 3 + 2] = value >> 0 & 0xFF;
|
|
117
47
|
}
|
|
118
|
-
return
|
|
48
|
+
return decoded.subarray(0, decoded.length - paddingRequired);
|
|
119
49
|
}
|
|
120
50
|
}
|
|
121
51
|
exports.Base64 = Base64;
|
package/dist/base64.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":";;;AAAA,MAAM,UAAU,GAAG,mEAAmE,CAAC;AAEvF,MAAa,MAAM;IACf,MAAM,CAAC,MAAM,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CAAC,IAAI,CAAC,CACpC;YAEL,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,EAAE,GAAG,IAAI,CAAC;YAC5C,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;YAC3C,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;SAC9C;QAED,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,eAAe,CAAC,CAAC;IACjE,CAAC;CACJ;AA1DD,wBA0DC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.test.d.ts","sourceRoot":"","sources":["../src/base64.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.test.js","sourceRoot":"","sources":["../src/base64.test.ts"],"names":[],"mappings":";;AAAA,qCAAkC;AAClC,+BAA8B;AAC9B,mCAAkC;AAElC,IAAA,iBAAQ,EAAC,QAAQ,EAAE,GAAG,EAAE;IACpB,IAAA,iBAAQ,EAAC,WAAW,EAAE,EAAE,CAAC,EAAE;QACvB,EAAE,CAAC,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE;YACtC,IAAA,aAAM,EAAC,eAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAC5C,IAAA,aAAM,EAAC,eAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAClE,IAAA,aAAM,EAAC,eAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,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dist/console.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,OAAO;IACpB,GAAG,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACrB,IAAI,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACtB,IAAI,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACtB,KAAK,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACvB,KAAK,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACvB,GAAG,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;CACxB;
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,OAAO;IACpB,GAAG,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACrB,IAAI,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACtB,IAAI,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACtB,KAAK,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACvB,KAAK,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACvB,GAAG,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;CACxB;AAaD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAG,CAAC,MAAM,EAAG,MAAM,EAAE,YAAY,EAAG,QAAQ,EAAE,OAAO,EAAG,OAAO,EAAE,IAAI,EAAG,GAAG,EAAE,KAAK,IAAI,EAAE,QAAQ,EAAG,QAAQ,QAoBlJ;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAG,MAAM,EAAE,QAAQ,EAAG,QAAQ,QAcjE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAG,CAAC,OAAO,EAAG,MAAM,KAAK,MAAM,EAAE,QAAQ,EAAG,QAAQ,QAa1F"}
|
package/dist/console.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatConsole = exports.indentConsole = exports.interceptConsole = void 0;
|
|
4
|
+
function safeRequire(name) {
|
|
5
|
+
if (typeof require === 'undefined')
|
|
6
|
+
return undefined;
|
|
7
|
+
try {
|
|
8
|
+
return require(name);
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
4
14
|
/**
|
|
5
15
|
* Intercept console messages emitted within the given function, allowing you to programmatically call the underlying raw console implementation (or not).
|
|
6
16
|
*
|
|
@@ -38,13 +48,11 @@ function indentConsole(spaces, callback) {
|
|
|
38
48
|
let indent = Array(spaces).join(' ');
|
|
39
49
|
return interceptConsole((method, original, console, args) => {
|
|
40
50
|
if (method == 'dir') {
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
const util = safeRequire('util');
|
|
52
|
+
if (util)
|
|
43
53
|
console.log(`${indent}${util.inspect(args[0])}`);
|
|
44
|
-
|
|
45
|
-
else {
|
|
54
|
+
else
|
|
46
55
|
original(...args);
|
|
47
|
-
}
|
|
48
56
|
}
|
|
49
57
|
else {
|
|
50
58
|
original(`${indent}${args.join(' ')}`);
|
|
@@ -62,8 +70,8 @@ exports.indentConsole = indentConsole;
|
|
|
62
70
|
function formatConsole(formatter, callback) {
|
|
63
71
|
return interceptConsole((method, original, console, args) => {
|
|
64
72
|
if (method == 'dir') {
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
const util = safeRequire('util');
|
|
74
|
+
if (util) {
|
|
67
75
|
console.log(`${formatter(util.inspect(args[0]))}`);
|
|
68
76
|
}
|
|
69
77
|
else {
|
package/dist/console.js.map
CHANGED
|
@@ -1 +1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
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight base64 encode / decode
|
|
3
|
-
*/
|
|
4
1
|
export declare class Base64 {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
static encode(input: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Decode a base64 encoded string to raw format.
|
|
12
|
-
* @param input The base64 encoded string
|
|
13
|
-
*/
|
|
14
|
-
static decode(input: string): string;
|
|
15
|
-
private static _utf8_encode;
|
|
16
|
-
private static _utf8_decode;
|
|
2
|
+
static encode(str: string): string;
|
|
3
|
+
static encodeBytes(bytes: Uint8Array): string;
|
|
4
|
+
static decode(str: string): string;
|
|
5
|
+
static decodeBytes(str: string): Uint8Array;
|
|
17
6
|
}
|
|
18
7
|
//# sourceMappingURL=base64.d.ts.map
|
package/dist.esm/base64.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAEA,qBAAa,MAAM;IACf,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIlC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IA4B7C,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIlC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;CAqB9C"}
|
package/dist.esm/base64.js
CHANGED
|
@@ -1,118 +1,48 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @hidden
|
|
3
|
-
*/
|
|
4
1
|
const BASE64_KEY = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
5
|
-
/**
|
|
6
|
-
* Lightweight base64 encode / decode
|
|
7
|
-
*/
|
|
8
2
|
export class Base64 {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @param input The string to encode
|
|
12
|
-
*/
|
|
13
|
-
static encode(input) {
|
|
14
|
-
input = input.replace(/ /g, ' ');
|
|
15
|
-
var output = "";
|
|
16
|
-
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
17
|
-
var i = 0;
|
|
18
|
-
input = Base64._utf8_encode(input);
|
|
19
|
-
while (i < input.length) {
|
|
20
|
-
chr1 = input.charCodeAt(i++);
|
|
21
|
-
chr2 = input.charCodeAt(i++);
|
|
22
|
-
chr3 = input.charCodeAt(i++);
|
|
23
|
-
enc1 = chr1 >> 2;
|
|
24
|
-
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
|
25
|
-
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
|
26
|
-
enc4 = chr3 & 63;
|
|
27
|
-
if (isNaN(chr2)) {
|
|
28
|
-
enc3 = enc4 = 64;
|
|
29
|
-
}
|
|
30
|
-
else if (isNaN(chr3)) {
|
|
31
|
-
enc4 = 64;
|
|
32
|
-
}
|
|
33
|
-
output = output +
|
|
34
|
-
BASE64_KEY.charAt(enc1) + BASE64_KEY.charAt(enc2) +
|
|
35
|
-
BASE64_KEY.charAt(enc3) + BASE64_KEY.charAt(enc4);
|
|
36
|
-
}
|
|
37
|
-
return output;
|
|
3
|
+
static encode(str) {
|
|
4
|
+
return this.encodeBytes(new TextEncoder().encode(str));
|
|
38
5
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
57
|
-
output = output + String.fromCharCode(chr1);
|
|
58
|
-
if (enc3 != 64) {
|
|
59
|
-
output = output + String.fromCharCode(chr2);
|
|
60
|
-
}
|
|
61
|
-
if (enc4 != 64) {
|
|
62
|
-
output = output + String.fromCharCode(chr3);
|
|
63
|
-
}
|
|
6
|
+
static encodeBytes(bytes) {
|
|
7
|
+
let output = '';
|
|
8
|
+
let inputPad = 3 - bytes.length % 3;
|
|
9
|
+
let buffer = new Uint8Array(bytes.length + inputPad);
|
|
10
|
+
buffer.set(bytes, 0);
|
|
11
|
+
for (let i = 0, max = buffer.length; i < max; i += 3) {
|
|
12
|
+
let value = buffer[i + 0] << 16
|
|
13
|
+
| buffer[i + 1] << 8
|
|
14
|
+
| buffer[i + 2];
|
|
15
|
+
let char1 = (value >> 18) & 0x3f;
|
|
16
|
+
let char2 = (value >> 12) & 0x3f;
|
|
17
|
+
let char3 = (value >> 6) & 0x3f;
|
|
18
|
+
let char4 = (value >> 0) & 0x3f;
|
|
19
|
+
output += BASE64_KEY[char1];
|
|
20
|
+
output += BASE64_KEY[char2];
|
|
21
|
+
output += BASE64_KEY[char3];
|
|
22
|
+
output += BASE64_KEY[char4];
|
|
64
23
|
}
|
|
65
|
-
|
|
24
|
+
let outputPad = Math.floor(inputPad * 8 / 6);
|
|
25
|
+
output = output.slice(0, -outputPad) + Array(outputPad + 1).join('=');
|
|
66
26
|
return output;
|
|
67
27
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
string = string.replace(/\r\n/g, "\n");
|
|
71
|
-
var utftext = "";
|
|
72
|
-
for (var n = 0; n < string.length; n++) {
|
|
73
|
-
var c = string.charCodeAt(n);
|
|
74
|
-
if (c < 128) {
|
|
75
|
-
utftext += String.fromCharCode(c);
|
|
76
|
-
}
|
|
77
|
-
else if ((c > 127) && (c < 2048)) {
|
|
78
|
-
utftext += String.fromCharCode((c >> 6) | 192);
|
|
79
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
utftext += String.fromCharCode((c >> 12) | 224);
|
|
83
|
-
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
84
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return utftext;
|
|
28
|
+
static decode(str) {
|
|
29
|
+
return new TextDecoder().decode(this.decodeBytes(str));
|
|
88
30
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
else if ((c > 191) && (c < 224)) {
|
|
104
|
-
c2 = utftext.charCodeAt(i + 1);
|
|
105
|
-
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
106
|
-
i += 2;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
c2 = utftext.charCodeAt(i + 1);
|
|
110
|
-
c3 = utftext.charCodeAt(i + 2);
|
|
111
|
-
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
112
|
-
i += 3;
|
|
113
|
-
}
|
|
31
|
+
static decodeBytes(str) {
|
|
32
|
+
str = str.replace(/=+$/g, '');
|
|
33
|
+
let paddingRequired = 4 - str.length % 4;
|
|
34
|
+
str += Array(paddingRequired + 1).join('=');
|
|
35
|
+
let decoded = new Uint8Array(str.length * 6 / 8);
|
|
36
|
+
for (let i = 0, max = str.length; i < max; i += 4) {
|
|
37
|
+
let value = BASE64_KEY.indexOf(str[i + 0]) << 18
|
|
38
|
+
| BASE64_KEY.indexOf(str[i + 1]) << 12
|
|
39
|
+
| BASE64_KEY.indexOf(str[i + 2]) << 6
|
|
40
|
+
| BASE64_KEY.indexOf(str[i + 3]) << 0;
|
|
41
|
+
decoded[i / 4 * 3 + 0] = value >> 16 & 0xFF;
|
|
42
|
+
decoded[i / 4 * 3 + 1] = value >> 8 & 0xFF;
|
|
43
|
+
decoded[i / 4 * 3 + 2] = value >> 0 & 0xFF;
|
|
114
44
|
}
|
|
115
|
-
return
|
|
45
|
+
return decoded.subarray(0, decoded.length - paddingRequired);
|
|
116
46
|
}
|
|
117
47
|
}
|
|
118
48
|
//# sourceMappingURL=base64.js.map
|
package/dist.esm/base64.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,mEAAmE,CAAC;AAEvF,MAAM,OAAO,MAAM;IACf,MAAM,CAAC,MAAM,CAAC,GAAW;QACrB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,KAAiB;QAChC,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACpC,IAAI,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;QACrD,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAErB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE;YAClD,IAAI,KAAK,GACL,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;kBACjB,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;kBAClB,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CACd;YACL,IAAI,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;YACjC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GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE;YAC/C,IAAI,KAAK,GACL,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE;kBAClC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE;kBACpC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;kBACnC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CACpC;YAEL,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,EAAE,GAAG,IAAI,CAAC;YAC5C,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;YAC3C,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;SAC9C;QAED,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,eAAe,CAAC,CAAC;IACjE,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.test.d.ts","sourceRoot":"","sources":["../src/base64.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.test.js","sourceRoot":"","sources":["../src/base64.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE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C,4BAA4B,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACxF,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE;YACtC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACnD,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,OAAO;IACpB,GAAG,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACrB,IAAI,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACtB,IAAI,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACtB,KAAK,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACvB,KAAK,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACvB,GAAG,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;CACxB;
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,OAAO;IACpB,GAAG,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACrB,IAAI,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACtB,IAAI,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACtB,KAAK,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACvB,KAAK,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;IACvB,GAAG,CAAC,GAAG,IAAI,EAAG,GAAG,EAAE,OAAE;CACxB;AAaD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAG,CAAC,MAAM,EAAG,MAAM,EAAE,YAAY,EAAG,QAAQ,EAAE,OAAO,EAAG,OAAO,EAAE,IAAI,EAAG,GAAG,EAAE,KAAK,IAAI,EAAE,QAAQ,EAAG,QAAQ,QAoBlJ;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAG,MAAM,EAAE,QAAQ,EAAG,QAAQ,QAcjE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAG,CAAC,OAAO,EAAG,MAAM,KAAK,MAAM,EAAE,QAAQ,EAAG,QAAQ,QAa1F"}
|
package/dist.esm/console.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
function safeRequire(name) {
|
|
2
|
+
if (typeof require === 'undefined')
|
|
3
|
+
return undefined;
|
|
4
|
+
try {
|
|
5
|
+
return require(name);
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* Intercept console messages emitted within the given function, allowing you to programmatically call the underlying raw console implementation (or not).
|
|
3
13
|
*
|
|
@@ -34,13 +44,11 @@ export function indentConsole(spaces, callback) {
|
|
|
34
44
|
let indent = Array(spaces).join(' ');
|
|
35
45
|
return interceptConsole((method, original, console, args) => {
|
|
36
46
|
if (method == 'dir') {
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
const util = safeRequire('util');
|
|
48
|
+
if (util)
|
|
39
49
|
console.log(`${indent}${util.inspect(args[0])}`);
|
|
40
|
-
|
|
41
|
-
else {
|
|
50
|
+
else
|
|
42
51
|
original(...args);
|
|
43
|
-
}
|
|
44
52
|
}
|
|
45
53
|
else {
|
|
46
54
|
original(`${indent}${args.join(' ')}`);
|
|
@@ -57,8 +65,8 @@ export function indentConsole(spaces, callback) {
|
|
|
57
65
|
export function formatConsole(formatter, callback) {
|
|
58
66
|
return interceptConsole((method, original, console, args) => {
|
|
59
67
|
if (method == 'dir') {
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
const util = safeRequire('util');
|
|
69
|
+
if (util) {
|
|
62
70
|
console.log(`${formatter(util.inspect(args[0]))}`);
|
|
63
71
|
}
|
|
64
72
|
else {
|
package/dist.esm/console.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.js","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA6F,EAAE,QAAmB;IAC/I,IAAI,OAAO,GAAG,CAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAE,CAAC;IAEjE,IAAI,UAAU,GAAa,EAAS,CAAC;IACrC,IAAI,WAAW,GAAG,EAAE,CAAC;IAErB,KAAK,IAAI,MAAM,IAAI,OAAO,EAAE;QACxB,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACtC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpE,OAAO,CAAC,MAAM,CAAC,GAAG;YACd,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QAC3E,CAAC,CAAC;KACL;IAED,IAAI;QACA,QAAQ,EAAE,CAAC;KACd;YAAS;QACN,KAAK,IAAI,MAAM,IAAI,OAAO;YACtB,OAAO,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;KAC7C;AACL,CAA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CAAA;aACrD;iBAAM;gBACH,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;aACrB;SACJ;aAAM;YACH,QAAQ,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;SAC5C;IACL,CAAC,EAAE,QAAQ,CAAC,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alterior/common",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "Useful utilities for Typescript apps",
|
|
5
5
|
"author": "The Alterior Project (https://github.com/alterior-mvc)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"typescript": "^4.1.5",
|
|
53
53
|
"zone.js": "^0.11.4"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "32ef41f96bfc52dfcc8bc56f29bf3a3ce842a4eb"
|
|
56
56
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Base64 } from "./base64";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { describe } from "razmin";
|
|
4
|
+
|
|
5
|
+
describe('Base64', () => {
|
|
6
|
+
describe('.encode()', it => {
|
|
7
|
+
it.only('encodes ASCII as expected', () => {
|
|
8
|
+
expect(Base64.encode('A')).to.equal('QQ==');
|
|
9
|
+
expect(Base64.encode('hello world')).to.equal('aGVsbG8gd29ybGQ=');
|
|
10
|
+
expect(Base64.encode('hello 123 $ _ / @ -')).to.equal('aGVsbG8gMTIzICQgXyAvIEAgLQ==');
|
|
11
|
+
});
|
|
12
|
+
it.only('encodes UTF-8 as expected', () => {
|
|
13
|
+
expect(Base64.encode('🚀')).to.equal('8J+agA==');
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
describe('.decode()', it => {
|
|
17
|
+
it.only('decodes ASCII as expected', () => {
|
|
18
|
+
expect(Base64.decode('aGVsbG8gd29ybGQ=')).to.equal('hello world');
|
|
19
|
+
expect(Base64.decode('aGVsbG8gd29ybGQ')).to.equal('hello world');
|
|
20
|
+
expect(Base64.decode('aGVsbG8gMTIzICQgXyAvIEAgLQ==')).to.equal('hello 123 $ _ / @ -');
|
|
21
|
+
expect(Base64.decode('aGVsbG8gMTIzICQgXyAvIEAgLQ')).to.equal('hello 123 $ _ / @ -');
|
|
22
|
+
});
|
|
23
|
+
it.only('decodes UTF-8 as expected', () => {
|
|
24
|
+
expect(Base64.decode('8J+agA==')).to.equal('🚀');
|
|
25
|
+
expect(Base64.decode('8J+agA')).to.equal('🚀');
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
})
|
package/src/base64.ts
CHANGED
|
@@ -1,151 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @hidden
|
|
4
|
-
*/
|
|
5
1
|
const BASE64_KEY = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
6
2
|
|
|
7
|
-
/**
|
|
8
|
-
* Lightweight base64 encode / decode
|
|
9
|
-
*/
|
|
10
3
|
export class Base64 {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
static encode(str: string): string {
|
|
5
|
+
return this.encodeBytes(new TextEncoder().encode(str));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static encodeBytes(bytes: Uint8Array): string {
|
|
9
|
+
let output = '';
|
|
10
|
+
let inputPad = 3 - bytes.length % 3;
|
|
11
|
+
let buffer = new Uint8Array(bytes.length + inputPad);
|
|
12
|
+
buffer.set(bytes, 0);
|
|
13
|
+
|
|
14
|
+
for (let i = 0, max = buffer.length; i < max; i += 3) {
|
|
15
|
+
let value =
|
|
16
|
+
buffer[i + 0] << 16
|
|
17
|
+
| buffer[i + 1] << 8
|
|
18
|
+
| buffer[i + 2]
|
|
19
|
+
;
|
|
20
|
+
let char1 = (value >> 18) & 0x3f;
|
|
21
|
+
let char2 = (value >> 12) & 0x3f;
|
|
22
|
+
let char3 = (value >> 6) & 0x3f;
|
|
23
|
+
let char4 = (value >> 0) & 0x3f;
|
|
24
|
+
|
|
25
|
+
output += BASE64_KEY[char1];
|
|
26
|
+
output += BASE64_KEY[char2];
|
|
27
|
+
output += BASE64_KEY[char3];
|
|
28
|
+
output += BASE64_KEY[char4];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let outputPad = Math.floor(inputPad * 8 / 6);
|
|
32
|
+
output = output.slice(0, -outputPad) + Array(outputPad + 1).join('=');
|
|
33
|
+
return output;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static decode(str: string): string {
|
|
37
|
+
return new TextDecoder().decode(this.decodeBytes(str));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static decodeBytes(str: string): Uint8Array {
|
|
41
|
+
str = str.replace(/=+$/g, '');
|
|
42
|
+
let paddingRequired = 4 - str.length % 4;
|
|
43
|
+
str += Array(paddingRequired + 1).join('=');
|
|
16
44
|
|
|
17
|
-
|
|
45
|
+
let decoded = new Uint8Array(str.length * 6 / 8);
|
|
46
|
+
for (let i = 0, max = str.length; i < max; i += 4) {
|
|
47
|
+
let value =
|
|
48
|
+
BASE64_KEY.indexOf(str[i + 0]) << 18
|
|
49
|
+
| BASE64_KEY.indexOf(str[i + 1]) << 12
|
|
50
|
+
| BASE64_KEY.indexOf(str[i + 2]) << 6
|
|
51
|
+
| BASE64_KEY.indexOf(str[i + 3]) << 0
|
|
52
|
+
;
|
|
18
53
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
input = Base64._utf8_encode(input);
|
|
24
|
-
|
|
25
|
-
while (i < input.length) {
|
|
26
|
-
|
|
27
|
-
chr1 = input.charCodeAt(i++);
|
|
28
|
-
chr2 = input.charCodeAt(i++);
|
|
29
|
-
chr3 = input.charCodeAt(i++);
|
|
30
|
-
|
|
31
|
-
enc1 = chr1 >> 2;
|
|
32
|
-
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
|
33
|
-
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
|
34
|
-
enc4 = chr3 & 63;
|
|
35
|
-
|
|
36
|
-
if (isNaN(chr2)) {
|
|
37
|
-
enc3 = enc4 = 64;
|
|
38
|
-
} else if (isNaN(chr3)) {
|
|
39
|
-
enc4 = 64;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
output = output +
|
|
43
|
-
BASE64_KEY.charAt(enc1) + BASE64_KEY.charAt(enc2) +
|
|
44
|
-
BASE64_KEY.charAt(enc3) + BASE64_KEY.charAt(enc4);
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return output;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Decode a base64 encoded string to raw format.
|
|
53
|
-
* @param input The base64 encoded string
|
|
54
|
-
*/
|
|
55
|
-
public static decode(input : string): string {
|
|
56
|
-
var output = "";
|
|
57
|
-
var chr1, chr2, chr3;
|
|
58
|
-
var enc1, enc2, enc3, enc4;
|
|
59
|
-
var i = 0;
|
|
60
|
-
|
|
61
|
-
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
|
62
|
-
|
|
63
|
-
while (i < input.length) {
|
|
64
|
-
|
|
65
|
-
enc1 = BASE64_KEY.indexOf(input.charAt(i++));
|
|
66
|
-
enc2 = BASE64_KEY.indexOf(input.charAt(i++));
|
|
67
|
-
enc3 = BASE64_KEY.indexOf(input.charAt(i++));
|
|
68
|
-
enc4 = BASE64_KEY.indexOf(input.charAt(i++));
|
|
69
|
-
|
|
70
|
-
chr1 = (enc1 << 2) | (enc2 >> 4);
|
|
71
|
-
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
|
72
|
-
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
73
|
-
|
|
74
|
-
output = output + String.fromCharCode(chr1);
|
|
75
|
-
|
|
76
|
-
if (enc3 != 64) {
|
|
77
|
-
output = output + String.fromCharCode(chr2);
|
|
78
|
-
}
|
|
79
|
-
if (enc4 != 64) {
|
|
80
|
-
output = output + String.fromCharCode(chr3);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
output = Base64._utf8_decode(output);
|
|
86
|
-
|
|
87
|
-
return output;
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// private method for UTF-8 encoding
|
|
92
|
-
private static _utf8_encode(string) {
|
|
93
|
-
string = string.replace(/\r\n/g,"\n");
|
|
94
|
-
var utftext = "";
|
|
95
|
-
|
|
96
|
-
for (var n = 0; n < string.length; n++) {
|
|
97
|
-
|
|
98
|
-
var c = string.charCodeAt(n);
|
|
99
|
-
|
|
100
|
-
if (c < 128) {
|
|
101
|
-
utftext += String.fromCharCode(c);
|
|
102
|
-
}
|
|
103
|
-
else if((c > 127) && (c < 2048)) {
|
|
104
|
-
utftext += String.fromCharCode((c >> 6) | 192);
|
|
105
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
utftext += String.fromCharCode((c >> 12) | 224);
|
|
109
|
-
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
110
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return utftext;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// private method for UTF-8 decoding
|
|
119
|
-
private static _utf8_decode(utftext) {
|
|
120
|
-
var string = "";
|
|
121
|
-
var i = 0;
|
|
122
|
-
var c = 0;
|
|
123
|
-
var c1 = 0;
|
|
124
|
-
var c2 = 0;
|
|
125
|
-
var c3 = 0;
|
|
54
|
+
decoded[i / 4 * 3 + 0] = value >> 16 & 0xFF;
|
|
55
|
+
decoded[i / 4 * 3 + 1] = value >> 8 & 0xFF;
|
|
56
|
+
decoded[i / 4 * 3 + 2] = value >> 0 & 0xFF;
|
|
57
|
+
}
|
|
126
58
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (c < 128) {
|
|
132
|
-
string += String.fromCharCode(c);
|
|
133
|
-
i++;
|
|
134
|
-
}
|
|
135
|
-
else if((c > 191) && (c < 224)) {
|
|
136
|
-
c2 = utftext.charCodeAt(i+1);
|
|
137
|
-
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
138
|
-
i += 2;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
c2 = utftext.charCodeAt(i+1);
|
|
142
|
-
c3 = utftext.charCodeAt(i+2);
|
|
143
|
-
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
144
|
-
i += 3;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return string;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
59
|
+
return decoded.subarray(0, decoded.length - paddingRequired);
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/console.ts
CHANGED
|
@@ -8,6 +8,17 @@ export interface Console {
|
|
|
8
8
|
dir(...args : any[]);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
function safeRequire(name : string) {
|
|
12
|
+
if (typeof require === 'undefined')
|
|
13
|
+
return undefined;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
return require(name);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
11
22
|
/**
|
|
12
23
|
* Intercept console messages emitted within the given function, allowing you to programmatically call the underlying raw console implementation (or not).
|
|
13
24
|
*
|
|
@@ -48,12 +59,11 @@ export function indentConsole(spaces : number, callback : Function) {
|
|
|
48
59
|
|
|
49
60
|
return interceptConsole((method, original, console, args) => {
|
|
50
61
|
if (method == 'dir') {
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
const util = safeRequire('util');
|
|
63
|
+
if (util)
|
|
53
64
|
console.log(`${indent}${util.inspect(args[0])}`)
|
|
54
|
-
|
|
65
|
+
else
|
|
55
66
|
original(...args);
|
|
56
|
-
}
|
|
57
67
|
} else {
|
|
58
68
|
original(`${indent}${args.join(' ')}`);
|
|
59
69
|
}
|
|
@@ -70,8 +80,8 @@ export function indentConsole(spaces : number, callback : Function) {
|
|
|
70
80
|
export function formatConsole(formatter : (message : string) => string, callback : Function) {
|
|
71
81
|
return interceptConsole((method, original, console, args) => {
|
|
72
82
|
if (method == 'dir') {
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
const util = safeRequire('util');
|
|
84
|
+
if (util) {
|
|
75
85
|
console.log(`${formatter(util.inspect(args[0]))}`)
|
|
76
86
|
} else {
|
|
77
87
|
original(...args);
|