@jondotsoy/flags
Version:
A Javascript arguments processor
28 lines (27 loc) • 1.47 kB
TypeScript
import type { Accumulate } from "../dtos/Accumulate.js";
import type { Refine } from "../dtos/Refine.js";
import type { ResultParser } from "../dtos/ResultParser.js";
import type { Builder } from "./Builder.js";
export type InitialType<T extends Spec<any, any>> = T extends Spec<infer U, any> ? U : never;
export type ParseResultType<T extends Spec<any, any>> = T extends Spec<any, infer U> ? U : never;
export type RedefineParseResult<T extends Spec<any, any>, U> = Spec<InitialType<T>, U>;
export type RedefineInitialValue<T extends Spec<any, any>, U> = Spec<U, ParseResultType<T>>;
/** Inmutable class */
export declare class Spec<InitialValue, ParseResult> {
#private;
constructor(initial: InitialValue, refiners: Refine[], accumulate?: Accumulate, metadata?: Record<string, any>);
initial<T>(initial: T): Spec<T, ParseResult>;
accumulate(accumulate: Accumulate): Spec<InitialValue, ParseResult>;
refine<U>(refine: Refine): Spec<InitialValue, U>;
metadata(values: Record<string, any>): Spec<InitialValue, ParseResult>;
getMetadata<T>(key: string): T;
hasMetadata(key: string): boolean;
copyMetadata(): Record<string, any>;
getInitial(): InitialValue;
getAccumulate(): Accumulate | undefined;
getRefiners(): Refine[];
parse(startIndex: number, args: string[], prevValue: {
current: any;
} | undefined, builder: Builder<any>): null | ResultParser<ParseResult>;
static create(): Spec<null, null>;
}