@fnndsc/brasa 0.56.2 → 0.56.4
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/buildinfo.json +1 -1
- package/dist/builtins/berth/berth.d.ts +11 -0
- package/dist/builtins/berth/berth.js +53 -22
- package/dist/builtins/berth/berth.js.map +1 -1
- package/dist/builtins/berth/berthCube.d.ts +17 -2
- package/dist/builtins/berth/berthCube.js +22 -10
- package/dist/builtins/berth/berthCube.js.map +1 -1
- package/dist/builtins/debug.d.ts +24 -3
- package/dist/builtins/debug.js +66 -13
- package/dist/builtins/debug.js.map +1 -1
- package/dist/builtins/fs/acl.args.d.ts +5 -38
- package/dist/builtins/fs/acl.args.js +6 -72
- package/dist/builtins/fs/acl.args.js.map +1 -1
- package/dist/builtins/fs/acl.d.ts +100 -10
- package/dist/builtins/fs/acl.js +222 -68
- package/dist/builtins/fs/acl.js.map +1 -1
- package/dist/builtins/fs/cat.args.d.ts +14 -15
- package/dist/builtins/fs/cat.args.js +13 -40
- package/dist/builtins/fs/cat.args.js.map +1 -1
- package/dist/builtins/fs/cat.d.ts +40 -3
- package/dist/builtins/fs/cat.js +89 -10
- package/dist/builtins/fs/cat.js.map +1 -1
- package/dist/builtins/fs/cd.d.ts +24 -6
- package/dist/builtins/fs/cd.js +71 -18
- package/dist/builtins/fs/cd.js.map +1 -1
- package/dist/builtins/fs/configWrite.d.ts +24 -8
- package/dist/builtins/fs/configWrite.js +77 -36
- package/dist/builtins/fs/configWrite.js.map +1 -1
- package/dist/builtins/fs/cp.d.ts +39 -4
- package/dist/builtins/fs/cp.js +120 -55
- package/dist/builtins/fs/cp.js.map +1 -1
- package/dist/builtins/fs/download.d.ts +12 -1
- package/dist/builtins/fs/download.js +24 -4
- package/dist/builtins/fs/download.js.map +1 -1
- package/dist/builtins/fs/du.d.ts +59 -33
- package/dist/builtins/fs/du.js +111 -79
- package/dist/builtins/fs/du.js.map +1 -1
- package/dist/builtins/fs/edit.d.ts +19 -4
- package/dist/builtins/fs/edit.js +77 -16
- package/dist/builtins/fs/edit.js.map +1 -1
- package/dist/builtins/fs/find.d.ts +25 -0
- package/dist/builtins/fs/find.js +76 -5
- package/dist/builtins/fs/find.js.map +1 -1
- package/dist/builtins/fs/mkdir.d.ts +28 -18
- package/dist/builtins/fs/mkdir.js +95 -66
- package/dist/builtins/fs/mkdir.js.map +1 -1
- package/dist/builtins/fs/mv.d.ts +34 -4
- package/dist/builtins/fs/mv.js +129 -64
- package/dist/builtins/fs/mv.js.map +1 -1
- package/dist/builtins/fs/pull.args.d.ts +56 -17
- package/dist/builtins/fs/pull.args.js +16 -66
- package/dist/builtins/fs/pull.args.js.map +1 -1
- package/dist/builtins/fs/pull.d.ts +62 -0
- package/dist/builtins/fs/pull.js +86 -22
- package/dist/builtins/fs/pull.js.map +1 -1
- package/dist/builtins/fs/pwd.d.ts +19 -5
- package/dist/builtins/fs/pwd.js +62 -8
- package/dist/builtins/fs/pwd.js.map +1 -1
- package/dist/builtins/fs/rm.d.ts +58 -21
- package/dist/builtins/fs/rm.js +99 -82
- package/dist/builtins/fs/rm.js.map +1 -1
- package/dist/builtins/fs/rmdir.d.ts +29 -11
- package/dist/builtins/fs/rmdir.js +87 -36
- package/dist/builtins/fs/rmdir.js.map +1 -1
- package/dist/builtins/fs/touch.d.ts +44 -9
- package/dist/builtins/fs/touch.js +91 -27
- package/dist/builtins/fs/touch.js.map +1 -1
- package/dist/builtins/fs/transferJobs.d.ts +64 -0
- package/dist/builtins/fs/transferJobs.js +98 -0
- package/dist/builtins/fs/transferJobs.js.map +1 -0
- package/dist/builtins/fs/tree.d.ts +36 -9
- package/dist/builtins/fs/tree.js +126 -36
- package/dist/builtins/fs/tree.js.map +1 -1
- package/dist/builtins/fs/upload.d.ts +35 -3
- package/dist/builtins/fs/upload.js +99 -14
- package/dist/builtins/fs/upload.js.map +1 -1
- package/dist/builtins/fs/xattr.args.d.ts +12 -33
- package/dist/builtins/fs/xattr.args.js +17 -95
- package/dist/builtins/fs/xattr.args.js.map +1 -1
- package/dist/builtins/fs/xattr.d.ts +98 -8
- package/dist/builtins/fs/xattr.js +163 -24
- package/dist/builtins/fs/xattr.js.map +1 -1
- package/dist/builtins/games/bytes.d.ts +201 -5
- package/dist/builtins/games/bytes.js +255 -54
- package/dist/builtins/games/bytes.js.map +1 -1
- package/dist/builtins/games/chimes.d.ts +180 -3
- package/dist/builtins/games/chimes.js +203 -26
- package/dist/builtins/games/chimes.js.map +1 -1
- package/dist/builtins/games/chrislab.d.ts +101 -3
- package/dist/builtins/games/chrislab.js +117 -17
- package/dist/builtins/games/chrislab.js.map +1 -1
- package/dist/builtins/games/cowsay.d.ts +93 -2
- package/dist/builtins/games/cowsay.js +90 -31
- package/dist/builtins/games/cowsay.js.map +1 -1
- package/dist/builtins/games/figlet.d.ts +70 -2
- package/dist/builtins/games/figlet.js +83 -6
- package/dist/builtins/games/figlet.js.map +1 -1
- package/dist/builtins/games/lab.d.ts +104 -5
- package/dist/builtins/games/lab.js +144 -6
- package/dist/builtins/games/lab.js.map +1 -1
- package/dist/builtins/games/lolcat.d.ts +61 -1
- package/dist/builtins/games/lolcat.js +59 -24
- package/dist/builtins/games/lolcat.js.map +1 -1
- package/dist/builtins/games/morse.d.ts +36 -1
- package/dist/builtins/games/morse.js +50 -2
- package/dist/builtins/games/morse.js.map +1 -1
- package/dist/builtins/games/numbers.d.ts +241 -5
- package/dist/builtins/games/numbers.js +298 -23
- package/dist/builtins/games/numbers.js.map +1 -1
- package/dist/builtins/games/play.d.ts +96 -6
- package/dist/builtins/games/play.js +137 -6
- package/dist/builtins/games/play.js.map +1 -1
- package/dist/builtins/games/qr.d.ts +40 -1
- package/dist/builtins/games/qr.js +51 -2
- package/dist/builtins/games/qr.js.map +1 -1
- package/dist/builtins/games/show.d.ts +131 -6
- package/dist/builtins/games/show.js +208 -20
- package/dist/builtins/games/show.js.map +1 -1
- package/dist/builtins/games/sky.d.ts +178 -4
- package/dist/builtins/games/sky.js +228 -12
- package/dist/builtins/games/sky.js.map +1 -1
- package/dist/builtins/games/text.d.ts +258 -7
- package/dist/builtins/games/text.js +310 -29
- package/dist/builtins/games/text.js.map +1 -1
- package/dist/builtins/games/trek.d.ts +67 -3
- package/dist/builtins/games/trek.js +63 -10
- package/dist/builtins/games/trek.js.map +1 -1
- package/dist/builtins/games/wtf.d.ts +58 -1
- package/dist/builtins/games/wtf.js +67 -6
- package/dist/builtins/games/wtf.js.map +1 -1
- package/dist/builtins/help.d.ts +38 -2
- package/dist/builtins/help.js +76 -769
- package/dist/builtins/help.js.map +1 -1
- package/dist/builtins/helpSections.js +4 -1
- package/dist/builtins/helpSections.js.map +1 -1
- package/dist/builtins/net/connect.d.ts +36 -3
- package/dist/builtins/net/connect.js +84 -26
- package/dist/builtins/net/connect.js.map +1 -1
- package/dist/builtins/net/cubepath.d.ts +49 -5
- package/dist/builtins/net/cubepath.js +69 -27
- package/dist/builtins/net/cubepath.js.map +1 -1
- package/dist/builtins/net/logout.d.ts +13 -4
- package/dist/builtins/net/logout.js +49 -3
- package/dist/builtins/net/logout.js.map +1 -1
- package/dist/builtins/net/netstat.d.ts +29 -4
- package/dist/builtins/net/netstat.js +64 -23
- package/dist/builtins/net/netstat.js.map +1 -1
- package/dist/builtins/net/pacs.d.ts +169 -15
- package/dist/builtins/net/pacs.js +92 -33
- package/dist/builtins/net/pacs.js.map +1 -1
- package/dist/builtins/net/query.args.d.ts +95 -0
- package/dist/builtins/net/query.args.js +26 -0
- package/dist/builtins/net/query.args.js.map +1 -0
- package/dist/builtins/net/query.d.ts +98 -5
- package/dist/builtins/net/query.js +89 -83
- package/dist/builtins/net/query.js.map +1 -1
- package/dist/builtins/net/status.d.ts +5 -3
- package/dist/builtins/net/status.js +5 -12
- package/dist/builtins/net/status.js.map +1 -1
- package/dist/builtins/parametersofplugin.d.ts +82 -3
- package/dist/builtins/parametersofplugin.js +79 -23
- package/dist/builtins/parametersofplugin.js.map +1 -1
- package/dist/builtins/proc.d.ts +210 -3
- package/dist/builtins/proc.js +210 -119
- package/dist/builtins/proc.js.map +1 -1
- package/dist/builtins/res/compute.d.ts +67 -3
- package/dist/builtins/res/compute.js +121 -35
- package/dist/builtins/res/compute.js.map +1 -1
- package/dist/builtins/res/dicom.d.ts +52 -3
- package/dist/builtins/res/dicom.js +82 -34
- package/dist/builtins/res/dicom.js.map +1 -1
- package/dist/builtins/res/expect.d.ts +52 -3
- package/dist/builtins/res/expect.js +92 -29
- package/dist/builtins/res/expect.js.map +1 -1
- package/dist/builtins/res/feed.d.ts +475 -3
- package/dist/builtins/res/feed.js +253 -158
- package/dist/builtins/res/feed.js.map +1 -1
- package/dist/builtins/res/files.d.ts +517 -3
- package/dist/builtins/res/files.js +124 -44
- package/dist/builtins/res/files.js.map +1 -1
- package/dist/builtins/res/gather.d.ts +113 -3
- package/dist/builtins/res/gather.js +153 -44
- package/dist/builtins/res/gather.js.map +1 -1
- package/dist/builtins/res/gather.process.d.ts +27 -19
- package/dist/builtins/res/gather.process.js +29 -59
- package/dist/builtins/res/gather.process.js.map +1 -1
- package/dist/builtins/res/group.d.ts +284 -3
- package/dist/builtins/res/group.js +147 -76
- package/dist/builtins/res/group.js.map +1 -1
- package/dist/builtins/res/image.d.ts +30 -2
- package/dist/builtins/res/image.js +62 -10
- package/dist/builtins/res/image.js.map +1 -1
- package/dist/builtins/res/play.d.ts +71 -9
- package/dist/builtins/res/play.js +124 -82
- package/dist/builtins/res/play.js.map +1 -1
- package/dist/builtins/res/plugininstance.d.ts +307 -2
- package/dist/builtins/res/plugininstance.js +122 -50
- package/dist/builtins/res/plugininstance.js.map +1 -1
- package/dist/builtins/res/pluginmeta.d.ts +244 -2
- package/dist/builtins/res/pluginmeta.js +98 -40
- package/dist/builtins/res/pluginmeta.js.map +1 -1
- package/dist/builtins/res/record.d.ts +37 -3
- package/dist/builtins/res/record.js +127 -57
- package/dist/builtins/res/record.js.map +1 -1
- package/dist/builtins/res/resourceList.d.ts +136 -0
- package/dist/builtins/res/resourceList.js +51 -0
- package/dist/builtins/res/resourceList.js.map +1 -0
- package/dist/builtins/res/tag.d.ts +244 -3
- package/dist/builtins/res/tag.js +97 -41
- package/dist/builtins/res/tag.js.map +1 -1
- package/dist/builtins/res/user.d.ts +122 -3
- package/dist/builtins/res/user.js +83 -21
- package/dist/builtins/res/user.js.map +1 -1
- package/dist/builtins/res/workflow.d.ts +244 -2
- package/dist/builtins/res/workflow.js +97 -40
- package/dist/builtins/res/workflow.js.map +1 -1
- package/dist/builtins/store.d.ts +85 -3
- package/dist/builtins/store.js +135 -68
- package/dist/builtins/store.js.map +1 -1
- package/dist/builtins/sys/apropos.d.ts +80 -5
- package/dist/builtins/sys/apropos.js +121 -15
- package/dist/builtins/sys/apropos.js.map +1 -1
- package/dist/builtins/sys/cal.d.ts +44 -5
- package/dist/builtins/sys/cal.js +57 -10
- package/dist/builtins/sys/cal.js.map +1 -1
- package/dist/builtins/sys/command.d.ts +20 -0
- package/dist/builtins/sys/command.js +31 -0
- package/dist/builtins/sys/command.js.map +1 -1
- package/dist/builtins/sys/context.d.ts +13 -3
- package/dist/builtins/sys/context.js +51 -4
- package/dist/builtins/sys/context.js.map +1 -1
- package/dist/builtins/sys/date.d.ts +56 -5
- package/dist/builtins/sys/date.js +63 -9
- package/dist/builtins/sys/date.js.map +1 -1
- package/dist/builtins/sys/echo.d.ts +63 -2
- package/dist/builtins/sys/echo.js +87 -8
- package/dist/builtins/sys/echo.js.map +1 -1
- package/dist/builtins/sys/fortune.d.ts +27 -2
- package/dist/builtins/sys/fortune.js +44 -2
- package/dist/builtins/sys/fortune.js.map +1 -1
- package/dist/builtins/sys/grep.d.ts +245 -11
- package/dist/builtins/sys/grep.js +418 -131
- package/dist/builtins/sys/grep.js.map +1 -1
- package/dist/builtins/sys/joblets.d.ts +66 -7
- package/dist/builtins/sys/joblets.js +101 -14
- package/dist/builtins/sys/joblets.js.map +1 -1
- package/dist/builtins/sys/motd.d.ts +37 -3
- package/dist/builtins/sys/motd.js +49 -8
- package/dist/builtins/sys/motd.js.map +1 -1
- package/dist/builtins/sys/notes.d.ts +75 -3
- package/dist/builtins/sys/notes.js +90 -29
- package/dist/builtins/sys/notes.js.map +1 -1
- package/dist/builtins/sys/physicalmode.d.ts +24 -3
- package/dist/builtins/sys/physicalmode.js +68 -14
- package/dist/builtins/sys/physicalmode.js.map +1 -1
- package/dist/builtins/sys/tasks.d.ts +74 -5
- package/dist/builtins/sys/tasks.js +102 -14
- package/dist/builtins/sys/tasks.js.map +1 -1
- package/dist/builtins/sys/textFilters.d.ts +673 -41
- package/dist/builtins/sys/textFilters.js +718 -263
- package/dist/builtins/sys/textFilters.js.map +1 -1
- package/dist/builtins/sys/timing.d.ts +24 -3
- package/dist/builtins/sys/timing.js +67 -14
- package/dist/builtins/sys/timing.js.map +1 -1
- package/dist/builtins/sys/variables.d.ts +70 -4
- package/dist/builtins/sys/variables.js +103 -31
- package/dist/builtins/sys/variables.js.map +1 -1
- package/dist/builtins/sys/version.d.ts +27 -2
- package/dist/builtins/sys/version.js +48 -3
- package/dist/builtins/sys/version.js.map +1 -1
- package/dist/builtins/sys/weather.d.ts +92 -15
- package/dist/builtins/sys/weather.js +71 -45
- package/dist/builtins/sys/weather.js.map +1 -1
- package/dist/builtins/sys/whoami.d.ts +38 -18
- package/dist/builtins/sys/whoami.js +112 -8
- package/dist/builtins/sys/whoami.js.map +1 -1
- package/dist/builtins/utils.d.ts +0 -37
- package/dist/builtins/utils.js +0 -86
- package/dist/builtins/utils.js.map +1 -1
- package/dist/chris/chrisCommands.js +58 -152
- package/dist/chris/chrisCommands.js.map +1 -1
- package/dist/chris/commandFallback.d.ts +12 -0
- package/dist/chris/commandFallback.js +47 -0
- package/dist/chris/commandFallback.js.map +1 -1
- package/dist/chris/filesystem.js +7 -5
- package/dist/chris/filesystem.js.map +1 -1
- package/dist/chris/help.js +0 -1018
- package/dist/chris/help.js.map +1 -1
- package/dist/chris/kinds.d.ts +21 -0
- package/dist/chris/kinds.js +114 -2
- package/dist/chris/kinds.js.map +1 -1
- package/dist/chris/mounts.d.ts +4 -4
- package/dist/chris/mounts.js +9 -16
- package/dist/chris/mounts.js.map +1 -1
- package/dist/chris/navigation.d.ts +2 -3
- package/dist/chris/navigation.js +6 -20
- package/dist/chris/navigation.js.map +1 -1
- package/dist/chris/pacsResources.d.ts +259 -0
- package/dist/chris/pacsResources.js +168 -0
- package/dist/chris/pacsResources.js.map +1 -0
- package/dist/core/commandDeclaration.d.ts +97 -7
- package/dist/core/commandDeclaration.js +21 -0
- package/dist/core/commandDeclaration.js.map +1 -1
- package/dist/core/commandParse.js +65 -17
- package/dist/core/commandParse.js.map +1 -1
- package/dist/core/commandRegistry.d.ts +4 -3
- package/dist/core/commandRegistry.js +36 -8
- package/dist/core/commandRegistry.js.map +1 -1
- package/dist/core/commandSchema.js +5 -2
- package/dist/core/commandSchema.js.map +1 -1
- package/dist/core/commandUsage.d.ts +15 -0
- package/dist/core/commandUsage.js +59 -7
- package/dist/core/commandUsage.js.map +1 -1
- package/dist/core/coreCommands.js +63 -212
- package/dist/core/coreCommands.js.map +1 -1
- package/dist/core/paths.d.ts +29 -1
- package/dist/core/paths.js +15 -2
- package/dist/core/paths.js.map +1 -1
- package/dist/core/preprocess.d.ts +3 -4
- package/dist/core/preprocess.js +4 -5
- package/dist/core/preprocess.js.map +1 -1
- package/dist/lib/completer/declared.js +7 -4
- package/dist/lib/completer/declared.js.map +1 -1
- package/dist/lib/completer/index.js +2 -7
- package/dist/lib/completer/index.js.map +1 -1
- package/dist/lib/parser.d.ts +0 -8
- package/dist/lib/parser.js +0 -11
- package/dist/lib/parser.js.map +1 -1
- package/dist/lib/vfs/vfs.d.ts +2 -1
- package/dist/lib/vfs/vfs.js +5 -4
- package/dist/lib/vfs/vfs.js.map +1 -1
- package/dist/notes.json +1 -1
- package/package.json +5 -5
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CommandEnvelope } from '@fnndsc/menu';
|
|
2
|
+
import { type ExpressionDeclaration } from '../../core/commandDeclaration.js';
|
|
2
3
|
/** The most primes `primes` lists in one call. */
|
|
3
4
|
export declare const PRIMES_MAX: number;
|
|
4
5
|
/** The prime factors of n, smallest first, with repeats. */
|
|
@@ -34,13 +35,248 @@ export declare function units_convert(value: number, from: string, to: string):
|
|
|
34
35
|
};
|
|
35
36
|
/** The unit names `units` knows, for its help and its refusals. */
|
|
36
37
|
export declare function units_known(): string[];
|
|
37
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* `factor N [N...]`: the declaration.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* commands_register({ declarations: [factorCommand] });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const factorCommand: import("../../core/commandDeclaration.js").CommandDeclaration<{
|
|
47
|
+
readonly operands: readonly [{
|
|
48
|
+
readonly name: "numbers";
|
|
49
|
+
readonly kind: "int";
|
|
50
|
+
readonly min: 1;
|
|
51
|
+
readonly max: number;
|
|
52
|
+
readonly optional: true;
|
|
53
|
+
readonly repeat: true;
|
|
54
|
+
readonly summary: "Whole numbers to factor (default: the numbers piped in)";
|
|
55
|
+
}];
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* `factor` over words already split: the declaration's parse and handler.
|
|
59
|
+
*
|
|
60
|
+
* @param args - The words after `factor`.
|
|
61
|
+
* @returns The factorisations, or the refusal of a bad line.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* await builtin_factor(['360']);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
38
68
|
export declare function builtin_factor(args: string[]): Promise<CommandEnvelope>;
|
|
39
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Factors the numbers piped in, else the numbers given.
|
|
71
|
+
*
|
|
72
|
+
* @param numbers - The numbers given, as words.
|
|
73
|
+
* @returns Each number with its prime factors, or a refusal for a word that is not a positive whole number.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* await factor_run(['360']); // 360: 2 2 2 3 3 5
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function factor_run(numbers: ReadonlyArray<string>): Promise<CommandEnvelope>;
|
|
81
|
+
/**
|
|
82
|
+
* `primes [FROM] TO`: the declaration.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* commands_register({ declarations: [primesCommand] });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare const primesCommand: import("../../core/commandDeclaration.js").CommandDeclaration<{
|
|
90
|
+
readonly operands: readonly [{
|
|
91
|
+
readonly name: "numbers";
|
|
92
|
+
readonly kind: "int";
|
|
93
|
+
readonly repeat: true;
|
|
94
|
+
readonly summary: "[FROM] TO";
|
|
95
|
+
}];
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* `primes` over words already split: the declaration's parse and handler.
|
|
99
|
+
*
|
|
100
|
+
* @param args - The words after `primes`.
|
|
101
|
+
* @returns The primes, or the refusal of a bad line.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* await builtin_primes(['20']);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
40
108
|
export declare function builtin_primes(args: string[]): Promise<CommandEnvelope>;
|
|
41
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Lists the primes in a range.
|
|
111
|
+
*
|
|
112
|
+
* @param nums - `TO`, or `FROM` and `TO`.
|
|
113
|
+
* @returns The primes on one line, or a refusal for a wrong count of numbers.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* await primes_run([1000, 1100]);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function primes_run(nums: ReadonlyArray<number>): Promise<CommandEnvelope>;
|
|
121
|
+
/**
|
|
122
|
+
* `roll [NdS[+M]...]`: the declaration.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* commands_register({ declarations: [rollCommand] });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare const rollCommand: import("../../core/commandDeclaration.js").CommandDeclaration<{
|
|
130
|
+
readonly operands: readonly [{
|
|
131
|
+
readonly name: "dice";
|
|
132
|
+
readonly kind: "word";
|
|
133
|
+
readonly optional: true;
|
|
134
|
+
readonly repeat: true;
|
|
135
|
+
readonly summary: "Dice as NdS[+M] (default 1d6)";
|
|
136
|
+
}];
|
|
137
|
+
}>;
|
|
138
|
+
/**
|
|
139
|
+
* `roll` over words already split: the declaration's parse and handler.
|
|
140
|
+
*
|
|
141
|
+
* @param args - The words after `roll`.
|
|
142
|
+
* @returns The rolls, or the refusal of a bad line.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* await builtin_roll(['2d6']);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
42
149
|
export declare function builtin_roll(args: string[]): Promise<CommandEnvelope>;
|
|
43
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Rolls each die spec, one six-sided die when there are none.
|
|
152
|
+
*
|
|
153
|
+
* @param dice - The specs, as `NdS[+M]`.
|
|
154
|
+
* @returns Each spec's faces and total, or a refusal for a spec that is not dice.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* await roll_run(['2d6+1']);
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare function roll_run(dice: ReadonlyArray<string>): Promise<CommandEnvelope>;
|
|
162
|
+
/**
|
|
163
|
+
* `calc EXPRESSION`: the declaration. Its words are an arithmetic
|
|
164
|
+
* expression, so one may begin with a dash (`calc -3+4`): it takes them
|
|
165
|
+
* as they come, parsing none as an option.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* commands_register({ declarations: [calcCommand] });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare const calcCommand: ExpressionDeclaration;
|
|
173
|
+
/**
|
|
174
|
+
* `calc` over words already split.
|
|
175
|
+
*
|
|
176
|
+
* @param args - The words after `calc`.
|
|
177
|
+
* @returns The value, or the refusal of a malformed expression.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* await builtin_calc(['2^10']);
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
44
184
|
export declare function builtin_calc(args: string[]): Promise<CommandEnvelope>;
|
|
45
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* Evaluates the piped expression, else the words joined.
|
|
187
|
+
*
|
|
188
|
+
* @param words - The words of the expression.
|
|
189
|
+
* @returns The value, or a refusal naming what is wrong with the expression.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* await calc_run(['-3+4']); // 1
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export declare function calc_run(words: ReadonlyArray<string>): Promise<CommandEnvelope>;
|
|
197
|
+
/**
|
|
198
|
+
* `units VALUE FROM [to] TO | units list`: the declaration.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* commands_register({ declarations: [unitsCommand] });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export declare const unitsCommand: import("../../core/commandDeclaration.js").CommandDeclaration<{
|
|
206
|
+
readonly operands: readonly [{
|
|
207
|
+
readonly name: "value";
|
|
208
|
+
readonly kind: "number";
|
|
209
|
+
readonly summary: "The quantity";
|
|
210
|
+
}, {
|
|
211
|
+
readonly name: "from";
|
|
212
|
+
readonly kind: "word";
|
|
213
|
+
readonly summary: "The unit it is in";
|
|
214
|
+
}, {
|
|
215
|
+
readonly name: "to";
|
|
216
|
+
readonly kind: "word";
|
|
217
|
+
readonly summary: "The unit to give it in (or the joining word to, in or as, then the unit)";
|
|
218
|
+
}, {
|
|
219
|
+
readonly name: "target";
|
|
220
|
+
readonly kind: "word";
|
|
221
|
+
readonly optional: true;
|
|
222
|
+
readonly summary: "The unit to give it in, after the joining word";
|
|
223
|
+
}];
|
|
224
|
+
readonly subcommands: {
|
|
225
|
+
readonly list: {
|
|
226
|
+
readonly summary: "Name the units known";
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
readonly bare: {
|
|
230
|
+
readonly summary: "Convert a quantity";
|
|
231
|
+
};
|
|
232
|
+
}>;
|
|
233
|
+
/**
|
|
234
|
+
* `units` over words already split: the declaration's parse and handler.
|
|
235
|
+
*
|
|
236
|
+
* @param args - The words after `units`.
|
|
237
|
+
* @returns The conversion, or the refusal of a bad line.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* await builtin_units(['10', 'mm', 'in']);
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
46
244
|
export declare function builtin_units(args: string[]): Promise<CommandEnvelope>;
|
|
245
|
+
/**
|
|
246
|
+
* The unit a conversion is to: the third word, or the fourth after a joining word.
|
|
247
|
+
*
|
|
248
|
+
* @param to - The third word.
|
|
249
|
+
* @param target - The fourth word, when there is one.
|
|
250
|
+
* @returns The destination unit, or null when a fourth word follows a third that is not `to`, `in` or `as`.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* units_destination('to', 'in'); // 'in'
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
export declare function units_destination(to: string, target: string | undefined): string | null;
|
|
258
|
+
/**
|
|
259
|
+
* Names every unit `units` knows.
|
|
260
|
+
*
|
|
261
|
+
* @returns The names on one line.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* await unitsList_run();
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
export declare function unitsList_run(): Promise<CommandEnvelope>;
|
|
269
|
+
/**
|
|
270
|
+
* Converts a quantity and says so.
|
|
271
|
+
*
|
|
272
|
+
* @param value - The quantity.
|
|
273
|
+
* @param from - The unit it is in.
|
|
274
|
+
* @param to - The unit to give it in.
|
|
275
|
+
* @returns The conversion, or a refusal naming the unit or kind that does not fit.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* await units_run(10, 'mm', 'in'); // 10 mm = 0.3937007874 in
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
export declare function units_run(value: number, from: string, to: string): Promise<CommandEnvelope>;
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { text_input } from './stdin.js';
|
|
11
11
|
import { envelope_ok, envelope_error } from '@fnndsc/menu';
|
|
12
|
+
import { command_declare } from '../../core/commandDeclaration.js';
|
|
13
|
+
import { declaredCommand_run } from '../../core/commandParse.js';
|
|
12
14
|
/** The most primes `primes` lists in one call. */
|
|
13
15
|
export const PRIMES_MAX = 10_000;
|
|
14
16
|
/** The prime factors of n, smallest first, with repeats. */
|
|
@@ -192,10 +194,58 @@ export function units_convert(value, from, to) {
|
|
|
192
194
|
export function units_known() {
|
|
193
195
|
return Object.keys(UNITS);
|
|
194
196
|
}
|
|
195
|
-
/*
|
|
196
|
-
/** `factor
|
|
197
|
+
/* ----------------------------------------------------- declarations */
|
|
198
|
+
/** What a `factor` line may hold. */
|
|
199
|
+
const FACTOR_GRAMMAR = {
|
|
200
|
+
operands: [{ name: 'numbers', kind: 'int', min: 1, max: Number.MAX_SAFE_INTEGER, optional: true, repeat: true, summary: 'Whole numbers to factor (default: the numbers piped in)' }],
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* `factor N [N...]`: the declaration.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* commands_register({ declarations: [factorCommand] });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export const factorCommand = command_declare({
|
|
211
|
+
name: 'factor',
|
|
212
|
+
grammar: FACTOR_GRAMMAR,
|
|
213
|
+
help: {
|
|
214
|
+
summary: 'Prime factors of a number',
|
|
215
|
+
description: 'Prints each number with its prime factors, smallest first, repeats included, as factor does.',
|
|
216
|
+
examples: ['factor 360', 'factor 2026 1729'],
|
|
217
|
+
posix: { group: 'System', differs: 'as factor' },
|
|
218
|
+
},
|
|
219
|
+
holds: [],
|
|
220
|
+
handler: async (args) => factor_run(args.operands.numbers.map(String)),
|
|
221
|
+
});
|
|
222
|
+
/**
|
|
223
|
+
* `factor` over words already split: the declaration's parse and handler.
|
|
224
|
+
*
|
|
225
|
+
* @param args - The words after `factor`.
|
|
226
|
+
* @returns The factorisations, or the refusal of a bad line.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* await builtin_factor(['360']);
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
197
233
|
export async function builtin_factor(args) {
|
|
198
|
-
|
|
234
|
+
return declaredCommand_run(factorCommand, args);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Factors the numbers piped in, else the numbers given.
|
|
238
|
+
*
|
|
239
|
+
* @param numbers - The numbers given, as words.
|
|
240
|
+
* @returns Each number with its prime factors, or a refusal for a word that is not a positive whole number.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* await factor_run(['360']); // 360: 2 2 2 3 3 5
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
export async function factor_run(numbers) {
|
|
248
|
+
const words = text_input(numbers)?.trim().split(/\s+/) ?? [];
|
|
199
249
|
if (words.length === 0)
|
|
200
250
|
return envelope_error('', undefined, 'factor: usage: factor N [N...]\n');
|
|
201
251
|
const lines = [];
|
|
@@ -210,20 +260,112 @@ export async function builtin_factor(args) {
|
|
|
210
260
|
}
|
|
211
261
|
return envelope_ok(`${lines.join('\n')}\n`, { kind: 'games.factor', data: { numbers: data } });
|
|
212
262
|
}
|
|
213
|
-
/** `primes
|
|
263
|
+
/** What a `primes` line may hold. */
|
|
264
|
+
const PRIMES_GRAMMAR = {
|
|
265
|
+
operands: [{ name: 'numbers', kind: 'int', repeat: true, summary: '[FROM] TO' }],
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* `primes [FROM] TO`: the declaration.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* commands_register({ declarations: [primesCommand] });
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export const primesCommand = command_declare({
|
|
276
|
+
name: 'primes',
|
|
277
|
+
grammar: PRIMES_GRAMMAR,
|
|
278
|
+
help: {
|
|
279
|
+
summary: 'The primes up to a number',
|
|
280
|
+
description: 'Lists the primes from FROM (2 when omitted) to TO, at most 10000 of them.',
|
|
281
|
+
examples: ['primes 100', 'primes 1000 1100'],
|
|
282
|
+
posix: { group: 'System', differs: 'as primes' },
|
|
283
|
+
},
|
|
284
|
+
holds: [],
|
|
285
|
+
handler: async (args) => primes_run(args.operands.numbers),
|
|
286
|
+
});
|
|
287
|
+
/**
|
|
288
|
+
* `primes` over words already split: the declaration's parse and handler.
|
|
289
|
+
*
|
|
290
|
+
* @param args - The words after `primes`.
|
|
291
|
+
* @returns The primes, or the refusal of a bad line.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* await builtin_primes(['20']);
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
214
298
|
export async function builtin_primes(args) {
|
|
215
|
-
|
|
216
|
-
|
|
299
|
+
return declaredCommand_run(primesCommand, args);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Lists the primes in a range.
|
|
303
|
+
*
|
|
304
|
+
* @param nums - `TO`, or `FROM` and `TO`.
|
|
305
|
+
* @returns The primes on one line, or a refusal for a wrong count of numbers.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* await primes_run([1000, 1100]);
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
export async function primes_run(nums) {
|
|
313
|
+
if (nums.length === 0 || nums.length > 2)
|
|
217
314
|
return envelope_error('', undefined, 'primes: usage: primes [FROM] TO\n');
|
|
218
|
-
}
|
|
219
315
|
const [from, to] = nums.length === 1 ? [2, nums[0]] : [nums[0], nums[1]];
|
|
220
316
|
const primes = primes_between(from, to);
|
|
221
317
|
const note = primes.length >= PRIMES_MAX ? `primes: stopped at ${PRIMES_MAX}\n` : '';
|
|
222
318
|
return envelope_ok(`${primes.join(' ')}\n${note}`, { kind: 'games.primes', data: { from, to, primes } });
|
|
223
319
|
}
|
|
224
|
-
/** `roll
|
|
320
|
+
/** What a `roll` line may hold. */
|
|
321
|
+
const ROLL_GRAMMAR = {
|
|
322
|
+
operands: [{ name: 'dice', kind: 'word', optional: true, repeat: true, summary: 'Dice as NdS[+M] (default 1d6)' }],
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* `roll [NdS[+M]...]`: the declaration.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```ts
|
|
329
|
+
* commands_register({ declarations: [rollCommand] });
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
export const rollCommand = command_declare({
|
|
333
|
+
name: 'roll',
|
|
334
|
+
grammar: ROLL_GRAMMAR,
|
|
335
|
+
help: {
|
|
336
|
+
summary: 'Roll dice: roll 2d6+1, roll d20',
|
|
337
|
+
description: 'Rolls dice written the tabletop way: N dice of S sides, plus or minus a modifier. Bare roll is one six-sided die. Shows each face and the total.',
|
|
338
|
+
examples: ['roll', 'roll 2d6', 'roll d20 3d8+2'],
|
|
339
|
+
},
|
|
340
|
+
handler: async (args) => roll_run(args.operands.dice),
|
|
341
|
+
});
|
|
342
|
+
/**
|
|
343
|
+
* `roll` over words already split: the declaration's parse and handler.
|
|
344
|
+
*
|
|
345
|
+
* @param args - The words after `roll`.
|
|
346
|
+
* @returns The rolls, or the refusal of a bad line.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* await builtin_roll(['2d6']);
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
225
353
|
export async function builtin_roll(args) {
|
|
226
|
-
|
|
354
|
+
return declaredCommand_run(rollCommand, args);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Rolls each die spec, one six-sided die when there are none.
|
|
358
|
+
*
|
|
359
|
+
* @param dice - The specs, as `NdS[+M]`.
|
|
360
|
+
* @returns Each spec's faces and total, or a refusal for a spec that is not dice.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```ts
|
|
364
|
+
* await roll_run(['2d6+1']);
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
export async function roll_run(dice) {
|
|
368
|
+
const specs = dice.length === 0 ? ['1d6'] : dice;
|
|
227
369
|
const lines = [];
|
|
228
370
|
const data = [];
|
|
229
371
|
for (const spec of specs) {
|
|
@@ -236,9 +378,55 @@ export async function builtin_roll(args) {
|
|
|
236
378
|
}
|
|
237
379
|
return envelope_ok(`${lines.join('\n')}\n`, { kind: 'games.roll', data: { rolls: data } });
|
|
238
380
|
}
|
|
239
|
-
/**
|
|
381
|
+
/**
|
|
382
|
+
* `calc EXPRESSION`: the declaration. Its words are an arithmetic
|
|
383
|
+
* expression, so one may begin with a dash (`calc -3+4`): it takes them
|
|
384
|
+
* as they come, parsing none as an option.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* commands_register({ declarations: [calcCommand] });
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
export const calcCommand = {
|
|
392
|
+
name: 'calc',
|
|
393
|
+
grammar: 'expression',
|
|
394
|
+
help: {
|
|
395
|
+
usage: 'calc <expression>',
|
|
396
|
+
summary: 'Arithmetic: calc 2^10, calc sqrt(2)*pi',
|
|
397
|
+
description: 'Evaluates an arithmetic expression: + - * / % ^, parentheses, sqrt, abs, ln, log, log2, exp, sin, cos, tan, asin, acos, atan, floor, ceil, round, and the constants pi, e and tau. No shell is involved. Its words are the expression, so one may begin with a dash: calc -3+4.',
|
|
398
|
+
examples: ['calc 2^10', 'calc (3+4)*5', 'calc sqrt(2)*pi', 'calc 1024*1024'],
|
|
399
|
+
},
|
|
400
|
+
holds: [],
|
|
401
|
+
handler: (args) => calc_run(args),
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* `calc` over words already split.
|
|
405
|
+
*
|
|
406
|
+
* @param args - The words after `calc`.
|
|
407
|
+
* @returns The value, or the refusal of a malformed expression.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* await builtin_calc(['2^10']);
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
240
414
|
export async function builtin_calc(args) {
|
|
241
|
-
|
|
415
|
+
return calc_run(args);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Evaluates the piped expression, else the words joined.
|
|
419
|
+
*
|
|
420
|
+
* @param words - The words of the expression.
|
|
421
|
+
* @returns The value, or a refusal naming what is wrong with the expression.
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```ts
|
|
425
|
+
* await calc_run(['-3+4']); // 1
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
export async function calc_run(words) {
|
|
429
|
+
const expression = text_input(words);
|
|
242
430
|
if (expression === null)
|
|
243
431
|
return envelope_error('', undefined, 'calc: usage: calc <expression> (e.g. calc 2^10, calc sqrt(2)*pi)\n');
|
|
244
432
|
try {
|
|
@@ -250,21 +438,108 @@ export async function builtin_calc(args) {
|
|
|
250
438
|
return envelope_error('', undefined, `${error instanceof Error ? error.message : String(error)}\n`);
|
|
251
439
|
}
|
|
252
440
|
}
|
|
253
|
-
/** `units
|
|
441
|
+
/** What a `units` line may hold: a conversion, or `list`. */
|
|
442
|
+
const UNITS_GRAMMAR = {
|
|
443
|
+
operands: [
|
|
444
|
+
{ name: 'value', kind: 'number', summary: 'The quantity' },
|
|
445
|
+
{ name: 'from', kind: 'word', summary: 'The unit it is in' },
|
|
446
|
+
{ name: 'to', kind: 'word', summary: 'The unit to give it in (or the joining word to, in or as, then the unit)' },
|
|
447
|
+
{ name: 'target', kind: 'word', optional: true, summary: 'The unit to give it in, after the joining word' },
|
|
448
|
+
],
|
|
449
|
+
subcommands: {
|
|
450
|
+
list: { summary: 'Name the units known' },
|
|
451
|
+
},
|
|
452
|
+
bare: { summary: 'Convert a quantity' },
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* `units VALUE FROM [to] TO | units list`: the declaration.
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```ts
|
|
459
|
+
* commands_register({ declarations: [unitsCommand] });
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
export const unitsCommand = command_declare({
|
|
463
|
+
name: 'units',
|
|
464
|
+
grammar: UNITS_GRAMMAR,
|
|
465
|
+
help: {
|
|
466
|
+
summary: 'Convert between units: units 10 mm in',
|
|
467
|
+
description: 'Converts a quantity between two units of one kind: length (mm cm m km in ft yd mi), mass (g kg mg lb oz), time (ms s min h d wk yr), data (B kB MB GB TB KiB MiB GiB TiB bit) and temperature (C F K). units list names them all. The line is units VALUE FROM [to] TO, or units list.',
|
|
468
|
+
examples: ['units 10 mm in', 'units 72 F to C', 'units 1 GiB MB', 'units list'],
|
|
469
|
+
posix: { group: 'System', differs: 'a small set of conversions' },
|
|
470
|
+
},
|
|
471
|
+
holds: [],
|
|
472
|
+
handler: async (args) => {
|
|
473
|
+
if (args.subcommand === 'list')
|
|
474
|
+
return unitsList_run();
|
|
475
|
+
const destination = units_destination(args.operands.to, args.operands.target);
|
|
476
|
+
if (destination === null)
|
|
477
|
+
return envelope_error('', undefined, 'units: usage: units VALUE FROM [to] TO (units list names the units)\n');
|
|
478
|
+
return units_run(args.operands.value, args.operands.from, destination);
|
|
479
|
+
},
|
|
480
|
+
});
|
|
481
|
+
/**
|
|
482
|
+
* `units` over words already split: the declaration's parse and handler.
|
|
483
|
+
*
|
|
484
|
+
* @param args - The words after `units`.
|
|
485
|
+
* @returns The conversion, or the refusal of a bad line.
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* ```ts
|
|
489
|
+
* await builtin_units(['10', 'mm', 'in']);
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
254
492
|
export async function builtin_units(args) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
493
|
+
return declaredCommand_run(unitsCommand, args);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* The unit a conversion is to: the third word, or the fourth after a joining word.
|
|
497
|
+
*
|
|
498
|
+
* @param to - The third word.
|
|
499
|
+
* @param target - The fourth word, when there is one.
|
|
500
|
+
* @returns The destination unit, or null when a fourth word follows a third that is not `to`, `in` or `as`.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```ts
|
|
504
|
+
* units_destination('to', 'in'); // 'in'
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
export function units_destination(to, target) {
|
|
508
|
+
if (target === undefined)
|
|
509
|
+
return to;
|
|
510
|
+
return /^(to|in|as)$/i.test(to) ? target : null;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Names every unit `units` knows.
|
|
514
|
+
*
|
|
515
|
+
* @returns The names on one line.
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```ts
|
|
519
|
+
* await unitsList_run();
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
export async function unitsList_run() {
|
|
523
|
+
return envelope_ok(`${units_known().join(' ')}\n`, { kind: 'games.units', data: { known: units_known() } });
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Converts a quantity and says so.
|
|
527
|
+
*
|
|
528
|
+
* @param value - The quantity.
|
|
529
|
+
* @param from - The unit it is in.
|
|
530
|
+
* @param to - The unit to give it in.
|
|
531
|
+
* @returns The conversion, or a refusal naming the unit or kind that does not fit.
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```ts
|
|
535
|
+
* await units_run(10, 'mm', 'in'); // 10 mm = 0.3937007874 in
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
export async function units_run(value, from, to) {
|
|
539
|
+
const r = units_convert(value, from, to);
|
|
265
540
|
if ('refusal' in r)
|
|
266
541
|
return envelope_error('', undefined, `${r.refusal}\n`);
|
|
267
542
|
const shown = String(Number(r.value.toPrecision(10)));
|
|
268
|
-
return envelope_ok(`${value} ${
|
|
543
|
+
return envelope_ok(`${value} ${from} = ${shown} ${to}\n`, { kind: 'games.units', data: { value, from, to, result: r.value } });
|
|
269
544
|
}
|
|
270
545
|
//# sourceMappingURL=numbers.js.map
|