@bemoje/cli 0.0.2

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 (120) hide show
  1. package/README.md +34 -0
  2. package/index.cjs.d.ts +1 -0
  3. package/index.cjs.js +2682 -0
  4. package/index.esm.js +2558 -0
  5. package/package.json +36 -0
  6. package/src/core/CommandBuilder/ArgumentBuilder.d.ts +21 -0
  7. package/src/core/CommandBuilder/ArgumentReader.d.ts +15 -0
  8. package/src/core/CommandBuilder/Base.d.ts +5 -0
  9. package/src/core/CommandBuilder/CommandBuilder.d.ts +80 -0
  10. package/src/core/CommandBuilder/CommandBuilder.example.d.ts +1 -0
  11. package/src/core/CommandBuilder/CommandBuilderMetaData.d.ts +17 -0
  12. package/src/core/CommandBuilder/CommandFeatureSelector.d.ts +26 -0
  13. package/src/core/CommandBuilder/ErrorParser.d.ts +15 -0
  14. package/src/core/CommandBuilder/OptionBuilder.d.ts +27 -0
  15. package/src/core/CommandBuilder/OptionReader.d.ts +24 -0
  16. package/src/core/CommandBuilder/OutputManager.d.ts +47 -0
  17. package/src/core/CommandBuilder/assertCommandNameNotReserved.d.ts +1 -0
  18. package/src/core/CommandBuilder/ensureBackRefToCommandBuilder.d.ts +7 -0
  19. package/src/core/CommandBuilder/features/action/actionWrapper.d.ts +5 -0
  20. package/src/core/CommandBuilder/features/action/combineVariadicArgs.d.ts +3 -0
  21. package/src/core/CommandBuilder/features/action/debugLogArgsOpts.d.ts +4 -0
  22. package/src/core/CommandBuilder/features/action/deleteOptionsWithDefaultOrNoValue.d.ts +3 -0
  23. package/src/core/CommandBuilder/features/action/getPresetArgsAndOpts.d.ts +3 -0
  24. package/src/core/CommandBuilder/features/action/handleError.d.ts +2 -0
  25. package/src/core/CommandBuilder/features/action/handleOutputOptions.d.ts +2 -0
  26. package/src/core/CommandBuilder/features/action/optsWithGlobalsParsed.d.ts +2 -0
  27. package/src/core/CommandBuilder/features/action/padArgsWithUndefinedUntilExpectedLength.d.ts +3 -0
  28. package/src/core/CommandBuilder/features/action/parseArguments.d.ts +2 -0
  29. package/src/core/CommandBuilder/features/action/parseOptions.d.ts +6 -0
  30. package/src/core/CommandBuilder/features/action/parsedValidArgsOptsWithPresets.d.ts +2 -0
  31. package/src/core/CommandBuilder/features/action/parsedValidArgsWithPresets.d.ts +2 -0
  32. package/src/core/CommandBuilder/features/action/parsedValidOptsWithPresets.d.ts +3 -0
  33. package/src/core/CommandBuilder/features/addConfigCommands.d.ts +3 -0
  34. package/src/core/CommandBuilder/features/addPresetsCommands.d.ts +3 -0
  35. package/src/core/CommandBuilder/features/addUtilCommands.d.ts +2 -0
  36. package/src/core/CommandBuilder/features/assertNoDuplicateCommandNames.d.ts +2 -0
  37. package/src/core/CommandBuilder/features/assertNoDuplicateOptionNames.d.ts +2 -0
  38. package/src/core/CommandBuilder/features/autoAssignMissingOptionFlags.d.ts +14 -0
  39. package/src/core/CommandBuilder/features/autoAssignSubCommandAliases.d.ts +13 -0
  40. package/src/core/CommandBuilder/features/formatTableForTerminal.d.ts +1 -0
  41. package/src/core/CommandBuilder/features/getClosestNonNativeParent.d.ts +2 -0
  42. package/src/core/CommandBuilder/getGlobalOptions.d.ts +3 -0
  43. package/src/core/CommandBuilder/getOwnAndGlobalOptions.d.ts +3 -0
  44. package/src/core/CommandBuilder/initializeCommand.d.ts +2 -0
  45. package/src/core/db/AbstractJsonFileSection.d.ts +45 -0
  46. package/src/core/db/ConfigSection.d.ts +19 -0
  47. package/src/core/db/JsonDB.d.ts +19 -0
  48. package/src/core/db/JsonFile.d.ts +25 -0
  49. package/src/core/db/JsonFileError.d.ts +6 -0
  50. package/src/core/db/PresetsSection.d.ts +14 -0
  51. package/src/core/help/configureHelp.d.ts +2 -0
  52. package/src/core/util/MethodDisabler.d.ts +42 -0
  53. package/src/core/util/arrAssign.d.ts +1 -0
  54. package/src/core/util/assertPresetArgsOptional.d.ts +3 -0
  55. package/src/core/util/assertValidArguments.d.ts +6 -0
  56. package/src/core/util/assertValidOptions.d.ts +6 -0
  57. package/src/core/util/assertValidPreset.d.ts +3 -0
  58. package/src/core/util/commandExists.d.ts +5 -0
  59. package/src/core/util/commandLocation.d.ts +5 -0
  60. package/src/core/util/createArrayMerger.d.ts +1 -0
  61. package/src/core/util/createObjectMerger.d.ts +2 -0
  62. package/src/core/util/errorToString.d.ts +1 -0
  63. package/src/core/util/escapeShellCommandArgument.d.ts +5 -0
  64. package/src/core/util/forEachChildRecursive.d.ts +4 -0
  65. package/src/core/util/getARGV.d.ts +1 -0
  66. package/src/core/util/getAncestors.d.ts +7 -0
  67. package/src/core/util/getChildren.d.ts +4 -0
  68. package/src/core/util/getJsonFilepath.d.ts +2 -0
  69. package/src/core/util/getOptionArgumentName.d.ts +5 -0
  70. package/src/core/util/getRootCommand.d.ts +5 -0
  71. package/src/core/util/getSiblings.d.ts +5 -0
  72. package/src/core/util/hasVariadicArguments.d.ts +5 -0
  73. package/src/core/util/objAssign.d.ts +1 -0
  74. package/src/core/util/objDestroy.d.ts +2 -0
  75. package/src/core/util/optHasArgument.d.ts +2 -0
  76. package/src/core/util/prefixArray.d.ts +5 -0
  77. package/src/core/util/prefixString.d.ts +5 -0
  78. package/src/core/util/prefixStringsRecursive.d.ts +5 -0
  79. package/src/core/util/realizeLazyProperty.d.ts +1 -0
  80. package/src/core/util/renderOptionFlags.d.ts +6 -0
  81. package/src/core/util/setOptionLongName.d.ts +6 -0
  82. package/src/core/util/setOptionShortName.d.ts +6 -0
  83. package/src/core/util/splitCombinedArgvShorts.d.ts +1 -0
  84. package/src/core/util/walkAncestors.d.ts +7 -0
  85. package/src/core/util/walkChildren.d.ts +4 -0
  86. package/src/core/util/walkSiblings.d.ts +5 -0
  87. package/src/index.d.ts +113 -0
  88. package/src/parsers/createBooleanParser.d.ts +7 -0
  89. package/src/parsers/createTupleListParser.d.ts +11 -0
  90. package/src/parsers/createTypedListParser.d.ts +11 -0
  91. package/src/parsers/parseBoolean.d.ts +10 -0
  92. package/src/parsers/parseInteger.d.ts +1 -0
  93. package/src/parsers/parseNumber.d.ts +1 -0
  94. package/src/parsers/parseString.d.ts +1 -0
  95. package/src/parsers/selector/AbstractStringParserSelector.d.ts +17 -0
  96. package/src/parsers/selector/ArgumentParserSelector.d.ts +7 -0
  97. package/src/parsers/selector/OptionArgumentParserSelector.d.ts +7 -0
  98. package/src/types/IDefinePropertyOptions.d.ts +9 -0
  99. package/src/types/IPreset.d.ts +14 -0
  100. package/src/types/IPresets.d.ts +6 -0
  101. package/src/types/TStringParser.d.ts +1 -0
  102. package/src/types/TValidator.d.ts +2 -0
  103. package/src/validators/createLengthValidator.d.ts +7 -0
  104. package/src/validators/createTypedArrayValidator.d.ts +11 -0
  105. package/src/validators/isArray.d.ts +1 -0
  106. package/src/validators/isBoolean.d.ts +1 -0
  107. package/src/validators/isInteger.d.ts +1 -0
  108. package/src/validators/isIntegerArray.d.ts +4 -0
  109. package/src/validators/isNamedFunction.d.ts +5 -0
  110. package/src/validators/isNamedFunctionArray.d.ts +1 -0
  111. package/src/validators/isNull.d.ts +1 -0
  112. package/src/validators/isNumber.d.ts +1 -0
  113. package/src/validators/isNumberArray.d.ts +4 -0
  114. package/src/validators/isNumericString.d.ts +1 -0
  115. package/src/validators/isString.d.ts +1 -0
  116. package/src/validators/isStringArray.d.ts +4 -0
  117. package/src/validators/isStringWithNoSpacesOrDashes.d.ts +1 -0
  118. package/src/validators/selector/ArgumentValidatorSelector.d.ts +6 -0
  119. package/src/validators/selector/OptionArgumentValidatorSelector.d.ts +6 -0
  120. package/src/validators/selector/ValidatorSelector.d.ts +17 -0
