toilscript 0.0.1 → 0.1.0
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/LICENSE +201 -201
- package/NOTICE +94 -94
- package/README.md +101 -114
- package/bin/asc.js +0 -0
- package/bin/asinit.js +0 -0
- package/dist/asc.generated.d.ts +10022 -0
- package/dist/asc.js +24457 -0
- package/dist/asc.js.map +7 -0
- package/dist/importmap.json +9 -0
- package/dist/toilscript.generated.d.ts +11237 -0
- package/dist/toilscript.js +337 -0
- package/dist/toilscript.js.map +7 -0
- package/dist/web.js +22 -0
- package/lib/binaryen.d.ts +2 -2
- package/lib/binaryen.js +2 -2
- package/package.json +115 -114
- package/std/README.md +6 -6
- package/std/assembly/array.ts +550 -550
- package/std/assembly/arraybuffer.ts +77 -77
- package/std/assembly/atomics.ts +127 -127
- package/std/assembly/bindings/asyncify.ts +16 -16
- package/std/assembly/bindings/dom.ts +291 -291
- package/std/assembly/bindings/node.ts +6 -6
- package/std/assembly/bitflags.ts +53 -53
- package/std/assembly/builtins.ts +2650 -2650
- package/std/assembly/byteslice.ts +177 -177
- package/std/assembly/compat.ts +2 -2
- package/std/assembly/console.ts +42 -42
- package/std/assembly/crypto.ts +9 -9
- package/std/assembly/dataview.ts +181 -181
- package/std/assembly/date.ts +375 -375
- package/std/assembly/diagnostics.ts +11 -11
- package/std/assembly/encoding.ts +151 -151
- package/std/assembly/endian.ts +45 -45
- package/std/assembly/error.ts +44 -44
- package/std/assembly/fixedarray.ts +173 -173
- package/std/assembly/fixedmap.ts +326 -326
- package/std/assembly/fixedset.ts +275 -275
- package/std/assembly/function.ts +42 -42
- package/std/assembly/index.d.ts +2891 -2891
- package/std/assembly/iterator.ts +35 -35
- package/std/assembly/map.ts +269 -269
- package/std/assembly/math.ts +3289 -3289
- package/std/assembly/memory.ts +123 -123
- package/std/assembly/number.ts +388 -388
- package/std/assembly/object.ts +36 -36
- package/std/assembly/performance.ts +9 -9
- package/std/assembly/pointer.ts +80 -80
- package/std/assembly/polyfills.ts +27 -27
- package/std/assembly/process.ts +50 -50
- package/std/assembly/reference.ts +48 -48
- package/std/assembly/regexp.ts +12 -12
- package/std/assembly/rt/README.md +83 -83
- package/std/assembly/rt/common.ts +81 -81
- package/std/assembly/rt/index-incremental.ts +2 -2
- package/std/assembly/rt/index-memory.ts +1 -1
- package/std/assembly/rt/index-minimal.ts +2 -2
- package/std/assembly/rt/index-stub.ts +1 -1
- package/std/assembly/rt/index.d.ts +37 -37
- package/std/assembly/rt/itcms.ts +419 -419
- package/std/assembly/rt/memory-runtime.ts +94 -94
- package/std/assembly/rt/rtrace.ts +15 -15
- package/std/assembly/rt/stub.ts +133 -133
- package/std/assembly/rt/tcms.ts +254 -254
- package/std/assembly/rt/tlsf.ts +592 -592
- package/std/assembly/rt.ts +90 -90
- package/std/assembly/set.ts +225 -225
- package/std/assembly/shared/feature.ts +68 -68
- package/std/assembly/shared/runtime.ts +13 -13
- package/std/assembly/shared/target.ts +11 -11
- package/std/assembly/shared/tsconfig.json +11 -11
- package/std/assembly/shared/typeinfo.ts +72 -72
- package/std/assembly/staticarray.ts +423 -423
- package/std/assembly/string.ts +850 -850
- package/std/assembly/symbol.ts +114 -114
- package/std/assembly/table.ts +16 -16
- package/std/assembly/tsconfig.json +6 -6
- package/std/assembly/typedarray.ts +1954 -1954
- package/std/assembly/uri.ts +17 -17
- package/std/assembly/util/bytes.ts +107 -107
- package/std/assembly/util/casemap.ts +497 -497
- package/std/assembly/util/error.ts +58 -58
- package/std/assembly/util/hash.ts +117 -117
- package/std/assembly/util/math.ts +1922 -1922
- package/std/assembly/util/memory.ts +290 -290
- package/std/assembly/util/number.ts +873 -873
- package/std/assembly/util/sort.ts +313 -313
- package/std/assembly/util/string.ts +1202 -1202
- package/std/assembly/util/uri.ts +275 -275
- package/std/assembly/vector.ts +4 -4
- package/std/assembly.json +16 -16
- package/std/portable/index.d.ts +461 -461
- package/std/portable/index.js +416 -416
- package/std/portable.json +11 -11
- package/std/types/assembly/index.d.ts +1 -1
- package/std/types/assembly/package.json +2 -2
- package/std/types/portable/index.d.ts +1 -1
- package/std/types/portable/package.json +2 -2
- package/tsconfig-base.json +13 -13
- package/util/README.md +23 -23
- package/util/browser/fs.js +1 -1
- package/util/browser/module.js +5 -5
- package/util/browser/path.js +520 -520
- package/util/browser/process.js +59 -59
- package/util/browser/url.js +23 -23
- package/util/cpu.d.ts +9 -9
- package/util/cpu.js +42 -42
- package/util/find.d.ts +6 -6
- package/util/find.js +20 -20
- package/util/node.d.ts +21 -21
- package/util/node.js +34 -34
- package/util/options.d.ts +70 -70
- package/util/options.js +262 -262
- package/util/terminal.d.ts +52 -52
- package/util/terminal.js +35 -35
- package/util/text.d.ts +26 -26
- package/util/text.js +114 -114
- package/util/tsconfig.json +9 -9
- package/util/web.d.ts +11 -11
- package/util/web.js +33 -33
package/util/terminal.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Terminal utility.
|
|
3
|
-
* @license Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
var proc = typeof process !== "undefined" && process || {};
|
|
7
|
-
var isCI = proc.env && "CI" in proc.env;
|
|
8
|
-
|
|
9
|
-
export const GRAY = "\u001b[90m";
|
|
10
|
-
export const RED = "\u001b[91m";
|
|
11
|
-
export const GREEN = "\u001b[92m";
|
|
12
|
-
export const YELLOW = "\u001b[93m";
|
|
13
|
-
export const BLUE = "\u001b[94m";
|
|
14
|
-
export const MAGENTA = "\u001b[95m";
|
|
15
|
-
export const CYAN = "\u001b[96m";
|
|
16
|
-
export const WHITE = "\u001b[97m";
|
|
17
|
-
export const RESET = "\u001b[0m";
|
|
18
|
-
|
|
19
|
-
export class Colors {
|
|
20
|
-
constructor(stream) {
|
|
21
|
-
this.stream = stream;
|
|
22
|
-
this.enabled = Boolean((this.stream && this.stream.isTTY) || isCI);
|
|
23
|
-
}
|
|
24
|
-
gray(text) { return this.enabled ? GRAY + text + RESET : text; }
|
|
25
|
-
red(text) { return this.enabled ? RED + text + RESET : text; }
|
|
26
|
-
green(text) { return this.enabled ? GREEN + text + RESET : text; }
|
|
27
|
-
yellow(text) { return this.enabled ? YELLOW + text + RESET : text; }
|
|
28
|
-
blue(text) { return this.enabled ? BLUE + text + RESET : text; }
|
|
29
|
-
magenta(text) { return this.enabled ? MAGENTA + text + RESET : text; }
|
|
30
|
-
cyan(text) { return this.enabled ? CYAN + text + RESET : text; }
|
|
31
|
-
white(text) { return this.enabled ? WHITE + text + RESET : text; }
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const stdoutColors = new Colors(proc.stdout);
|
|
35
|
-
export const stderrColors = new Colors(proc.stderr);
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Terminal utility.
|
|
3
|
+
* @license Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var proc = typeof process !== "undefined" && process || {};
|
|
7
|
+
var isCI = proc.env && "CI" in proc.env;
|
|
8
|
+
|
|
9
|
+
export const GRAY = "\u001b[90m";
|
|
10
|
+
export const RED = "\u001b[91m";
|
|
11
|
+
export const GREEN = "\u001b[92m";
|
|
12
|
+
export const YELLOW = "\u001b[93m";
|
|
13
|
+
export const BLUE = "\u001b[94m";
|
|
14
|
+
export const MAGENTA = "\u001b[95m";
|
|
15
|
+
export const CYAN = "\u001b[96m";
|
|
16
|
+
export const WHITE = "\u001b[97m";
|
|
17
|
+
export const RESET = "\u001b[0m";
|
|
18
|
+
|
|
19
|
+
export class Colors {
|
|
20
|
+
constructor(stream) {
|
|
21
|
+
this.stream = stream;
|
|
22
|
+
this.enabled = Boolean((this.stream && this.stream.isTTY) || isCI);
|
|
23
|
+
}
|
|
24
|
+
gray(text) { return this.enabled ? GRAY + text + RESET : text; }
|
|
25
|
+
red(text) { return this.enabled ? RED + text + RESET : text; }
|
|
26
|
+
green(text) { return this.enabled ? GREEN + text + RESET : text; }
|
|
27
|
+
yellow(text) { return this.enabled ? YELLOW + text + RESET : text; }
|
|
28
|
+
blue(text) { return this.enabled ? BLUE + text + RESET : text; }
|
|
29
|
+
magenta(text) { return this.enabled ? MAGENTA + text + RESET : text; }
|
|
30
|
+
cyan(text) { return this.enabled ? CYAN + text + RESET : text; }
|
|
31
|
+
white(text) { return this.enabled ? WHITE + text + RESET : text; }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const stdoutColors = new Colors(proc.stdout);
|
|
35
|
+
export const stderrColors = new Colors(proc.stderr);
|
package/util/text.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Text utility definitions.
|
|
3
|
-
* @license Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/** Calculates the UTF-8 byte length of a string. */
|
|
7
|
-
export function utf8Length(string: string): number;
|
|
8
|
-
|
|
9
|
-
/** Reads UTF-8 bytes as a string. */
|
|
10
|
-
export function utf8Read(buffer: Uint8Array, start: number, end: number): string;
|
|
11
|
-
|
|
12
|
-
/** Writes a string as UTF-8 bytes. */
|
|
13
|
-
export function utf8Write(string: string, buffer: Uint8Array, offset: number): number;
|
|
14
|
-
|
|
15
|
-
/** UTF-8 utility. */
|
|
16
|
-
export const utf8: {
|
|
17
|
-
/** Calculates the UTF8 byte length of a string. */
|
|
18
|
-
length: typeof utf8Length;
|
|
19
|
-
/** Reads UTF8 bytes as a string. */
|
|
20
|
-
read: typeof utf8Read;
|
|
21
|
-
/** Writes a string as UTF8 bytes. */
|
|
22
|
-
write: typeof utf8Write;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/** Computes the difference between an expected and its actual text. */
|
|
26
|
-
export function diff(filename: string, expected: string, actual: string): string;
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Text utility definitions.
|
|
3
|
+
* @license Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Calculates the UTF-8 byte length of a string. */
|
|
7
|
+
export function utf8Length(string: string): number;
|
|
8
|
+
|
|
9
|
+
/** Reads UTF-8 bytes as a string. */
|
|
10
|
+
export function utf8Read(buffer: Uint8Array, start: number, end: number): string;
|
|
11
|
+
|
|
12
|
+
/** Writes a string as UTF-8 bytes. */
|
|
13
|
+
export function utf8Write(string: string, buffer: Uint8Array, offset: number): number;
|
|
14
|
+
|
|
15
|
+
/** UTF-8 utility. */
|
|
16
|
+
export const utf8: {
|
|
17
|
+
/** Calculates the UTF8 byte length of a string. */
|
|
18
|
+
length: typeof utf8Length;
|
|
19
|
+
/** Reads UTF8 bytes as a string. */
|
|
20
|
+
read: typeof utf8Read;
|
|
21
|
+
/** Writes a string as UTF8 bytes. */
|
|
22
|
+
write: typeof utf8Write;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Computes the difference between an expected and its actual text. */
|
|
26
|
+
export function diff(filename: string, expected: string, actual: string): string;
|
package/util/text.js
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Text utility.
|
|
3
|
-
* @license Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as Diff from "diff";
|
|
7
|
-
import { stdoutColors } from "./terminal.js";
|
|
8
|
-
|
|
9
|
-
export function utf8Length(string) {
|
|
10
|
-
var len = 0;
|
|
11
|
-
for (var i = 0, k = string.length; i < k; ++i) {
|
|
12
|
-
let c = string.charCodeAt(i);
|
|
13
|
-
if (c < 128) {
|
|
14
|
-
len += 1;
|
|
15
|
-
} else if (c < 2048) {
|
|
16
|
-
len += 2;
|
|
17
|
-
} else if ((c & 0xFC00) === 0xD800 && i + 1 < k && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
|
18
|
-
++i;
|
|
19
|
-
len += 4;
|
|
20
|
-
} else {
|
|
21
|
-
len += 3;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return len;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function utf8Read(buffer, start, end) {
|
|
28
|
-
var len = end - start;
|
|
29
|
-
if (len < 1) return "";
|
|
30
|
-
var parts = null,
|
|
31
|
-
chunk = [],
|
|
32
|
-
i = 0, // char offset
|
|
33
|
-
t; // temporary
|
|
34
|
-
while (start < end) {
|
|
35
|
-
t = buffer[start++];
|
|
36
|
-
if (t < 128) {
|
|
37
|
-
chunk[i++] = t;
|
|
38
|
-
} else if (t > 191 && t < 224) {
|
|
39
|
-
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
|
|
40
|
-
} else if (t > 239 && t < 365) {
|
|
41
|
-
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
|
|
42
|
-
chunk[i++] = 0xD800 + (t >> 10);
|
|
43
|
-
chunk[i++] = 0xDC00 + (t & 1023);
|
|
44
|
-
} else {
|
|
45
|
-
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
|
|
46
|
-
}
|
|
47
|
-
if (i >= 8192) {
|
|
48
|
-
(parts || (parts = [])).push(String.fromCharCode(...chunk));
|
|
49
|
-
i = 0;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (parts) {
|
|
53
|
-
if (i) parts.push(String.fromCharCode(...chunk.slice(0, i)));
|
|
54
|
-
return parts.join("");
|
|
55
|
-
}
|
|
56
|
-
return String.fromCharCode(...chunk.slice(0, i));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function utf8Write(string, buffer, offset) {
|
|
60
|
-
var start = offset;
|
|
61
|
-
for (var i = 0, k = string.length; i < k; ++i) {
|
|
62
|
-
let c1 = string.charCodeAt(i), c2;
|
|
63
|
-
if (c1 < 128) {
|
|
64
|
-
buffer[offset++] = c1;
|
|
65
|
-
} else if (c1 < 2048) {
|
|
66
|
-
buffer[offset++] = c1 >> 6 | 192;
|
|
67
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
68
|
-
} else if ((c1 & 0xFC00) === 0xD800 && i + 1 < k && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
|
69
|
-
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
|
70
|
-
++i;
|
|
71
|
-
buffer[offset++] = c1 >> 18 | 240;
|
|
72
|
-
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
73
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
74
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
75
|
-
} else {
|
|
76
|
-
buffer[offset++] = c1 >> 12 | 224;
|
|
77
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
78
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return offset - start;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export const utf8 = {
|
|
85
|
-
length: utf8Length,
|
|
86
|
-
read: utf8Read,
|
|
87
|
-
write: utf8Write
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export function diff(filename, expected, actual) {
|
|
91
|
-
const diff = Diff.structuredPatch(filename, filename, expected, actual, "expected", "actual", { context: 5 });
|
|
92
|
-
if (!diff.hunks.length) return null;
|
|
93
|
-
|
|
94
|
-
const out = [
|
|
95
|
-
'--- ' + diff.oldHeader,
|
|
96
|
-
'+++ ' + diff.newHeader
|
|
97
|
-
];
|
|
98
|
-
for (const hunk of diff.hunks) {
|
|
99
|
-
out.push(
|
|
100
|
-
'@@ -' + hunk.oldStart + ',' + hunk.oldLines
|
|
101
|
-
+ ' +' + hunk.newStart + ',' + hunk.newLines
|
|
102
|
-
+ ' @@'
|
|
103
|
-
);
|
|
104
|
-
out.push(...hunk.lines.map(line =>
|
|
105
|
-
line.charAt(0) === "+"
|
|
106
|
-
? stdoutColors.green(line)
|
|
107
|
-
: line.charAt(0) === "-"
|
|
108
|
-
? stdoutColors.red(line)
|
|
109
|
-
: line
|
|
110
|
-
));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return out.join('\n') + '\n';
|
|
114
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Text utility.
|
|
3
|
+
* @license Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as Diff from "diff";
|
|
7
|
+
import { stdoutColors } from "./terminal.js";
|
|
8
|
+
|
|
9
|
+
export function utf8Length(string) {
|
|
10
|
+
var len = 0;
|
|
11
|
+
for (var i = 0, k = string.length; i < k; ++i) {
|
|
12
|
+
let c = string.charCodeAt(i);
|
|
13
|
+
if (c < 128) {
|
|
14
|
+
len += 1;
|
|
15
|
+
} else if (c < 2048) {
|
|
16
|
+
len += 2;
|
|
17
|
+
} else if ((c & 0xFC00) === 0xD800 && i + 1 < k && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
|
18
|
+
++i;
|
|
19
|
+
len += 4;
|
|
20
|
+
} else {
|
|
21
|
+
len += 3;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return len;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function utf8Read(buffer, start, end) {
|
|
28
|
+
var len = end - start;
|
|
29
|
+
if (len < 1) return "";
|
|
30
|
+
var parts = null,
|
|
31
|
+
chunk = [],
|
|
32
|
+
i = 0, // char offset
|
|
33
|
+
t; // temporary
|
|
34
|
+
while (start < end) {
|
|
35
|
+
t = buffer[start++];
|
|
36
|
+
if (t < 128) {
|
|
37
|
+
chunk[i++] = t;
|
|
38
|
+
} else if (t > 191 && t < 224) {
|
|
39
|
+
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
|
|
40
|
+
} else if (t > 239 && t < 365) {
|
|
41
|
+
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
|
|
42
|
+
chunk[i++] = 0xD800 + (t >> 10);
|
|
43
|
+
chunk[i++] = 0xDC00 + (t & 1023);
|
|
44
|
+
} else {
|
|
45
|
+
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
|
|
46
|
+
}
|
|
47
|
+
if (i >= 8192) {
|
|
48
|
+
(parts || (parts = [])).push(String.fromCharCode(...chunk));
|
|
49
|
+
i = 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (parts) {
|
|
53
|
+
if (i) parts.push(String.fromCharCode(...chunk.slice(0, i)));
|
|
54
|
+
return parts.join("");
|
|
55
|
+
}
|
|
56
|
+
return String.fromCharCode(...chunk.slice(0, i));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function utf8Write(string, buffer, offset) {
|
|
60
|
+
var start = offset;
|
|
61
|
+
for (var i = 0, k = string.length; i < k; ++i) {
|
|
62
|
+
let c1 = string.charCodeAt(i), c2;
|
|
63
|
+
if (c1 < 128) {
|
|
64
|
+
buffer[offset++] = c1;
|
|
65
|
+
} else if (c1 < 2048) {
|
|
66
|
+
buffer[offset++] = c1 >> 6 | 192;
|
|
67
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
68
|
+
} else if ((c1 & 0xFC00) === 0xD800 && i + 1 < k && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
|
69
|
+
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
|
70
|
+
++i;
|
|
71
|
+
buffer[offset++] = c1 >> 18 | 240;
|
|
72
|
+
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
73
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
74
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
75
|
+
} else {
|
|
76
|
+
buffer[offset++] = c1 >> 12 | 224;
|
|
77
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
78
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return offset - start;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const utf8 = {
|
|
85
|
+
length: utf8Length,
|
|
86
|
+
read: utf8Read,
|
|
87
|
+
write: utf8Write
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export function diff(filename, expected, actual) {
|
|
91
|
+
const diff = Diff.structuredPatch(filename, filename, expected, actual, "expected", "actual", { context: 5 });
|
|
92
|
+
if (!diff.hunks.length) return null;
|
|
93
|
+
|
|
94
|
+
const out = [
|
|
95
|
+
'--- ' + diff.oldHeader,
|
|
96
|
+
'+++ ' + diff.newHeader
|
|
97
|
+
];
|
|
98
|
+
for (const hunk of diff.hunks) {
|
|
99
|
+
out.push(
|
|
100
|
+
'@@ -' + hunk.oldStart + ',' + hunk.oldLines
|
|
101
|
+
+ ' +' + hunk.newStart + ',' + hunk.newLines
|
|
102
|
+
+ ' @@'
|
|
103
|
+
);
|
|
104
|
+
out.push(...hunk.lines.map(line =>
|
|
105
|
+
line.charAt(0) === "+"
|
|
106
|
+
? stdoutColors.green(line)
|
|
107
|
+
: line.charAt(0) === "-"
|
|
108
|
+
? stdoutColors.red(line)
|
|
109
|
+
: line
|
|
110
|
+
));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return out.join('\n') + '\n';
|
|
114
|
+
}
|
package/util/tsconfig.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../tsconfig-base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"esModuleInterop": true
|
|
5
|
-
},
|
|
6
|
-
"include": [
|
|
7
|
-
"./**/*.ts"
|
|
8
|
-
]
|
|
9
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig-base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"esModuleInterop": true
|
|
5
|
+
},
|
|
6
|
+
"include": [
|
|
7
|
+
"./**/*.ts"
|
|
8
|
+
]
|
|
9
|
+
}
|
package/util/web.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Web polyfill definitions.
|
|
3
|
-
* @license Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/** Fetches a file. */
|
|
7
|
-
export function fetch(url: string): Promise<{
|
|
8
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
9
|
-
text(): Promise<string>;
|
|
10
|
-
json(): Promise<any>;
|
|
11
|
-
}>;
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Web polyfill definitions.
|
|
3
|
+
* @license Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Fetches a file. */
|
|
7
|
+
export function fetch(url: string): Promise<{
|
|
8
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
9
|
+
text(): Promise<string>;
|
|
10
|
+
json(): Promise<any>;
|
|
11
|
+
}>;
|
package/util/web.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Web polyfills.
|
|
3
|
-
* @license Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { fs } from "./node.js";
|
|
7
|
-
|
|
8
|
-
var _fetch = typeof fetch === "function" ? fetch :
|
|
9
|
-
url => new Promise((resolve, reject) => {
|
|
10
|
-
fs.readFile(url, (err, data) => {
|
|
11
|
-
if (err) reject(err);
|
|
12
|
-
resolve({
|
|
13
|
-
arrayBuffer() {
|
|
14
|
-
let offset = data.byteOffset;
|
|
15
|
-
return Promise.resolve(data.buffer.slice(offset, offset + data.byteLength));
|
|
16
|
-
},
|
|
17
|
-
text() {
|
|
18
|
-
return Promise.resolve(data.toString());
|
|
19
|
-
},
|
|
20
|
-
json() {
|
|
21
|
-
try {
|
|
22
|
-
return Promise.resolve(JSON.parse(data.toString()));
|
|
23
|
-
} catch (err) {
|
|
24
|
-
return Promise.reject(err);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
_fetch as fetch
|
|
33
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Web polyfills.
|
|
3
|
+
* @license Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { fs } from "./node.js";
|
|
7
|
+
|
|
8
|
+
var _fetch = typeof fetch === "function" ? fetch :
|
|
9
|
+
url => new Promise((resolve, reject) => {
|
|
10
|
+
fs.readFile(url, (err, data) => {
|
|
11
|
+
if (err) reject(err);
|
|
12
|
+
resolve({
|
|
13
|
+
arrayBuffer() {
|
|
14
|
+
let offset = data.byteOffset;
|
|
15
|
+
return Promise.resolve(data.buffer.slice(offset, offset + data.byteLength));
|
|
16
|
+
},
|
|
17
|
+
text() {
|
|
18
|
+
return Promise.resolve(data.toString());
|
|
19
|
+
},
|
|
20
|
+
json() {
|
|
21
|
+
try {
|
|
22
|
+
return Promise.resolve(JSON.parse(data.toString()));
|
|
23
|
+
} catch (err) {
|
|
24
|
+
return Promise.reject(err);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
_fetch as fetch
|
|
33
|
+
};
|