@ibgib/helper-gib
Version:
common helper/utils/etc used in ibgib libs. Node v19+ needed for heavily-used isomorphic webcrypto hashing consumed in both node and browsers.
113 lines • 3.83 kB
text/typescript
/**
* @module rcli-helper functions
*
* utilities to help enable rcli functionality, yeah, that's the ticket...
*/
import { RCLIArgInfo, RCLIArgType, RCLIParamInfo, RawArgInfo } from "./rcli-types.mjs";
/**
* All incoming arg values are strings. This will convert that depending on the
* parameter definition.
*
* ...hmm, unsure how to handle undefined just yet, even though that is a return type here...
*
* @returns casted/parsed value as a string/number/boolean value.
*/
export declare function getValueFromRawString<T extends RCLIArgType = string>({ paramInfo, valueString, }: {
paramInfo: RCLIParamInfo;
valueString: string | undefined;
}): T | undefined;
/**
* extracts the arg value(s) from the corresponding `paramInfo` from the given
* `argInfos`.
*
* @returns the arg.value corresponding to the given `paramInfo`
*/
export declare function extractArgValue<T extends RCLIArgType>({ paramInfo, argInfos, throwIfNotFound, }: {
/**
* Param you're pulling from the args.
*/
paramInfo: RCLIParamInfo;
/**
* the given arg infos from the request line.
*/
argInfos: RCLIArgInfo<RCLIArgType>[];
/**
* If true, will throw an exception if the param is not found in the args,
* else just returns undefined.
*/
throwIfNotFound?: boolean;
}): T | T[] | undefined;
/**
* gets the paramInfo corresponding to the given argIdentifier
* @returns paramInfo from given `paramInfos` or undefined if not found
*/
export declare function getParamInfo({ argIdentifier, paramInfos, throwIfNotFound, }: {
/**
* arg identifier is either a name or a synonym. atow only a name.
*/
argIdentifier: string;
/**
* All possible param infos that the given arg identifier could be.
*/
paramInfos: RCLIParamInfo[];
throwIfNotFound?: boolean;
}): RCLIParamInfo | undefined;
/**
* helper that parses a raw arg e.g. 'bare-arg', '--double-dashed-arg',
* '-single-dashed-arg', ':command-arg', etc.
*/
export declare function parseRawArg({ rawArg, }: {
rawArg: string;
}): RawArgInfo;
/**
* helper that checks a raw arg (including any dashes) against a parameter
* definition.
*
* @returns true if the arg is the given paramInfo, else false
*/
export declare function argIs({ arg, paramInfo, argInfoIndex, }: {
/**
* raw arg string, including dash(es)
*/
arg: string;
/**
* param you're checking against the raw arg value.
*/
paramInfo: RCLIParamInfo;
/**
* positional index in argInfos. used in interpreting bare args.
*
* if it's the first arg and bare, then it's a command identifier. If it's a
* different position and bare, then it's the bare arg value.
*/
argInfoIndex: number;
}): boolean;
/**
* This takes incoming raw `args` and parameter definitions and
* creates arginfos based on the given args.
* @returns argInfos that include values based on given raw args
*/
export declare function buildArgInfos<T extends RCLIArgType = string>({ args, paramInfos, bareArgParamInfo, logalot: localLogalot, }: {
/**
* array of raw args, including dashes
*/
args: string[];
/**
* parameter set of all possible parameters
*/
paramInfos: RCLIParamInfo[];
/**
* provides the param info to use when encountering a "bare arg".
*
* there can be one bare arg in the RCLI args list. This is an arg that does
* not start with the `--` prefix. When a bare arg is received, you must
* specify which param to map this to, because we don't have a param
* identifer (param name or synonym).
*/
bareArgParamInfo?: RCLIParamInfo;
/**
* if you want to use verbose logging, set this to true
*/
logalot?: boolean;
}): RCLIArgInfo<T>[];
//# sourceMappingURL=rcli-helper.d.mts.map