toilscript 0.0.1 → 0.1.1

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.
Files changed (121) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +94 -94
  3. package/README.md +101 -114
  4. package/bin/asc.js +0 -0
  5. package/bin/asinit.js +6 -6
  6. package/dist/asc.generated.d.ts +10027 -0
  7. package/dist/asc.js +24474 -0
  8. package/dist/asc.js.map +7 -0
  9. package/dist/importmap.json +9 -0
  10. package/dist/toilscript.generated.d.ts +11242 -0
  11. package/dist/toilscript.js +337 -0
  12. package/dist/toilscript.js.map +7 -0
  13. package/dist/web.js +22 -0
  14. package/lib/binaryen.d.ts +2 -2
  15. package/lib/binaryen.js +2 -2
  16. package/package.json +115 -114
  17. package/std/README.md +6 -6
  18. package/std/assembly/array.ts +550 -550
  19. package/std/assembly/arraybuffer.ts +77 -77
  20. package/std/assembly/atomics.ts +127 -127
  21. package/std/assembly/bindings/asyncify.ts +16 -16
  22. package/std/assembly/bindings/dom.ts +291 -291
  23. package/std/assembly/bindings/node.ts +6 -6
  24. package/std/assembly/bitflags.ts +53 -53
  25. package/std/assembly/builtins.ts +2650 -2650
  26. package/std/assembly/byteslice.ts +177 -177
  27. package/std/assembly/compat.ts +2 -2
  28. package/std/assembly/console.ts +42 -42
  29. package/std/assembly/crypto.ts +9 -9
  30. package/std/assembly/dataview.ts +181 -181
  31. package/std/assembly/date.ts +375 -375
  32. package/std/assembly/diagnostics.ts +11 -11
  33. package/std/assembly/encoding.ts +151 -151
  34. package/std/assembly/endian.ts +45 -45
  35. package/std/assembly/error.ts +44 -44
  36. package/std/assembly/fixedarray.ts +173 -173
  37. package/std/assembly/fixedmap.ts +326 -326
  38. package/std/assembly/fixedset.ts +275 -275
  39. package/std/assembly/function.ts +42 -42
  40. package/std/assembly/index.d.ts +2892 -2891
  41. package/std/assembly/iterator.ts +35 -35
  42. package/std/assembly/map.ts +269 -269
  43. package/std/assembly/math.ts +3289 -3289
  44. package/std/assembly/memory.ts +123 -123
  45. package/std/assembly/number.ts +388 -388
  46. package/std/assembly/object.ts +36 -36
  47. package/std/assembly/performance.ts +9 -9
  48. package/std/assembly/pointer.ts +80 -80
  49. package/std/assembly/polyfills.ts +27 -27
  50. package/std/assembly/process.ts +50 -50
  51. package/std/assembly/reference.ts +48 -48
  52. package/std/assembly/regexp.ts +12 -12
  53. package/std/assembly/rt/README.md +83 -83
  54. package/std/assembly/rt/common.ts +81 -81
  55. package/std/assembly/rt/index-incremental.ts +2 -2
  56. package/std/assembly/rt/index-memory.ts +1 -1
  57. package/std/assembly/rt/index-minimal.ts +2 -2
  58. package/std/assembly/rt/index-stub.ts +1 -1
  59. package/std/assembly/rt/index.d.ts +37 -37
  60. package/std/assembly/rt/itcms.ts +419 -419
  61. package/std/assembly/rt/memory-runtime.ts +94 -94
  62. package/std/assembly/rt/rtrace.ts +15 -15
  63. package/std/assembly/rt/stub.ts +133 -133
  64. package/std/assembly/rt/tcms.ts +254 -254
  65. package/std/assembly/rt/tlsf.ts +592 -592
  66. package/std/assembly/rt.ts +90 -90
  67. package/std/assembly/set.ts +225 -225
  68. package/std/assembly/shared/feature.ts +68 -68
  69. package/std/assembly/shared/runtime.ts +13 -13
  70. package/std/assembly/shared/target.ts +11 -11
  71. package/std/assembly/shared/tsconfig.json +11 -11
  72. package/std/assembly/shared/typeinfo.ts +72 -72
  73. package/std/assembly/staticarray.ts +423 -423
  74. package/std/assembly/string.ts +850 -850
  75. package/std/assembly/symbol.ts +114 -114
  76. package/std/assembly/table.ts +16 -16
  77. package/std/assembly/toilscript.ts +16 -0
  78. package/std/assembly/tsconfig.json +6 -6
  79. package/std/assembly/typedarray.ts +1954 -1954
  80. package/std/assembly/uri.ts +17 -17
  81. package/std/assembly/util/bytes.ts +107 -107
  82. package/std/assembly/util/casemap.ts +497 -497
  83. package/std/assembly/util/error.ts +58 -58
  84. package/std/assembly/util/hash.ts +117 -117
  85. package/std/assembly/util/math.ts +1922 -1922
  86. package/std/assembly/util/memory.ts +290 -290
  87. package/std/assembly/util/number.ts +873 -873
  88. package/std/assembly/util/sort.ts +313 -313
  89. package/std/assembly/util/string.ts +1202 -1202
  90. package/std/assembly/util/uri.ts +275 -275
  91. package/std/assembly/vector.ts +4 -4
  92. package/std/assembly.json +16 -16
  93. package/std/portable/index.d.ts +461 -461
  94. package/std/portable/index.js +416 -416
  95. package/std/portable.json +11 -11
  96. package/std/types/assembly/index.d.ts +1 -1
  97. package/std/types/assembly/package.json +2 -2
  98. package/std/types/portable/index.d.ts +1 -1
  99. package/std/types/portable/package.json +2 -2
  100. package/tsconfig-base.json +13 -13
  101. package/util/README.md +23 -23
  102. package/util/browser/fs.js +1 -1
  103. package/util/browser/module.js +5 -5
  104. package/util/browser/path.js +520 -520
  105. package/util/browser/process.js +59 -59
  106. package/util/browser/url.js +23 -23
  107. package/util/cpu.d.ts +9 -9
  108. package/util/cpu.js +42 -42
  109. package/util/find.d.ts +6 -6
  110. package/util/find.js +20 -20
  111. package/util/node.d.ts +21 -21
  112. package/util/node.js +34 -34
  113. package/util/options.d.ts +70 -70
  114. package/util/options.js +262 -262
  115. package/util/terminal.d.ts +52 -52
  116. package/util/terminal.js +35 -35
  117. package/util/text.d.ts +26 -26
  118. package/util/text.js +114 -114
  119. package/util/tsconfig.json +9 -9
  120. package/util/web.d.ts +11 -11
  121. package/util/web.js +33 -33
