UNPKG

2.7 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
17 type RevalidatorSchema = Partial<Revalidator.ISchema<any>> & {
18 ask?: AskFunction | undefined;
19 name?: string | undefined;
20 raw?: [string, string] | undefined;
21 };
22
23 interface Properties {
24 [name: string]: RevalidatorSchema | string;
25 }
26
27 interface Schema {
28 properties: Properties;
29 }
30
31 interface History {
32 property: RevalidatorSchema | string;
33 value: string;
34 }
35
36 interface StartOptions {
37 allowEmpty?: boolean | undefined;
38 colors?: boolean | undefined;
39 delimiter?: string | undefined;
40 memory?: number | undefined;
41 message?: string | undefined;
42 noHandleSIGINT?: boolean | undefined;
43 stdin?: ReadStream | undefined;
44 stdout?: WriteStream | undefined;
45 }
46}
47
48declare class prompt extends EventEmitter {
49 on(event: 'invalid', listener: (prop: prompt.RevalidatorSchema | string, line: number) => void): this;
50 on(event: 'prompt', listener: (prop: prompt.RevalidatorSchema | string) => void): this;
51 on(event: 'pause' | 'resume' | 'SIGINT' | 'start' | 'stop', listener: () => void): this;
52
53 static colors: boolean;
54 static delimiter: string;
55 static message: string;
56 static override?: any;
57 static version: string;
58
59 static addProperties(obj: any, values: Array<string | prompt.RevalidatorSchema>): Promise<void>;
60 static addProperties(
61 obj: any,
62 values: Array<string | prompt.RevalidatorSchema>,
63 callback: prompt.GetCallback<prompt.Properties>,
64 ): void;
65 static get<T extends prompt.Properties>(
66 values: Array<keyof T | prompt.Schema | prompt.RevalidatorSchema> | prompt.Schema | prompt.RevalidatorSchema,
67 ): Promise<T>;
68 static get<T extends prompt.Properties>(
69 values: Array<keyof T | prompt.Schema | prompt.RevalidatorSchema> | prompt.Schema | prompt.RevalidatorSchema,
70 callback: prompt.GetCallback<T>,
71 ): void;
72 static history(name?: string | number): prompt.History | null;
73 static start(options?: prompt.StartOptions): void;
74}
75
76export = prompt;