ox-argv-parser/types.d.ts
2025-05-09 15:55:57 +02:00

66 lines
3.6 KiB
TypeScript

interface FlagT<T, Z> {
default?: T,
aliases?: string[],
/** Shorhands, AKA only work with singular minus signs like -f; Multiple characters are allowed; Will not count as a full (like --f) flag alias; */
shorthands?: string|string[],
type?: Z
/** Whether to send/throw an error if the flag is present but no value is set, either with an assigned (--flag=value) value, or regular --flag value @default false */
requiredValue?: boolean
};
export type FlagAny = FlagT<string, "string"> | FlagT<boolean, "boolean"> | FlagT<number, "number"> | FlagT<string | number | boolean, "any">
export interface FlagsI { [key: readonly string]: FlagAny }
export type DefaultParserOptsType = ParserOpts<FlagsI>
/** This object will be modified by parser */
export interface ParserOpts<Flags extends FlagsI> {
flags?: Flags,
/** Wether to allow versions of `-flag` as a singular and valid flag. @default false */
allowSingularDashLongFlags?: boolean = false
/** Wether to allow flags not denoted in the flag property. @default true */
allowUnknownFlags?: boolean = true
/** Wether to lowercase all flags key. Incompatible with camelCaseFlags option. @default true */
lowerCaseFlags?: boolean = true
/** Wether to automatically resolve flag number values into numbers and boolean flags into booleans if flag type is explicitly set. @default true */
resolveFlagValueTypes?: boolean = true
/**
* Setting according flag to the inversed provided boolean value (defaulting to false if none is provided) with their '--no' variants unless a defined flag exists with that
* name already; Additional informations in sub-properties.
* @default
* ```js
* = { enabled: true, allowUnspacedNegatedFlags: true, shorthandNegation: true }
* ```
*/
automaticBooleanFlagNegation?: {
/** Wether to automatically resolve boolean flags that are negated to the inverse boolean value. Requires resolveFlagValueTypes. @default true */
enabled?: boolean;
/** Allows flags negated without a space (eg: "--noflag") to still be automatically resolved @default true */
allowUnspacedNegatedFlags?: boolean;
/** Wether to negate shorthand flags with if an n is present before hand (eg: '-nf'). Providing a shorthand of 'n' will disable this feature. @default true */
shorthandNegation?: boolean;
}
/** Enable this option to silence any warnings about potentially unexpected behavior (eg: a flag's unset type being set to the default). @default false */
silenceWarnings?: boolean;
/** Override to change how warnings are emitted @default console.warn */
warningLogger?: (log: string) => void;
/** Default type for either unknown flags or flags without an explicit type being set @default "any" */
defaultFlagType?: "string" | "boolean" | "number" | "any";
/**
* Behavior when input does not follow the provided flags constraints (eg: flag assigned value (--flag=value) not being the correct type).
*
* Setting it to 'ignore' or 'log' is highly not recommended and will lead to undefined behavior. (eg: flags not meeting the configuration not being present
* in the final returned object)
* Setting this to 'ignore' will give the same undefined behavior as setting it to 'log', but without emitting any logs to `warningLogger`.
* @default 'throw'
*/
behaviorOnInputError?: 'throw' | 'log' | 'log&exit' | 'ignore';
/** Wether to allow default flag values set to null being valid @default true */
allowNullDefaultFlagValues?: boolean;
}
function __type__getType(e: any) { return typeof e };
export type JSTypes = ReturnType<typeof __type__getType>