@@ -0,0 +1,42 @@
1
+ import { Any, ObjectKey, TFunctionNoNew } from '@bemoje/util';
2
+ import { Base } from '../CommandBuilder/Base';
3
+ /**
4
+ * A class that creates an object with methods for disabling/enabling a given method on a given object.
5
+ *
6
+ * @example
7
+ * const md = new MethodDisabler(process.stdout, 'write')
8
+ *
9
+ * md.disable()
10
+ * assert(!md.isEnabled)
11
+ * console.log('This will not print')
12
+ *
13
+ * md.enable()
14
+ * assert(md.isEnabled)
15
+ * console.log('This will print')
16
+ *
17
+ * assert(md.original === process.stdout.write)
18
+ */
19
+ export declare class MethodDisabler extends Base {
20
+ #private;
21
+ /**
22
+ * @param obj - The object on which the method is defined.
23
+ * @param key - The property name of the method.
24
+ */
25
+ constructor(obj: Record<ObjectKey, Any>, key: string);
26
+ /**
27
+ * Disable the method.
28
+ */
29
+ disable(): void;
30
+ /**
31
+ * Enable the method.
32
+ */
33
+ enable(): void;
34
+ /**
35
+ * The original method before it was disabled.
36
+ */
37
+ get original(): TFunctionNoNew;
38
+ /**
39
+ * Whether the method is currently enabled.
40
+ */
41
+ get isEnabled(): boolean;
42
+ }
@@ -0,0 +1 @@
1
+ export declare const arrAssign: <E extends unknown>(target: E[], ...sources: E[][]) => E[];
@@ -0,0 +1,3 @@
1
+ import { Any } from '@bemoje/util';
2
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
3
+ export declare function assertPresetArgsOptional(cmd: CommandBuilder, args: Any[]): void;
@@ -0,0 +1,6 @@
1
+ import { Any } from '@bemoje/util';
2
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
3
+ /**
4
+ * Validate ALREADY PARSED args using the validators defined in the command builder.
5
+ */
6
+ export declare function assertValidArguments(cmd: CommandBuilder, parsedArgs: Any[]): any[];
@@ -0,0 +1,6 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ import { OptionValues } from 'commander';
3
+ /**
4
+ * Validate ALREADY PARSED options using the validators defined in the command builder.
5
+ */
6
+ export declare function assertValidOptions(cb: CommandBuilder, parsedOptions: OptionValues): OptionValues;
@@ -0,0 +1,3 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ import { IPreset } from '../../types/IPreset';
3
+ export declare function assertValidPreset(cmd: CommandBuilder, key: string, preset: IPreset): void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Check whether a command exists in the PATH.
3
+ * @param command The command to check for.
4
+ */
5
+ export declare function commandExists(command: string): Promise<boolean>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Get the absolute file path of given command or undefined it does not exist in the PATH.
3
+ * @param command The command to check for.
4
+ */
5
+ export declare function commandLocation(command: string): Promise<undefined | string>;
@@ -0,0 +1 @@
1
+ export declare function createArrayMerger<T>(predicate: (value: T, index: number, arr: T[]) => boolean): <E extends T>(target: E[], ...sources: E[][]) => E[];
@@ -0,0 +1,2 @@
1
+ import { Any } from '@bemoje/util';
2
+ export declare function createObjectMerger(predicate: (value: Any, key: string, obj: Record<string, Any>) => boolean): (target: Record<string, Any>, ...sources: Record<string, Any>[]) => Record<string, any>;
@@ -0,0 +1 @@
1
+ export declare function errorToString(error: unknown): string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Escape a string to be used as a shell command argument.
3
+ * Wraps in double quotes only if necessary.
4
+ */
5
+ export declare function escapeShellCommandArgument(command: string): string;
@@ -0,0 +1,4 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ export declare function forEachChildRecursive(cmd: CommandBuilder, callback: (cmd: CommandBuilder) => void | true, options?: {
3
+ includeSelf?: boolean;
4
+ }): void | true;
@@ -0,0 +1 @@
1
+ export declare function getARGV(argv?: string[]): string[];
@@ -0,0 +1,7 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ /**
3
+ * Get a command's ancestors, optionally starting from the command itself.
4
+ */
5
+ export declare function getAncestors(cmd: CommandBuilder, options?: {
6
+ includeSelf?: boolean;
7
+ }): CommandBuilder[];
@@ -0,0 +1,4 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ export declare function getChildren(cmd: CommandBuilder, options?: {
3
+ includeSelf?: boolean;
4
+ }): CommandBuilder[];
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ export declare function getJsonFilepath(cmd: CommandBuilder): string;
@@ -0,0 +1,5 @@
1
+ import { Option } from 'commander';
2
+ /**
3
+ * Extract the argument name from an option's 'flags' string.
4
+ */
5
+ export declare function getOptionArgumentName(opt: Option): string | undefined;
@@ -0,0 +1,5 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ /**
3
+ * Get the command at the root of the command tree.
4
+ */
5
+ export declare function getRootCommand(cmd: CommandBuilder): CommandBuilder;
@@ -0,0 +1,5 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ /**
3
+ * Returns an array of sibling CommandBuilder objects.
4
+ */
5
+ export declare function getSiblings(cmd: CommandBuilder): CommandBuilder[];
@@ -0,0 +1,5 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ /**
3
+ * Returns whether a command's last argument is variadic.
4
+ */
5
+ export declare function hasVariadicArguments(cmd: CommandBuilder): boolean;
@@ -0,0 +1 @@
1
+ export declare const objAssign: (target: Record<string, any>, ...sources: Record<string, any>[]) => Record<string, any>;
@@ -0,0 +1,2 @@
1
+ import { Any } from '@bemoje/util';
2
+ export declare function objDestroy(obj: Record<string | symbol, Any>): void;
@@ -0,0 +1,2 @@
1
+ import { Option } from 'commander';
2
+ export declare function optHasArgument(opt: Option): boolean;
@@ -0,0 +1,5 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ /**
3
+ * Get a commands prefix array based on all its parent/ancestor commands.
4
+ */
5
+ export declare function prefixArray(cmd: CommandBuilder): string[];
@@ -0,0 +1,5 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ /**
3
+ * Get a commands prefix string based on all its parent/ancestor commands.
4
+ */
5
+ export declare function prefixString(cmd: CommandBuilder): string;
@@ -0,0 +1,5 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ /**
3
+ * Returns a command's and its children's prefix strings.
4
+ */
5
+ export declare function prefixStringsRecursive(cmd: CommandBuilder, filter?: (prefix: string, cmd: CommandBuilder) => boolean): string[][];
@@ -0,0 +1 @@
1
+ export declare function realizeLazyProperty<T>(obj: unknown, key: string, value: T): T;
@@ -0,0 +1,6 @@
1
+ import { Option } from 'commander';
2
+ /**
3
+ * Update an Option's 'flags' property from its 'short' and 'long' properties.
4
+ * The flags property is not automatically updated when 'short' or 'long' are changed.
5
+ */
6
+ export declare function renderOptionFlags(opt: Option): string;
@@ -0,0 +1,6 @@
1
+ import { Option } from 'commander';
2
+ /**
3
+ * Set an Option's 'long' name. The 'flags' property is updated accordingly.
4
+ * The '--' prefix is automatically added if not present.
5
+ */
6
+ export declare function setOptionLongName(opt: Option, long: string): void;
@@ -0,0 +1,6 @@
1
+ import { Option } from 'commander';
2
+ /**
3
+ * Set an Option's 'short' name. The 'flags' property is updated accordingly.
4
+ * The '-' prefix is automatically added if not present.
5
+ */
6
+ export declare function setOptionShortName(opt: Option, short: string): void;
@@ -0,0 +1 @@
1
+ export declare function splitCombinedArgvShorts(argv: string[]): string[];
@@ -0,0 +1,7 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ /**
3
+ * Returns an iterator that walks the command's ancestors, optionally starting with the command itself.
4
+ */
5
+ export declare function walkAncestors(cmd: CommandBuilder, options?: {
6
+ includeSelf?: boolean;
7
+ }): Generator<CommandBuilder>;
@@ -0,0 +1,4 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ export declare function walkChildren(cmd: CommandBuilder, options?: {
3
+ includeSelf?: boolean;
4
+ }): Generator<CommandBuilder>;
@@ -0,0 +1,5 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ /**
3
+ * Iterate sibling CommandBuilder objects.
4
+ */
5
+ export declare function walkSiblings(cmd: CommandBuilder): Generator<CommandBuilder, void, unknown>;
package/src/index.d.ts ADDED
@@ -0,0 +1,113 @@
1
+ export * from './core/CommandBuilder/ArgumentBuilder';
2
+ export * from './core/CommandBuilder/ArgumentReader';
3
+ export * from './core/CommandBuilder/assertCommandNameNotReserved';
4
+ export * from './core/CommandBuilder/Base';
5
+ export * from './core/CommandBuilder/CommandBuilder';
6
+ export * from './core/CommandBuilder/CommandBuilderMetaData';
7
+ export * from './core/CommandBuilder/CommandFeatureSelector';
8
+ export * from './core/CommandBuilder/ensureBackRefToCommandBuilder';
9
+ export * from './core/CommandBuilder/ErrorParser';
10
+ export * from './core/CommandBuilder/features/action/actionWrapper';
11
+ export * from './core/CommandBuilder/features/action/combineVariadicArgs';
12
+ export * from './core/CommandBuilder/features/action/debugLogArgsOpts';
13
+ export * from './core/CommandBuilder/features/action/deleteOptionsWithDefaultOrNoValue';
14
+ export * from './core/CommandBuilder/features/action/getPresetArgsAndOpts';
15
+ export * from './core/CommandBuilder/features/action/handleError';
16
+ export * from './core/CommandBuilder/features/action/handleOutputOptions';
17
+ export * from './core/CommandBuilder/features/action/optsWithGlobalsParsed';
18
+ export * from './core/CommandBuilder/features/action/padArgsWithUndefinedUntilExpectedLength';
19
+ export * from './core/CommandBuilder/features/action/parseArguments';
20
+ export * from './core/CommandBuilder/features/action/parsedValidArgsOptsWithPresets';
21
+ export * from './core/CommandBuilder/features/action/parsedValidArgsWithPresets';
22
+ export * from './core/CommandBuilder/features/action/parsedValidOptsWithPresets';
23
+ export * from './core/CommandBuilder/features/action/parseOptions';
24
+ export * from './core/CommandBuilder/features/addConfigCommands';
25
+ export * from './core/CommandBuilder/features/addPresetsCommands';
26
+ export * from './core/CommandBuilder/features/addUtilCommands';
27
+ export * from './core/CommandBuilder/features/assertNoDuplicateCommandNames';
28
+ export * from './core/CommandBuilder/features/assertNoDuplicateOptionNames';
29
+ export * from './core/CommandBuilder/features/autoAssignMissingOptionFlags';
30
+ export * from './core/CommandBuilder/features/autoAssignSubCommandAliases';
31
+ export * from './core/CommandBuilder/features/formatTableForTerminal';
32
+ export * from './core/CommandBuilder/features/getClosestNonNativeParent';
33
+ export * from './core/CommandBuilder/getGlobalOptions';
34
+ export * from './core/CommandBuilder/getOwnAndGlobalOptions';
35
+ export * from './core/CommandBuilder/initializeCommand';
36
+ export * from './core/CommandBuilder/OptionBuilder';
37
+ export * from './core/CommandBuilder/OptionReader';
38
+ export * from './core/CommandBuilder/OutputManager';
39
+ export * from './core/db/AbstractJsonFileSection';
40
+ export * from './core/db/ConfigSection';
41
+ export * from './core/db/JsonDB';
42
+ export * from './core/db/JsonFile';
43
+ export * from './core/db/JsonFileError';
44
+ export * from './core/db/PresetsSection';
45
+ export * from './core/help/configureHelp';
46
+ export * from './core/util/arrAssign';
47
+ export * from './core/util/assertPresetArgsOptional';
48
+ export * from './core/util/assertValidArguments';
49
+ export * from './core/util/assertValidOptions';
50
+ export * from './core/util/assertValidPreset';
51
+ export * from './core/util/commandExists';
52
+ export * from './core/util/commandLocation';
53
+ export * from './core/util/createArrayMerger';
54
+ export * from './core/util/createObjectMerger';
55
+ export * from './core/util/errorToString';
56
+ export * from './core/util/escapeShellCommandArgument';
57
+ export * from './core/util/forEachChildRecursive';
58
+ export * from './core/util/getAncestors';
59
+ export * from './core/util/getARGV';
60
+ export * from './core/util/getChildren';
61
+ export * from './core/util/getJsonFilepath';
62
+ export * from './core/util/getOptionArgumentName';
63
+ export * from './core/util/getRootCommand';
64
+ export * from './core/util/getSiblings';
65
+ export * from './core/util/hasVariadicArguments';
66
+ export * from './core/util/MethodDisabler';
67
+ export * from './core/util/objAssign';
68
+ export * from './core/util/objDestroy';
69
+ export * from './core/util/optHasArgument';
70
+ export * from './core/util/prefixArray';
71
+ export * from './core/util/prefixString';
72
+ export * from './core/util/prefixStringsRecursive';
73
+ export * from './core/util/realizeLazyProperty';
74
+ export * from './core/util/renderOptionFlags';
75
+ export * from './core/util/setOptionLongName';
76
+ export * from './core/util/setOptionShortName';
77
+ export * from './core/util/splitCombinedArgvShorts';
78
+ export * from './core/util/walkAncestors';
79
+ export * from './core/util/walkChildren';
80
+ export * from './core/util/walkSiblings';
81
+ export * from './parsers/createBooleanParser';
82
+ export * from './parsers/createTupleListParser';
83
+ export * from './parsers/createTypedListParser';
84
+ export * from './parsers/parseBoolean';
85
+ export * from './parsers/parseInteger';
86
+ export * from './parsers/parseNumber';
87
+ export * from './parsers/parseString';
88
+ export * from './parsers/selector/AbstractStringParserSelector';
89
+ export * from './parsers/selector/ArgumentParserSelector';
90
+ export * from './parsers/selector/OptionArgumentParserSelector';
91
+ export * from './types/IDefinePropertyOptions';
92
+ export * from './types/IPreset';
93
+ export * from './types/IPresets';
94
+ export * from './types/TStringParser';
95
+ export * from './types/TValidator';
96
+ export * from './validators/createLengthValidator';
97
+ export * from './validators/createTypedArrayValidator';
98
+ export * from './validators/isArray';
99
+ export * from './validators/isBoolean';
100
+ export * from './validators/isInteger';
101
+ export * from './validators/isIntegerArray';
102
+ export * from './validators/isNamedFunction';
103
+ export * from './validators/isNamedFunctionArray';
104
+ export * from './validators/isNull';
105
+ export * from './validators/isNumber';
106
+ export * from './validators/isNumberArray';
107
+ export * from './validators/isNumericString';
108
+ export * from './validators/isString';
109
+ export * from './validators/isStringArray';
110
+ export * from './validators/isStringWithNoSpacesOrDashes';
111
+ export * from './validators/selector/ArgumentValidatorSelector';
112
+ export * from './validators/selector/OptionArgumentValidatorSelector';
113
+ export * from './validators/selector/ValidatorSelector';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates a parser function that parses a string into a boolean.
3
+ *
4
+ * @param trueValues - An array of strings that are considered true. Defaults to ['TRUE', 'T', 'YES', 'Y', '1'].
5
+ * @param falseValues - An array of strings that are considered false. Defaults to ['', 'FALSE', 'F', 'NO', 'N', '0'].
6
+ */
7
+ export declare function createBooleanParser(trueValues?: string[], falseValues?: string[]): (string: string) => boolean;
@@ -0,0 +1,11 @@
1
+ import { JsonRawPrimitive } from '@bemoje/util';
2
+ /**
3
+ * Creates a parser function that parses a delimited string into a list of typed values.
4
+ * The parsers array corresponds to the ordering of the expected input values.
5
+ *
6
+ * @param delimiter - The delimiter used to split the string into individual values.
7
+ * @param parsers - An array of functions used to parse each individual value in the string.
8
+ * @returns A function that takes a delimited string and returns an array of typed values.
9
+ * @template T - The type of the values in the list.
10
+ */
11
+ export declare function createTupleListParser<T extends JsonRawPrimitive = JsonRawPrimitive>(delimiter: string, parsers: ((value: string) => T)[]): (value: string) => T[];
@@ -0,0 +1,11 @@
1
+ import { TStringParser } from '../types/TStringParser';
2
+ /**
3
+ * Creates a parser function that parses a delimited string into a list of typed values.
4
+ * The parser function takes a string and returns an array of typed values.
5
+ *
6
+ * @param delimiter - The delimiter used to split the string into individual values.
7
+ * @param parser - The function used to parse each individual value in the string.
8
+ * @returns A function that takes a delimited string and returns an array of typed values.
9
+ * @template T - The type of the values in the list.
10
+ */
11
+ export declare function createTypedListParser<T>(delimiter: string, parser: TStringParser<T>): TStringParser<T[]>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Parses a string into a boolean.
3
+ *
4
+ * Accepted values (case insensitive):
5
+ * - true: 'TRUE', 'T', 'YES', 'Y', '1'
6
+ * - false: 'FALSE', 'F', 'NO', 'N', '0'
7
+ *
8
+ * @throws Will throw an error if the input string is not a valid input.
9
+ */
10
+ export declare const parseBoolean: (string: string) => boolean;
@@ -0,0 +1 @@
1
+ export declare function parseInteger(string: string): number;
@@ -0,0 +1 @@
1
+ export declare function parseNumber(string: string): number;
@@ -0,0 +1 @@
1
+ export declare function parseString<O = string>(string: string): O;
@@ -0,0 +1,17 @@
1
+ import { ArgumentBuilder } from '../../core/CommandBuilder/ArgumentBuilder';
2
+ import { Base } from '../../core/CommandBuilder/Base';
3
+ import { JsonValue } from '@bemoje/util';
4
+ import { OptionBuilder } from '../../core/CommandBuilder/OptionBuilder';
5
+ import { TStringParser } from '../../types/TStringParser';
6
+ export declare abstract class AbstractStringParserSelector<Builder extends ArgumentBuilder | OptionBuilder> extends Base {
7
+ protected readonly builder: Builder;
8
+ constructor(builder: Builder);
9
+ abstract custom<T extends JsonValue>(parser: TStringParser<T>): Builder;
10
+ string(): Builder;
11
+ number(): Builder;
12
+ integer(): Builder;
13
+ delimitedStrings(delimiter?: string): Builder;
14
+ delimitedNumbers(delimiter?: string): Builder;
15
+ delimitedIntegers(delimiter?: string): Builder;
16
+ delimited<T extends JsonValue>(delimiter: string | undefined, parser: TStringParser<T>): Builder;
17
+ }
@@ -0,0 +1,7 @@
1
+ import { AbstractStringParserSelector } from './AbstractStringParserSelector';
2
+ import { ArgumentBuilder } from '../../core/CommandBuilder/ArgumentBuilder';
3
+ import { JsonValue } from '@bemoje/util';
4
+ import { TStringParser } from '../../types/TStringParser';
5
+ export declare class ArgumentParserSelector extends AbstractStringParserSelector<ArgumentBuilder> {
6
+ custom<T extends JsonValue>(parser: TStringParser<T>): ArgumentBuilder;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AbstractStringParserSelector } from './AbstractStringParserSelector';
2
+ import { JsonValue } from '@bemoje/util';
3
+ import { OptionBuilder } from '../../core/CommandBuilder/OptionBuilder';
4
+ import { TStringParser } from '../../types/TStringParser';
5
+ export declare class OptionArgumentParserSelector extends AbstractStringParserSelector<OptionBuilder> {
6
+ custom<T extends JsonValue>(parser: TStringParser<T>): OptionBuilder;
7
+ }
@@ -0,0 +1,9 @@
1
+ import { JsonRawPrimitive } from '@bemoje/util';
2
+ import { TStringParser } from './TStringParser';
3
+ import { TValidator } from './TValidator';
4
+ export interface IConfigDefinePropertyOptions<Val = JsonRawPrimitive> {
5
+ description: string;
6
+ defaultValue: Val;
7
+ parse: TStringParser<Val>;
8
+ validate?: TValidator<Val>;
9
+ }
@@ -0,0 +1,14 @@
1
+ import { Any } from '@bemoje/util';
2
+ import { OptionValues } from 'commander';
3
+ export interface IPreset<O extends OptionValues = OptionValues> {
4
+ description: string;
5
+ presets: string[];
6
+ args: Any[];
7
+ options: O;
8
+ }
9
+ export interface IPresetPartial<O extends OptionValues = OptionValues> {
10
+ description: string;
11
+ presets?: string[];
12
+ args?: Any[];
13
+ options?: O;
14
+ }
@@ -0,0 +1,6 @@
1
+ import { IPreset } from './IPreset';
2
+ import { OptionValues } from 'commander';
3
+ export interface IPresets<O extends OptionValues = OptionValues> {
4
+ defaults: IPreset<O>;
5
+ [name: string]: IPreset<O>;
6
+ }
@@ -0,0 +1 @@
1
+ export type TStringParser<T> = (value: string) => T;
@@ -0,0 +1,2 @@
1
+ import { JsonValue } from '@bemoje/util';
2
+ export type TValidator<T = JsonValue> = (value: T, ...args: any[]) => boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates a function that validates if the length of the input is equal to the specified length.
3
+ * The returned function accepts any value with a 'name' property and is named 'isLengthOf' concatenated with the specified length.
4
+ * @param length - The length to validate against.
5
+ * @throws if length is not an integer.
6
+ */
7
+ export declare function createLengthValidator(length: number): (input: unknown) => boolean;
@@ -0,0 +1,11 @@
1
+ import { JsonValue } from '@bemoje/util';
2
+ import { TValidator } from '../types/TValidator';
3
+ /**
4
+ * Creates a validator function that checks whether the input is an array where all elements are valid according to every validator provided.
5
+ *
6
+ * @param validators - An array of validator functions.
7
+ * @param name - The name of the validator function. If not provided, the name will be derived from the validator functions.
8
+ *
9
+ * @throws TypeError - if no name is provided and not all validators are named functions.
10
+ */
11
+ export declare function createTypedArrayValidator<O extends JsonValue = JsonValue>(validators: TValidator<O>[], name?: string): (array: unknown) => boolean;
@@ -0,0 +1 @@
1
+ export declare const isArray: (arg: any) => arg is any[];
@@ -0,0 +1 @@
1
+ export declare function isBoolean(value: unknown): value is boolean;
@@ -0,0 +1 @@
1
+ export declare const isInteger: (number: unknown) => boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determine whether the input is an integer array.
3
+ */
4
+ export declare function isIntegerArray(value: unknown): value is number[];
@@ -0,0 +1,5 @@
1
+ import { TFunction } from '@bemoje/util';
2
+ /**
3
+ * Checks if the provided value is a named function.
4
+ */
5
+ export declare function isNamedFunction(func: unknown): func is TFunction;
@@ -0,0 +1 @@
1
+ export declare function isNamedFunctionArray(array: unknown): boolean;
@@ -0,0 +1 @@
1
+ export declare function isNull(value: unknown): value is null;
@@ -0,0 +1 @@
1
+ export declare function isNumber(value: unknown): value is number;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determine whether the input is a number array.
3
+ */
4
+ export declare function isNumberArray(value: unknown): value is number[];
@@ -0,0 +1 @@
1
+ export declare function isNumericString(string: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function isString(value: unknown): value is string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determine whether the input is a string array.
3
+ */
4
+ export declare function isStringArray(value: unknown): value is string[];
@@ -0,0 +1 @@
1
+ export declare function isStringWithNoSpacesOrDashes(value: unknown): boolean;
@@ -0,0 +1,6 @@
1
+ import { AbstractValidatorSelector } from './ValidatorSelector';
2
+ import { ArgumentBuilder } from '../../core/CommandBuilder/ArgumentBuilder';
3
+ import { TValidator } from '../../types/TValidator';
4
+ export declare class ArgumentValidatorSelector extends AbstractValidatorSelector<ArgumentBuilder> {
5
+ custom<O>(validator: TValidator<O>): ArgumentBuilder;
6
+ }
@@ -0,0 +1,6 @@
1
+ import { AbstractValidatorSelector } from './ValidatorSelector';
2
+ import { OptionBuilder } from '../../core/CommandBuilder/OptionBuilder';
3
+ import { TValidator } from '../../types/TValidator';
4
+ export declare class OptionArgumentValidatorSelector extends AbstractValidatorSelector<OptionBuilder> {
5
+ custom<O>(validator: TValidator<O>): OptionBuilder;
6
+ }
@@ -0,0 +1,17 @@
1
+ import { ArgumentBuilder } from '../../core/CommandBuilder/ArgumentBuilder';
2
+ import { Base } from '../../core/CommandBuilder/Base';
3
+ import { JsonValue } from '@bemoje/util';
4
+ import { OptionBuilder } from '../../core/CommandBuilder/OptionBuilder';
5
+ import { TValidator } from '../../types/TValidator';
6
+ export declare abstract class AbstractValidatorSelector<Builder extends OptionBuilder | ArgumentBuilder> extends Base {
7
+ protected readonly builder: Builder;
8
+ constructor(builder: Builder);
9
+ abstract custom<O>(validator: TValidator<O>): typeof this.builder;
10
+ isString(): Builder;
11
+ isNumber(): Builder;
12
+ isInteger(): Builder;
13
+ isStringArray(): Builder;
14
+ isNumberArray(): Builder;
15
+ isIntegerArray(): Builder;
16
+ arrayWhereEach<O extends JsonValue = JsonValue>(...validators: TValidator<O>[]): Builder;
17
+ }