@@ -1,59 +1,59 @@
1
- export const platform = "linux";
2
-
3
- export function cwd() {
4
- return ".";
5
- }
6
-
7
- export function umask() {
8
- return 0;
9
- }
10
-
11
- export const argv = [];
12
-
13
- export function exit(code = 0) {
14
- throw Error(`exit ${code}`);
15
- }
16
-
17
- // https://github.com/kumavis/browser-process-hrtime v1.0.0
18
- //
19
- // Copyright 2014 kumavis
20
- //
21
- // Redistribution and use in source and binary forms, with or without
22
- // modification, are permitted provided that the following conditions are met:
23
- //
24
- // 1. Redistributions of source code must retain the above copyright notice,
25
- // this list of conditions and the following disclaimer.
26
- //
27
- // 2. Redistributions in binary form must reproduce the above copyright notice,
28
- // this list of conditions and the following disclaimer in the documentation
29
- // and/or other materials provided with the distribution.
30
- //
31
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32
- // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
- // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
35
- // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36
- // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37
- // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38
- // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39
- // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
- // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41
- // POSSIBILITY OF SUCH DAMAGE.
42
-
43
- var performance = globalThis.performance || {};
44
- var performanceNow = performance.now || function() { return new Date().getTime(); };
45
-
46
- export function hrtime(previousTimestamp) {
47
- var clocktime = performanceNow.call(performance);
48
- var seconds = Math.floor(clocktime * 1e-3);
49
- var nanoseconds = Math.floor(clocktime * 1e6 - seconds * 1e9);
50
- if (previousTimestamp) {
51
- seconds -= previousTimestamp[0];
52
- nanoseconds -= previousTimestamp[1];
53
- if (nanoseconds < 0) {
54
- seconds--;
55
- nanoseconds += 1e9;
56
- }
57
- }
58
- return [ seconds, nanoseconds ];
59
- }
1
+ export const platform = "linux";
2
+
3
+ export function cwd() {
4
+ return ".";
5
+ }
6
+
7
+ export function umask() {
8
+ return 0;
9
+ }
10
+
11
+ export const argv = [];
12
+
13
+ export function exit(code = 0) {
14
+ throw Error(`exit ${code}`);
15
+ }
16
+
17
+ // https://github.com/kumavis/browser-process-hrtime v1.0.0
18
+ //
19
+ // Copyright 2014 kumavis
20
+ //
21
+ // Redistribution and use in source and binary forms, with or without
22
+ // modification, are permitted provided that the following conditions are met:
23
+ //
24
+ // 1. Redistributions of source code must retain the above copyright notice,
25
+ // this list of conditions and the following disclaimer.
26
+ //
27
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
28
+ // this list of conditions and the following disclaimer in the documentation
29
+ // and/or other materials provided with the distribution.
30
+ //
31
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
35
+ // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36
+ // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37
+ // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38
+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39
+ // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
+ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41
+ // POSSIBILITY OF SUCH DAMAGE.
42
+
43
+ var performance = globalThis.performance || {};
44
+ var performanceNow = performance.now || function() { return new Date().getTime(); };
45
+
46
+ export function hrtime(previousTimestamp) {
47
+ var clocktime = performanceNow.call(performance);
48
+ var seconds = Math.floor(clocktime * 1e-3);
49
+ var nanoseconds = Math.floor(clocktime * 1e6 - seconds * 1e9);
50
+ if (previousTimestamp) {
51
+ seconds -= previousTimestamp[0];
52
+ nanoseconds -= previousTimestamp[1];
53
+ if (nanoseconds < 0) {
54
+ seconds--;
55
+ nanoseconds += 1e9;
56
+ }
57
+ }
58
+ return [ seconds, nanoseconds ];
59
+ }
@@ -1,23 +1,23 @@
1
- import * as path from "./path.js";
2
-
3
- function encodePathChars(filepath) {
4
- return filepath
5
- .replace(/%/g, "%25")
6
- .replace(/\\/g, "%5C")
7
- .replace(/\n/g, "%0A")
8
- .replace(/\r/g, "%0D")
9
- .replace(/\t/g, "%09");
10
- }
11
-
12
- export function pathToFileURL(filepath) {
13
- let resolved = path.resolve(filepath);
14
- if (
15
- filepath.charCodeAt(filepath.length - 1) === /* SLASH */ 47 &&
16
- resolved[resolved.length - 1] !== path.sep
17
- ) {
18
- resolved += "/";
19
- }
20
- const url = new URL("file://");
21
- url.pathname = encodePathChars(resolved);
22
- return url;
23
- }
1
+ import * as path from "./path.js";
2
+
3
+ function encodePathChars(filepath) {
4
+ return filepath
5
+ .replace(/%/g, "%25")
6
+ .replace(/\\/g, "%5C")
7
+ .replace(/\n/g, "%0A")
8
+ .replace(/\r/g, "%0D")
9
+ .replace(/\t/g, "%09");
10
+ }
11
+
12
+ export function pathToFileURL(filepath) {
13
+ let resolved = path.resolve(filepath);
14
+ if (
15
+ filepath.charCodeAt(filepath.length - 1) === /* SLASH */ 47 &&
16
+ resolved[resolved.length - 1] !== path.sep
17
+ ) {
18
+ resolved += "/";
19
+ }
20
+ const url = new URL("file://");
21
+ url.pathname = encodePathChars(resolved);
22
+ return url;
23
+ }
package/util/cpu.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- /**
2
- * @fileoverview CPU utility definitions.
3
- * @license Apache-2.0
4
- */
5
-
6
- /** Number of threads. */
7
- export const threadCount: number;
8
- /** Number of cores. */
9
- export const coreCount: number;
1
+ /**
2
+ * @fileoverview CPU utility definitions.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ /** Number of threads. */
7
+ export const threadCount: number;
8
+ /** Number of cores. */
9
+ export const coreCount: number;
package/util/cpu.js CHANGED
@@ -1,42 +1,42 @@
1
- /**
2
- * @fileoverview CPU utility.
3
- * @license Apache-2.0
4
- */
5
-
6
- // https://www.npmjs.com/package/physical-cpu-count
7
-
8
- import os from "os";
9
- import childProcess from "child_process";
10
-
11
- const cpus = os.cpus();
12
-
13
- function exec(command) {
14
- return childProcess.execSync(command, {encoding: 'utf8'});
15
- }
16
-
17
- var coreCount;
18
-
19
- const platform = os.platform();
20
- if (platform === "linux") {
21
- const output = exec("lscpu -p | egrep -v \"^#\" | sort -u -t, -k 2,4 | wc -l");
22
- coreCount = parseInt(output.trim(), 10);
23
- } else if (platform === "darwin") {
24
- const output = exec("sysctl -n hw.physicalcpu_max");
25
- coreCount = parseInt(output.trim(), 10);
26
- } else if (platform === "windows") {
27
- const output = exec("WMIC CPU Get NumberOfCores");
28
- coreCount = output.split(os.EOL)
29
- .map(line => parseInt(line))
30
- .filter(value => !isNaN(value))
31
- .reduce((sum, number) => sum + number, 0);
32
- } else {
33
- const cores = cpus.filter(function (cpu, index) {
34
- const hasHyperthreading = cpu.model.includes("Intel");
35
- const isOdd = index % 2 === 1;
36
- return !hasHyperthreading || isOdd;
37
- });
38
- coreCount = cores.length;
39
- }
40
-
41
- export const threadCount = cpus.length;
42
- export { coreCount };
1
+ /**
2
+ * @fileoverview CPU utility.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ // https://www.npmjs.com/package/physical-cpu-count
7
+
8
+ import os from "os";
9
+ import childProcess from "child_process";
10
+
11
+ const cpus = os.cpus();
12
+
13
+ function exec(command) {
14
+ return childProcess.execSync(command, {encoding: 'utf8'});
15
+ }
16
+
17
+ var coreCount;
18
+
19
+ const platform = os.platform();
20
+ if (platform === "linux") {
21
+ const output = exec("lscpu -p | egrep -v \"^#\" | sort -u -t, -k 2,4 | wc -l");
22
+ coreCount = parseInt(output.trim(), 10);
23
+ } else if (platform === "darwin") {
24
+ const output = exec("sysctl -n hw.physicalcpu_max");
25
+ coreCount = parseInt(output.trim(), 10);
26
+ } else if (platform === "windows") {
27
+ const output = exec("WMIC CPU Get NumberOfCores");
28
+ coreCount = output.split(os.EOL)
29
+ .map(line => parseInt(line))
30
+ .filter(value => !isNaN(value))
31
+ .reduce((sum, number) => sum + number, 0);
32
+ } else {
33
+ const cores = cpus.filter(function (cpu, index) {
34
+ const hasHyperthreading = cpu.model.includes("Intel");
35
+ const isOdd = index % 2 === 1;
36
+ return !hasHyperthreading || isOdd;
37
+ });
38
+ coreCount = cores.length;
39
+ }
40
+
41
+ export const threadCount = cpus.length;
42
+ export { coreCount };
package/util/find.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- /**
2
- * @fileoverview File finding utility definitions.
3
- * @license Apache-2.0
4
- */
5
-
6
- export function findFiles(dirname: string, filter?: ((name: string) => boolean) | RegExp): string[];
1
+ /**
2
+ * @fileoverview File finding utility definitions.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ export function findFiles(dirname: string, filter?: ((name: string) => boolean) | RegExp): string[];
package/util/find.js CHANGED
@@ -1,20 +1,20 @@
1
- /**
2
- * @fileoverview File finding utility.
3
- * @license Apache-2.0
4
- */
5
-
6
- import { fs, path } from "./node.js";
7
-
8
- export function findFiles(dirname, filter) {
9
- var out = [];
10
- fs.readdirSync(dirname).forEach(name => {
11
- if (fs.statSync(path.join(dirname, name)).isDirectory()) {
12
- findFiles(path.join(dirname, name), filter).forEach(iname => out.push(name + "/" + iname));
13
- } else if (!filter || typeof filter === "function" ? filter(name) : filter.test(name)) {
14
- out.push(name);
15
- }
16
- });
17
- return out;
18
- }
19
-
20
- export default findFiles;
1
+ /**
2
+ * @fileoverview File finding utility.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ import { fs, path } from "./node.js";
7
+
8
+ export function findFiles(dirname, filter) {
9
+ var out = [];
10
+ fs.readdirSync(dirname).forEach(name => {
11
+ if (fs.statSync(path.join(dirname, name)).isDirectory()) {
12
+ findFiles(path.join(dirname, name), filter).forEach(iname => out.push(name + "/" + iname));
13
+ } else if (!filter || typeof filter === "function" ? filter(name) : filter.test(name)) {
14
+ out.push(name);
15
+ }
16
+ });
17
+ return out;
18
+ }
19
+
20
+ export default findFiles;
package/util/node.d.ts CHANGED
@@ -1,21 +1,21 @@
1
- /**
2
- * @fileoverview Node polyfill definitions.
3
- * @license Apache-2.0
4
- */
5
-
6
- import fs from "fs";
7
- import module from "module";
8
- import path from "path";
9
- import process from "process";
10
- import url from "url";
11
-
12
- /** Whether the environment is Node.js. */
13
- export const isNode: boolean;
14
-
15
- export {
16
- fs,
17
- module,
18
- path,
19
- process,
20
- url
21
- };
1
+ /**
2
+ * @fileoverview Node polyfill definitions.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ import fs from "fs";
7
+ import module from "module";
8
+ import path from "path";
9
+ import process from "process";
10
+ import url from "url";
11
+
12
+ /** Whether the environment is Node.js. */
13
+ export const isNode: boolean;
14
+
15
+ export {
16
+ fs,
17
+ module,
18
+ path,
19
+ process,
20
+ url
21
+ };
package/util/node.js CHANGED
@@ -1,34 +1,34 @@
1
- /**
2
- * @fileoverview Node.js polyfills.
3
- * @license Apache-2.0
4
- */
5
-
6
- export const isNode = Object.prototype.toString.call(typeof globalThis.process !== 'undefined' ? globalThis.process : 0) === '[object process]';
7
-
8
- var fs;
9
- var module;
10
- var path;
11
- var process;
12
- var url;
13
-
14
- if (isNode) {
15
- fs = await import("fs");
16
- module = await import("module");
17
- path = await import("path");
18
- process = globalThis.process;
19
- url = await import("url");
20
- } else {
21
- fs = await import("./browser/fs.js");
22
- module = await import("./browser/module.js");
23
- path = await import("./browser/path.js");
24
- process = await import("./browser/process.js");
25
- url = await import("./browser/url.js");
26
- }
27
-
28
- export {
29
- fs,
30
- module,
31
- path,
32
- process,
33
- url
34
- };
1
+ /**
2
+ * @fileoverview Node.js polyfills.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ export const isNode = Object.prototype.toString.call(typeof globalThis.process !== 'undefined' ? globalThis.process : 0) === '[object process]';
7
+
8
+ var fs;
9
+ var module;
10
+ var path;
11
+ var process;
12
+ var url;
13
+
14
+ if (isNode) {
15
+ fs = await import("fs");
16
+ module = await import("module");
17
+ path = await import("path");
18
+ process = globalThis.process;
19
+ url = await import("url");
20
+ } else {
21
+ fs = await import("./browser/fs.js");
22
+ module = await import("./browser/module.js");
23
+ path = await import("./browser/path.js");
24
+ process = await import("./browser/process.js");
25
+ url = await import("./browser/url.js");
26
+ }
27
+
28
+ export {
29
+ fs,
30
+ module,
31
+ path,
32
+ process,
33
+ url
34
+ };
package/util/options.d.ts CHANGED
@@ -1,70 +1,70 @@
1
- /**
2
- * @fileoverview Command line options utility definitions.
3
- * @license Apache-2.0
4
- */
5
-
6
- /** A set of options. */
7
- export interface OptionSet {
8
- [key: string]: number | string
9
- }
10
-
11
- /** Command line option description. */
12
- export interface OptionDescription {
13
- /** Textual description. */
14
- description?: string | string[],
15
- /** Data type. One of (b)oolean [default], (i)nteger, (f)loat or (s)tring. Uppercase means multiple values. */
16
- type?: "b" | "i" | "f" | "s" | "I" | "F" | "S",
17
- /** Substituted options, if any. */
18
- value?: OptionSet,
19
- /** Short alias, if any. */
20
- alias?: string
21
- /** The default value, if any. */
22
- default?: string | number | boolean | string[] | number[];
23
- /** The category this option belongs in. */
24
- category?: string;
25
- }
26
-
27
- /** Configuration object. */
28
- export interface Config {
29
- [key: string]: OptionDescription;
30
- }
31
-
32
- /** Parsing result. */
33
- export interface Result {
34
- /** Parsed options. */
35
- options: OptionSet,
36
- /** Unknown options. */
37
- unknown: string[],
38
- /** Normal arguments. */
39
- arguments: string[],
40
- /** Trailing arguments. */
41
- trailing: string[]
42
- }
43
-
44
- /** Parses the specified command line arguments according to the given configuration. */
45
- export function parse(argv: string[], config: Config, propagateDefaults?: boolean): Result;
46
-
47
- /** Help formatting options. */
48
- export interface HelpOptions {
49
- /** Leading indent. Defaults to 2. */
50
- indent?: number,
51
- /** Table padding. Defaults to 24. */
52
- padding?: number,
53
- /** End of line character. Defaults to "\n". */
54
- eol?: string
55
- }
56
-
57
- /** Generates the help text for the specified configuration. */
58
- export function help(config: Config, options?: HelpOptions): string;
59
-
60
- /** Merges two sets of options into one, preferring the current over the parent set. */
61
- export function merge(config: Config, currentOptions: OptionSet, parentOptions: OptionSet, parentBaseDir: string): OptionSet;
62
-
63
- /** Normalizes a path. */
64
- export function normalizePath(path: string): string;
65
-
66
- /** Resolves a single relative path. Keeps absolute paths, otherwise prepends baseDir. */
67
- export function resolvePath(path: string, baseDir: string, useNodeResolution?: boolean): string;
68
-
69
- /** Populates default values on a parsed options result. */
70
- export function addDefaults(config: Config, options: OptionSet): void;
1
+ /**
2
+ * @fileoverview Command line options utility definitions.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ /** A set of options. */
7
+ export interface OptionSet {
8
+ [key: string]: number | string
9
+ }
10
+
11
+ /** Command line option description. */
12
+ export interface OptionDescription {
13
+ /** Textual description. */
14
+ description?: string | string[],
15
+ /** Data type. One of (b)oolean [default], (i)nteger, (f)loat or (s)tring. Uppercase means multiple values. */
16
+ type?: "b" | "i" | "f" | "s" | "I" | "F" | "S",
17
+ /** Substituted options, if any. */
18
+ value?: OptionSet,
19
+ /** Short alias, if any. */
20
+ alias?: string
21
+ /** The default value, if any. */
22
+ default?: string | number | boolean | string[] | number[];
23
+ /** The category this option belongs in. */
24
+ category?: string;
25
+ }
26
+
27
+ /** Configuration object. */
28
+ export interface Config {
29
+ [key: string]: OptionDescription;
30
+ }
31
+
32
+ /** Parsing result. */
33
+ export interface Result {
34
+ /** Parsed options. */
35
+ options: OptionSet,
36
+ /** Unknown options. */
37
+ unknown: string[],
38
+ /** Normal arguments. */
39
+ arguments: string[],
40
+ /** Trailing arguments. */
41
+ trailing: string[]
42
+ }
43
+
44
+ /** Parses the specified command line arguments according to the given configuration. */
45
+ export function parse(argv: string[], config: Config, propagateDefaults?: boolean): Result;
46
+
47
+ /** Help formatting options. */
48
+ export interface HelpOptions {
49
+ /** Leading indent. Defaults to 2. */
50
+ indent?: number,
51
+ /** Table padding. Defaults to 24. */
52
+ padding?: number,
53
+ /** End of line character. Defaults to "\n". */
54
+ eol?: string
55
+ }
56
+
57
+ /** Generates the help text for the specified configuration. */
58
+ export function help(config: Config, options?: HelpOptions): string;
59
+
60
+ /** Merges two sets of options into one, preferring the current over the parent set. */
61
+ export function merge(config: Config, currentOptions: OptionSet, parentOptions: OptionSet, parentBaseDir: string): OptionSet;
62
+
63
+ /** Normalizes a path. */
64
+ export function normalizePath(path: string): string;
65
+
66
+ /** Resolves a single relative path. Keeps absolute paths, otherwise prepends baseDir. */
67
+ export function resolvePath(path: string, baseDir: string, useNodeResolution?: boolean): string;
68
+
69
+ /** Populates default values on a parsed options result. */
70
+ export function addDefaults(config: Config, options: OptionSet): void;