UNPKG

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