UNPKG

2.57 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import { EventEmitter } from "events";
4import { ReadStream, WriteStream } from "tty";
5import "revalidator";
6
7declare namespace prompt {
8 type GetCallback<T> = (err: Error | null, result: T) => void;
9 type AddCallback = (err: Error | null) => void;
10 type AskFunction = () => boolean;
11 type BeforeFunction = (line: string) => string;
12
13 type RevalidatorSchema = Partial<Revalidator.ISchema<any>> & {
14 ask?: AskFunction | undefined;
15 before?: BeforeFunction | undefined;
16 name?: string | undefined;
17 raw?: [string, string] | undefined;
18 hidden?: boolean;
19 };
20
21 interface Properties {
22 [name: string]: RevalidatorSchema | string;
23 }
24
25 interface Schema {
26 properties: Properties;
27 }
28
29 interface History {
30 property: RevalidatorSchema | string;
31 value: string;
32 }
33
34 interface StartOptions {
35 allowEmpty?: boolean | undefined;
36 colors?: boolean | undefined;
37 delimiter?: string | undefined;
38 memory?: number | undefined;
39 message?: string | undefined;
40 noHandleSIGINT?: boolean | undefined;
41 stdin?: ReadStream | undefined;
42 stdout?: WriteStream | undefined;
43 }
44}
45
46declare class prompt extends EventEmitter {
47 on(event: "invalid", listener: (prop: prompt.RevalidatorSchema | string, line: number) => void): this;
48 on(event: "prompt", listener: (prop: prompt.RevalidatorSchema | string) => void): this;
49 on(event: "pause" | "resume" | "SIGINT" | "start" | "stop", listener: () => void): this;
50
51 static colors: boolean;
52 static delimiter: string;
53 static message: string;
54 static override?: any;
55 static version: string;
56
57 static addProperties(obj: any, values: Array<string | prompt.RevalidatorSchema>): Promise<void>;
58 static addProperties(
59 obj: any,
60 values: Array<string | prompt.RevalidatorSchema>,
61 callback: prompt.GetCallback<prompt.Properties>,
62 ): void;
63 static get<T extends prompt.Properties>(
64 values: Array<keyof T | prompt.Schema | prompt.RevalidatorSchema> | prompt.Schema | prompt.RevalidatorSchema,
65 ): Promise<T>;
66 static get<T extends prompt.Properties>(
67 values: Array<keyof T | prompt.Schema | prompt.RevalidatorSchema> | prompt.Schema | prompt.RevalidatorSchema,
68 callback: prompt.GetCallback<T>,
69 ): void;
70 static history(name?: string | number): prompt.History | null;
71 static start(options?: prompt.StartOptions): void;
72 static stop(): void;
73}
74
75export = prompt;