Skip to content

Commit

Permalink
feat: added typings
Browse files Browse the repository at this point in the history
  • Loading branch information
unlok committed Aug 11, 2021
1 parent 4ac2f23 commit c8d3663
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.1",
"description": "Config parser module for gemini",
"main": "lib/index.js",
"types": "./typings/index.d.ts",
"author": "Sergey Tatarintsev <sevinf@yandex-team.ru> (https://github.com/SevInf)",
"license": "MIT",
"devDependencies": {
Expand Down
41 changes: 41 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
declare module "gemini-configparser" {
type PartialConfig = never;
type Locator = never;
type UnsanitizedRootConfig = any;
type UnsanitizedConfigNode = any;

type Parser<T> = (locator: Locator, config: PartialConfig) => T;

type RootPrefixes = {
envPrefix: string;
cliPrefix: string;
};

type OptionParserConfig<T> = {
defaultValue: T | ((config: UnsanitizedRootConfig, currNode: UnsanitizedConfigNode) => T);
parseCli?(input: string): T;
parseEnv?(input: string): T;
validate?(value: T, config: UnsanitizedRootConfig, currNode: UnsanitizedConfigNode): void;
};

type MappedOptionParserConfig<S, T> = OptionParserConfig<S> & {
map(value: S, config: UnsanitizedRootConfig, currNode: UnsanitizedConfigNode): T;
};

type SectionProperties<T> = { [name in keyof T]: Parser<T[name]> };

export function option<T>(description: OptionParserConfig<T>): Parser<T>;
export function option<S, T>(description: MappedOptionParserConfig<S, T>): Parser<T>;
export function section<T>(properties: SectionProperties<T>): Parser<T>;

type RootParserArg = {
options: UnsanitizedRootConfig;
env: NodeJS.ProcessEnv;
argv: Array<string>;
};
type RootParser<T> = (arg: RootParserArg) => T;
export function root<T>(rootParser: Parser<T>, prefixes: RootPrefixes): RootParser<T>;

export class MissingOptionError extends Error {}
export class UnknownKeysError extends Error {}
}

0 comments on commit c8d3663

Please sign in to comment.