Socket
Socket
Sign inDemoInstall

@types/inquirer

Package Overview
Dependencies
4
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.3 to 6.5.0

inquirer/lib/objects/choice.d.ts

1060

inquirer/index.d.ts

@@ -1,2 +0,2 @@

// Type definitions for Inquirer.js 6.x
// Type definitions for inquirer 6.5
// Project: https://github.com/SBoudrias/Inquirer.js

@@ -13,422 +13,922 @@ // Definitions by: Qubo <https://github.com/tkQubo>

// Jed Mao <https://github.com/jedmao>
// Manuel Thalmann <https://github.com/manuth>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.3
import { Interface as ReadlineInterface } from "readline";
import { Observable } from "rxjs";
import { ThroughStream } from "through";
import Choice = require("./lib/objects/choice");
import Choices = require("./lib/objects/choices");
import Separator = require("./lib/objects/separator");
import Prompt = require("./lib/prompts/base");
import "./lib/prompts/checkbox";
import "./lib/prompts/confirm";
import "./lib/prompts/editor";
import "./lib/prompts/expand";
import "./lib/prompts/input";
import "./lib/prompts/list";
import "./lib/prompts/number";
import "./lib/prompts/password";
import "./lib/prompts/rawlist";
import BottomBar = require("./lib/ui/bottom-bar");
import PromptUI = require("./lib/ui/prompt");
import "./lib/utils/events";
import Paginator = require("./lib/utils/paginator");
import "./lib/utils/readline";
import ScreenManager = require("./lib/utils/screen-manager");
import "./lib/utils/utils";
import { ThroughStream } from 'through';
import { Observable } from 'rxjs';
import { Interface as ReadlineInterface } from 'readline';
/**
* Represents a union which preserves autocompletion.
*
* @template T
* The keys which are available for autocompletion.
*
* @template F
* The fallback-type.
*/
type LiteralUnion<T extends F, F = string> = T | (F & {});
/**
* Provides prompts for answering questions.
*/
interface PromptModuleBase {
/**
* Registers a new prompt-type.
*
* @param name
* The name of the prompt.
*
* @param prompt
* The constructor of the prompt.
*/
registerPrompt(name: string, prompt: inquirer.prompts.PromptConstructor): void;
/**
* Registers the default prompts.
*/
restoreDefaultPrompts(): void;
}
/**
* Represents a list-based question.
*
* @template T
* The type of the answers.
*
* @template TChoiceMap
* The valid choices for the question.
*/
interface ListQuestionOptionsBase<T, TChoiceMap> extends inquirer.Question<T> {
/**
* The choices of the prompt.
*/
choices?: inquirer.AsyncDynamicQuestionProperty<ReadonlyArray<inquirer.DistinctChoice<TChoiceMap>>, T>;
/**
* The number of elements to show on each page.
*/
pageSize?: number;
}
/**
* Provides components for the module.
*/
declare namespace inquirer {
type Prompts = { [name: string]: prompts.Base };
type ChoiceType<A> = string | objects.ChoiceOption<A> | objects.Separator;
type Questions<A extends Answers = Answers> =
| Question<A>
| Question<A>[]
| ReadonlyArray<Question<A>>
| Observable<Question<A>>;
type Answers = Record<string, any>
type StreamOptions = {
input?: NodeJS.ReadStream,
output?: NodeJS.WriteStream,
};
/**
* Represents either a key of `T` or a `string`.
*
* @template T
* The type of the keys to suggest.
*/
type KeyUnion<T> = LiteralUnion<Extract<keyof T, string>>;
interface Inquirer {
restoreDefaultPrompts(): void;
/**
* Converts the specified union-type `U` to an intersection-type.
*
* @template U
* The union to convert to an intersection.
*/
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
/**
* Provides an input and an output-stream.
*/
interface StreamOptions {
/**
* Expose helper functions on the top level for easiest usage by common users
* A stream to read the input from.
*/
input?: NodeJS.ReadStream;
/**
* A stream to write the output to.
*/
output?: NodeJS.WriteStream;
}
/**
* Provides the functionality to prompt questions to the user.
*/
interface PromptModule extends PromptModuleBase {
/**
* The prompts of the prompt-module.
*/
prompts: prompts.PromptCollection;
/**
* Prompts the questions to the user.
*/
<T>(questions: QuestionCollection<T>): Promise<T> & { ui: PromptUI };
/**
* Registers a new prompt-type.
*
* @param name
* The name of the prompt.
*
* @param prompt
* The constructor of the prompt.
*/
registerPrompt(name: string, prompt: PromptModule): void;
registerPrompt(name: string, prompt: prompts.PromptConstructor): this;
}
interface Inquirer extends PromptModuleBase {
/**
* Create a new self-contained prompt module.
* @param opt Object specifying input and output streams for the prompt
* Registers a new prompt-type.
*
* @param name
* The name of the prompt.
*
* @param prompt
* The constructor of the prompt.
*/
registerPrompt(name: string, prompt: prompts.PromptConstructor): void;
/**
* Creates a prompt-module.
*
* @param opt
* The streams for the prompt-module.
*
* @returns
* The new prompt-module.
*/
createPromptModule(opt?: StreamOptions): PromptModule;
/**
* Public CLI helper interface
* @param questions Questions settings array
* @return
* The default prompt-module.
*/
prompt: PromptModule;
prompts: Prompts;
Separator: objects.SeparatorStatic;
/**
* The prompts of the default prompt-module.
*
* @deprecated
*/
prompts: {};
/**
* Represents a choice-item separator.
*/
Separator: typeof Separator;
/**
* Provides ui-components.
*/
ui: {
BottomBar: ui.BottomBar;
Prompt: ui.PromptUI;
/**
* Represents the bottom-bar UI.
*/
BottomBar: typeof BottomBar;
/**
* Represents the prompt ui.
*/
Prompt: typeof PromptUI;
};
}
interface PromptModule {
<A>(questions: Questions<A>): Promise<A> & { ui: ui.PromptUI };
/**
* A set of answers.
*/
interface Answers extends Record<string, any> { }
/**
* Provides the functionality to validate answers.
*
* @template T
* The type of the answers.
*/
type Validator<T extends Answers = Answers> = Question<T>["validate"];
/**
* Provides the functionality to transform an answer.
*
* @template T
* The type of the answers.
*/
type Transformer<T extends Answers = Answers> = InputQuestionOptions<T>["transformer"];
/**
* Represents a dynamic property for a question.
*/
type DynamicQuestionProperty<T, TAnswers extends Answers = Answers> = T | ((answers: TAnswers) => T);
/**
* Represents a dynamic property for a question which can be fetched asynchronously.
*/
type AsyncDynamicQuestionProperty<T, TAnswers extends Answers = Answers> = DynamicQuestionProperty<T | Promise<T>, TAnswers>;
/**
* Provides options for a question.
*
* @template T
* The type of the answers.
*/
interface Question<T extends Answers = Answers> {
/**
* Register a prompt type
* @param name Prompt type name
* @param prompt Prompt constructor
* The type of the question.
*/
registerPrompt(name: string, prompt: prompts.Base): PromptModule;
type?: string;
/**
* Register the defaults provider prompts
* The key to save the answer to the answers-hash.
*/
restoreDefaultPrompts(): void;
name?: KeyUnion<T>;
/**
* The message to show to the user.
*/
message?: AsyncDynamicQuestionProperty<string, T>;
/**
* The default value of the question.
*/
default?: AsyncDynamicQuestionProperty<any, T>;
/**
* The prefix of the `message`.
*/
prefix?: string;
/**
* The suffix of the `message`.
*/
suffix?: string;
/**
* Post-processes the answer.
*
* @param input
* The answer provided by the user.
*/
filter?(input: any): any;
/**
* A value indicating whether the question should be prompted.
*/
when?: AsyncDynamicQuestionProperty<boolean, T>;
/**
* Validates the integrity of the answer.
*
* @param input
* The answer provided by the user.
*
* @param answers
* The answers provided by the user.
*
* @returns
* Either a value indicating whether the answer is valid or a `string` which describes the error.
*/
validate?(input: any, answers?: T): boolean | string | Promise<boolean | string>;
}
interface QuestionCommon<A> {
/**
* Represents a choice-item.
*/
interface ChoiceBase {
/**
* The name to use when storing the answer in the answers hash.
* If the name contains periods, it will define a path in the answers hash.
* The type of the choice.
*/
name?: string;
type?: string;
}
/**
* Provides options for a choice.
*
* @template T
* The type of the answers.
*/
interface ChoiceOptions<T extends Answers = Answers> extends ChoiceBase {
/**
* The question to print. If defined as a function, the first parameter will be
* the current inquirer session answers.
* Defaults to the value of `name` (followed by a colon).
* @inheritdoc
*/
message?: string | ((answers: A) => string);
type?: "choice";
/**
* Default value(s) to use if nothing is entered, or a function that returns
* the default value(s). If defined as a function, the first parameter will be
* the current inquirer session answers.
* The name of the choice to show to the user.
*/
default?: string | number | boolean | any[] | ((answers: A) => any) | ((answers: A) => Promise<any>);
name?: string;
/**
* Change the default _prefix_ message.
* The value of the choice.
*/
prefix?: string;
value?: any;
/**
* Change the default _suffix_ message.
* The short form of the name of the choice.
*/
suffix?: string;
short?: string;
/**
* Receive the current user answers hash and should return `true` or `false` depending
* on whether or not this question should be asked. The value can also be a simple boolean.
* The extra properties of the choice.
*/
when?: boolean | ((answers: A) => boolean | Promise<boolean>);
extra?: any;
}
interface QuestionOptions<A> {
/**
* Provides options for a choice of the `ListPrompt`.
*
* @template T
* The type of the answers.
*/
interface ListChoiceOptions<T extends Answers = Answers> extends ChoiceOptions<T> {
/**
* Choices array or a function returning a choices array. If defined as a function,
* the first parameter will be the current inquirer session answers. Array values can
* be simple `numbers`, `strings`, or `objects` containing a `name` (to display in list),
* a `value` (to save in the answers hash) and a `short` (to display after selection)
* properties. The choices array can also contain
* [a Separator](https://github.com/SBoudrias/Inquirer.js#separator).
* A value indicating whether the choice is disabled.
*/
choices?:
| ReadonlyArray<ChoiceType<A>>
| ((answers: A) => ReadonlyArray<ChoiceType<A>>)
| ((answers: A) => Promise<ReadonlyArray<ChoiceType<A>>>);
disabled?: DynamicQuestionProperty<boolean | string, T>;
}
/**
* Provides options for a choice of the `CheckboxPrompt`.
*
* @template T
* The type of the answers.
*/
interface CheckboxChoiceOptions<T extends Answers = Answers> extends ListChoiceOptions<T> {
/**
* Receive the user input and return the filtered value to be used inside the program.
* The value returned will be added to the _Answers_ hash.
* A value indicating whether the choice should be initially checked.
*/
filter?(input: string): any;
checked?: boolean;
}
/**
* Provides options for a choice of the `ExpandPrompt`.
*
* @template T
* The type of the answers.
*/
interface ExpandChoiceOptions<T extends Answers = Answers> extends ChoiceOptions<T> {
/**
* Receive the user input, answers hash and option flags, and return a transformed value
* to display to the user. The transformation only impacts what is shown while editing.
* It does not modify the answers hash.
* The key to press for selecting the choice.
*/
transformer?(input: string, answers: A, flags: any): string;
key?: string;
}
/**
* Represents a separator.
*/
interface SeparatorOptions {
/**
* Change the number of lines that will be rendered when using `list`, `rawList`,
* `expand` or `checkbox`.
* Gets the type of the choice.
*/
pageSize?: number;
type: "separator";
/**
* Gets or sets the text of the separator.
*/
line?: string;
}
type Question<A extends Answers = Answers> = (
ListQuestion<A> |
RawListQuestion<A> |
ExpandQuestion<A> |
CheckboxQuestion<A> |
ConfirmQuestion<A> |
InputQuestion<A> |
NumberQuestion<A> |
PasswordQuestion<A> |
EditorQuestion<A>
)
/**
* Provides all valid choice-types for any kind of question.
*
* @template T
* The type of the answers.
*/
interface BaseChoiceMap<T extends Answers = Answers> {
Choice: Choice<T>;
ChoiceOptions: ChoiceOptions<T>;
SeparatorOptions: SeparatorOptions;
Separator: Separator;
}
interface ListQuestion<A> extends QuestionCommon<A>,
Pick<QuestionOptions<A>, 'choices' | 'filter' | 'pageSize'> {
type: 'list'
/**
* Provides all valid choice-types for the `ListQuestion`.
*
* @template T
* The type of the answers.
*/
interface ListChoiceMap<T extends Answers = Answers> extends BaseChoiceMap<T> {
ListChoiceOptions: ListChoiceOptions<T>;
}
interface RawListQuestion<A> extends QuestionCommon<A>,
Pick<QuestionOptions<A>, 'choices' | 'filter' | 'pageSize'> {
type: 'rawlist'
/**
* Provides all valid choice-types for the `CheckboxQuestion`.
*
* @template T
* The type of the answers.
*/
interface CheckboxChoiceMap<T extends Answers = Answers> extends BaseChoiceMap<T> {
CheckboxChoiceOptions: CheckboxChoiceOptions<T>;
}
interface ExpandQuestion<A> extends QuestionCommon<A>,
Pick<QuestionOptions<A>, 'choices' | 'pageSize'> {
type: 'expand'
/**
* Provides all valid choice-types for the `ExpandQuestion`.
*
* @template T
* The type of the answers.
*/
interface ExpandChoiceMap<T extends Answers = Answers> extends BaseChoiceMap<T> {
ExpandChoiceOptions: ExpandChoiceOptions<T>;
}
interface CheckboxQuestion<A> extends QuestionCommon<A>,
Pick<QuestionOptions<A>, 'choices' | 'filter' | 'pageSize'> {
type: 'checkbox'
/**
* Provides all valid choice-types.
*
* @template T
* The type of the answers.
*/
interface AllChoiceMap<T extends Answers = Answers> {
BaseChoiceMap: BaseChoiceMap<T>[keyof BaseChoiceMap<T>];
ListChoiceMap: ListChoiceMap<T>[keyof ListChoiceMap<T>];
CheckboxChoiceMap: CheckboxChoiceMap<T>[keyof CheckboxChoiceMap<T>];
ExpandChoiceMap: ExpandChoiceMap<T>[keyof ExpandChoiceMap<T>];
}
/**
* Provides valid choices for the question of the `TChoiceMap`.
*
* @template TChoiceMap
* The choice-types to provide.
*/
type DistinctChoice<TChoiceMap> =
string |
TChoiceMap[keyof TChoiceMap];
/**
* Represents a set of choices.
*/
type ChoiceCollection<T extends Answers = Answers> = Array<DistinctChoice<AllChoiceMap>>;
/**
* Provides options for a question for the `InputPrompt`.
*
* @template T
* The type of the answers.
*/
interface InputQuestionOptions<T extends Answers = Answers> extends Question<T> {
/**
* Receive the user input and answers hash. Should return `true` if the value is valid,
* and an error message (`String`) otherwise. If `false` is returned, a default error
* message is provided.
* Transforms the value to display to the user.
*
* @param input
* The input provided by the user.
*
* @param answers
* The answers provided by the users.
*
* @param flags
* Additional information about the value.
*
* @returns
* The value to display to the user.
*/
validate?(input: string, answers?: A): boolean | string | Promise<boolean | string>;
transformer?(input: any, answers: T, flags: { isFinal?: boolean }): string | Promise<string>;
}
interface ConfirmQuestion<A> extends QuestionCommon<A>, QuestionOptions<A> {
type: 'confirm'
/**
* Provides options for a question for the `InputPrompt`.
*
* @template T
* The type of the answers.
*/
interface InputQuestion<T extends Answers = Answers> extends InputQuestionOptions<T> {
/**
* @inheritdoc
*/
type?: "input";
}
interface InputQuestion<A> extends QuestionCommon<A>,
Pick<QuestionOptions<A>, 'filter' | 'transformer'> {
type?: 'input'
/**
* Provides options for a question for the `NumberPrompt`.
*
* @template T
* The type of the answers.
*/
interface NumberQuestionOptions<T extends Answers = Answers> extends InputQuestionOptions<T> { }
/**
* Provides options for a question for the `NumberPrompt`.
*
* @template T
* The type of the answers.
*/
interface NumberQuestion<T extends Answers = Answers> extends NumberQuestionOptions<T> {
/**
* Receive the user input and answers hash. Should return `true` if the value is valid,
* and an error message (`String`) otherwise. If `false` is returned, a default error
* message is provided.
* @inheritdoc
*/
validate?(input: string, answers?: A): boolean | string | Promise<boolean | string>;
type: "number";
}
interface NumberQuestion<A> extends QuestionCommon<A>,
Pick<QuestionOptions<A>, 'filter' | 'transformer'> {
type: 'number'
/**
* Provides options for a question for the `PasswordPrompt`.
*
* @template T
* The type of the answers.
*/
interface PasswordQuestionOptions<T extends Answers = Answers> extends InputQuestionOptions<T> {
/**
* Receive the user input and answers hash. Should return `true` if the value is valid,
* and an error message (`String`) otherwise. If `false` is returned, a default error
* message is provided.
* The character to replace the user-input.
*/
validate?(input: number, answers?: A): boolean | string | Promise<boolean | string>;
mask?: string;
}
interface PasswordQuestion<A> extends QuestionCommon<A>,
Pick<QuestionOptions<A>, 'filter' | 'transformer'> {
type: 'password'
/**
* Provides options for a question for the `PasswordPrompt`.
*
* @template T
* The type of the answers.
*/
interface PasswordQuestion<T extends Answers = Answers> extends PasswordQuestionOptions<T> {
/**
* Hides the user input.
* @inheritdoc
*/
mask?: string;
type: "password";
}
/**
* Provides options for a question for the `ListPrompt`.
*
* @template T
* The type of the answers.
*/
interface ListQuestionOptions<T extends Answers = Answers> extends ListQuestionOptionsBase<T, ListChoiceMap<T>> { }
/**
* Provides options for a question for the `ListPrompt`.
*
* @template T
* The type of the answers.
*/
interface ListQuestion<T extends Answers = Answers> extends ListQuestionOptions<T> {
/**
* Receive the user input and answers hash. Should return `true` if the value is valid,
* and an error message (`String`) otherwise. If `false` is returned, a default error
* message is provided.
* @inheritdoc
*/
validate?(input: string, answers?: A): boolean | string | Promise<boolean | string>;
type: "list";
}
interface EditorQuestion<A> extends QuestionCommon<A>,
Pick<QuestionOptions<A>, 'filter'> {
type: 'editor'
/**
* Provides options for a question for the `RawListPrompt`.
*
* @template T
* The type of the answers.
*/
interface RawListQuestionOptions<T extends Answers = Answers> extends ListQuestionOptions<T> { }
/**
* Provides options for a question for the `RawListPrompt`.
*
* @template T
* The type of the answers.
*/
interface RawListQuestion<T extends Answers = Answers> extends ListQuestionOptionsBase<T, ListChoiceMap<T>> {
/**
* Receive the user input and answers hash. Should return `true` if the value is valid,
* and an error message (`String`) otherwise. If `false` is returned, a default error
* message is provided.
* @inheritdoc
*/
validate?(input: string, answers?: A): boolean | string | Promise<boolean | string>;
type: "rawlist";
}
/**
* Corresponding to the answer object creation in:
* https://github.com/SBoudrias/Inquirer.js/blob/ff075f587ef78504f0eae4ee5ca0656432429026/packages/inquirer/lib/ui/prompt.js#L88
* Provides options for a question for the `ExpandPrompt`.
*
* @template T
* The type of the answers.
*/
interface Answer {
name: string,
answer: any,
interface ExpandQuestionOptions<T extends Answers = Answers> extends ListQuestionOptionsBase<T, ExpandChoiceMap<T>> { }
/**
* Provides options for a question for the `ExpandPrompt`.
*
* @template T
* The type of the answers.
*/
interface ExpandQuestion<T extends Answers = Answers> extends ExpandQuestionOptions<T> {
/**
* @inheritdoc
*/
type: "expand";
}
/**
* Provides options for a question for the `CheckboxPrompt`.
*
* @template T
* The type of the answers.
*/
interface CheckboxQuestionOptions<T extends Answers = Answers> extends ListQuestionOptionsBase<T, CheckboxChoiceMap<T>> { }
/**
* Provides options for a question for the `CheckboxPrompt`.
*
* @template T
* The type of the answers.
*/
interface CheckboxQuestion<T extends Answers = Answers> extends CheckboxQuestionOptions<T> {
/**
* @inheritdoc
*/
type: "checkbox";
}
/**
* Provides options for a question for the `ConfirmPrompt`.
*
* @template T
* The type of the answers.
*/
interface ConfirmQuestionOptions<T extends Answers = Answers> extends Question<T> { }
/**
* Provides options for a question for the `ConfirmPrompt`.
*
* @template T
* The type of the answers.
*/
interface ConfirmQuestion<T extends Answers = Answers> extends ConfirmQuestionOptions<T> {
/**
* @inheritdoc
*/
type: "confirm";
}
/**
* Provides options for a question for the `EditorPrompt`.
*
* @template T
* The type of the answers.
*/
interface EditorQuestionOptions<T extends Answers = Answers> extends Question<T> { }
/**
* Provides options for a question for the `EditorPrompt`.
*
* @template T
* The type of the answers.
*/
interface EditorQuestion<T extends Answers = Answers> extends EditorQuestionOptions<T> {
/**
* @inheritdoc
*/
type: "editor";
}
/**
* Provides the available question-types.
*
* @template T
* The type of the answers.
*/
interface QuestionMap<T extends Answers = Answers> {
/**
* The `InputQuestion` type.
*/
input: InputQuestion<T>;
/**
* The `NumberQuestion` type.
*/
number: NumberQuestion<T>;
/**
* The `PasswordQuestion` type.
*/
password: PasswordQuestion<T>;
/**
* The `ListQuestion` type.
*/
list: ListQuestion<T>;
/**
* The `RawListQuestion` type.
*/
rawList: RawListQuestion<T>;
/**
* The `ExpandQuestion` type.
*/
expand: ExpandQuestion<T>;
/**
* The `CheckboxQuestion` type.
*/
checkbox: CheckboxQuestion<T>;
/**
* The `ConfirmQuestion` type.
*/
confirm: ConfirmQuestion<T>;
/**
* The `EditorQuestion` type.
*/
editor: EditorQuestion<T>;
}
/**
* Represents one of the available questions.
*
* @template T
* The type of the answers.
*/
type DistinctQuestion<T extends Answers = Answers> = QuestionMap<T>[keyof QuestionMap<T>];
/**
* Represents a collection of questions.
*
* @template T
* The type of the answers.
*/
type QuestionCollection<T extends Answers = Answers> =
| DistinctQuestion<T>
| ReadonlyArray<DistinctQuestion<T>>
| Observable<DistinctQuestion<T>>;
/**
* Provides components for the prompts.
*/
namespace prompts {
/**
* Base prompt implementation
* Should be extended by prompt types.
* Provides a base for and prompt-options.
*
* @interface Base
* @template T
* The type of the answers.
*/
interface Base {
new <A>(question: Question<A>, rl: ReadlineInterface, answers: A): Base;
type PromptOptions<T extends Question = Question> = T & {
/**
* Start the Inquiry session and manage output value filtering
*
* @returns {Promise<any>}
* @memberof Base
* The choices of the prompt.
*/
run(): Promise<any>;
choices: Choices;
};
/**
* Represents the state of a prompt.
*/
type PromptState = LiteralUnion<"pending" | "idle" | "loading" | "answered" | "done">;
/**
* Represents a prompt.
*/
interface PromptBase {
/**
* Called when the UI closes. Override to do any specific cleanup necessary
* Gets or sets a string which represents the state of the prompt.
*/
close(): void;
status: PromptState;
/**
* Generate the prompt question string
* Runs the prompt.
*
* @returns
* The result of the prompt.
*/
getQuestion(): string;
run(): Promise<any>;
}
}
namespace ui {
/**
* Base interface class other can inherits from
* Provides the functionality to initialize new prompts.
*/
interface BaseUI {
rl: ReadlineInterface;
new(opt: StreamOptions): BaseUI;
interface PromptConstructor {
/**
* Handle the ^C exit
* @return {null}
* Initializes a new instance of a prompt.
*
* @param question
* The question to prompt.
*
* @param readLine
* An object for reading from the command-line.
*
* @param answers
* The answers provided by the user.
*/
onForceClose(): void;
/**
* Close the interface and cleanup listeners
*/
close(): void;
new(question: any, readLine: ReadlineInterface, answers: Answers): PromptBase;
}
/**
* Base interface class other can inherits from
* Provides a set of prompt-constructors.
*/
interface PromptUI extends BaseUI {
process: Observable<Answer>;
new(prompts: Prompts, opt: StreamOptions): PromptUI;
run<A>(questions: Questions<A>): Promise<A>;
type PromptCollection = Record<string, PromptConstructor>;
/**
* Provides data about the state of a prompt.
*/
interface PromptStateData {
/**
* Once all prompt are over
* Either a string which describes the error of the prompt or a boolean indicating whether the prompt-value is valid.
*/
onCompletion(): void;
processQuestion<A>(question: Question<A>): Observable<Question<A>>;
fetchAnswer<A>(question: Question<A>): Observable<Question<A>>;
setDefaultType<A>(question: Question<A>): Observable<Question<A>>;
filterIfRunnable<A>(question: Question<A>): Observable<Question<A>>;
isValid: string | boolean;
}
/**
* Sticky bottom bar user interface
* Provides data about the successful state of a prompt.
*
* @param T
* The type of the answer.
*/
interface BottomBar extends BaseUI {
new(opt?: StreamOptions & { bottomBar?: string }): BottomBar;
interface SuccessfulPromptStateData<T = any> extends PromptStateData {
/**
* Render the prompt to screen
* @return self
* @inheritdoc
*/
render(): BottomBar;
clean(): BottomBar;
isValid: true;
/**
* Update the bottom bar content and rerender
* @param bottomBar Bottom bar content
* @return self
* The value of the prompt.
*/
updateBottomBar(bottomBar: string): BottomBar;
value: T;
}
/**
* Provides data about the failed state of a prompt.
*/
interface FailedPromptStateData extends PromptStateData {
/**
* Write out log data
* @param {String} data - The log data to be output
* @return self
* @inheritdoc
*/
writeLog(data: string): BottomBar;
isValid: false | string;
}
/**
* Provides pipes for handling events of a prompt.
*
* @param T
* The type of the answer.
*/
interface PromptEventPipes<T = any> {
/**
* Make sure line end on a line feed
* @param str Input string
* @return The input string with a final line feed
* A pypeline for succesful inputs.
*/
enforceLF(str: string): string;
success: Observable<SuccessfulPromptStateData<T>>;
/**
* Helper for writing message in Prompt
* @param message The message to be output
* An object representing an error.
*/
write(message: string): void;
log: ThroughStream;
error: Observable<FailedPromptStateData>;
}
}
namespace objects {
/**
* Provides components for the ui.
*/
namespace ui {
/**
* Choice object
* Normalize input as choice object
* @constructor
* @param {String|Object} val Choice value. If an object is passed, it should contains
* at least one of `value` or `name` property
* Provides options for the bottom-bar UI.
*/
interface Choice<A> {
new (str: string): Choice<A>;
new (separator: Separator): Choice<A>;
new (option: ChoiceOption<A>): Choice<A>;
interface BottomBarOptions extends StreamOptions {
/**
* The initial text to display.
*/
bottomBar?: string;
}
interface ChoiceOption<A> {
name?: string;
value?: any;
type?: string;
short?: string;
extra?: any;
key?: string;
checked?: boolean;
disabled?: string | (<A>(answers: A) => any);
}
/**
* Choices collection
* Collection of multiple `choice` object
* @constructor
* @param choices All `choice` to keep in the collection
* Represents a fetched answer.
*
* @template T
* The type of the answers.
*/
interface Choices<A> {
new (
choices: ReadonlyArray<string | Separator | ChoiceOption<A>>,
answers?: A
): Choices<A>;
choices: ReadonlyArray<Choice<A>>;
realChoices: ReadonlyArray<Choice<A>>;
length: number;
realLength: number;
type FetchedQuestion<T extends Answers = Answers> = DistinctQuestion<T> & {
/**
* Get a valid choice from the collection
* @param selector The selected choice index
* @return Return the matched choice or undefined
* The type of the question.
*/
getChoice(selector: number): Choice<A>;
type: string;
/**
* Get a raw element from the collection
* @param selector The selected index value
* @return Return the matched choice or undefined
* The message to show to the user.
*/
get(selector: number): Choice<A>;
message: string;
/**
* Match the valid choices against a where clause
* @param whereClause Lodash `where` clause
* @return Matching choices or empty array
* The default value of the question.
*/
where<U extends {}>(whereClause: U): Choice<A>[];
/**
* Pluck a particular key from the choices
* @param propertyName Property name to select
* @return Selected properties
*/
pluck(propertyName: string): any[];
forEach<T>(application: (choice: Choice<A>) => T): T[];
}
default: any;
interface SeparatorStatic {
/**
* @param line Separation line content (facultative)
* The choices of the question.
*/
new (line?: string): Separator;
/**
* Helper function returning false if object is a separator
* @param obj object to test against
* @return `false` if object is a separator
*/
exclude(obj: any): boolean;
}
choices: ChoiceCollection<T>;
};
/**
* Separator object
* Used to space/separate choices group
* @constructor
* @param {String} line Separation line content (facultative)
* Represents a fetched answer.
*/
interface Separator {
type: string;
line: string;
interface FetchedAnswer {
/**
* Stringify separator
* @return {String} the separator display string
* The name of the answer.
*/
toString(): string;
name: string;
/**
* The value of the answer.
*/
answer: any;
}

@@ -438,4 +938,6 @@ }

/**
* Provides the functionality to prompt questions.
*/
declare var inquirer: inquirer.Inquirer;
export = inquirer;
{
"name": "@types/inquirer",
"version": "6.0.3",
"description": "TypeScript definitions for Inquirer.js",
"version": "6.5.0",
"description": "TypeScript definitions for inquirer",
"license": "MIT",

@@ -56,2 +56,7 @@ "contributors": [

"githubUsername": "jedmao"
},
{
"name": "Manuel Thalmann",
"url": "https://github.com/manuth",
"githubUsername": "manuth"
}

@@ -71,4 +76,4 @@ ],

},
"typesPublisherContentHash": "7469f6c5bf9811728d2bc8f62b248ab2cec11d43a243c38be5587c1fb2de2a16",
"typesPublisherContentHash": "3ad7bbf17647a468e5db6e137a5e3edcc026c56aa33f9421315fcb94ca58cf0a",
"typeScriptVersion": "3.3"
}

@@ -5,3 +5,3 @@ # Installation

# Summary
This package contains type definitions for Inquirer.js ( https://github.com/SBoudrias/Inquirer.js ).
This package contains type definitions for inquirer (https://github.com/SBoudrias/Inquirer.js).

@@ -12,7 +12,7 @@ # Details

Additional Details
* Last updated: Wed, 22 May 2019 15:30:00 GMT
* Dependencies: @types/through, @types/rxjs
* Last updated: Wed, 31 Jul 2019 17:22:21 GMT
* Dependencies: @types/rxjs, @types/through
* Global values: none
# Credits
These definitions were written by Qubo <https://github.com/tkQubo>, Parvez <https://github.com/ppathan>, Jouderian <https://github.com/jouderianjr>, Qibang <https://github.com/bang88>, Jason Dreyzehner <https://github.com/bitjson>, Synarque <https://github.com/synarque>, Justin Rockwood <https://github.com/jrockwood>, Keith Kelly <https://github.com/kwkelly>, Richard Lea <https://github.com/chigix>, Jed Mao <https://github.com/jedmao>.
These definitions were written by Qubo <https://github.com/tkQubo>, Parvez <https://github.com/ppathan>, Jouderian <https://github.com/jouderianjr>, Qibang <https://github.com/bang88>, Jason Dreyzehner <https://github.com/bitjson>, Synarque <https://github.com/synarque>, Justin Rockwood <https://github.com/jrockwood>, Keith Kelly <https://github.com/kwkelly>, Richard Lea <https://github.com/chigix>, Jed Mao <https://github.com/jedmao>, and Manuel Thalmann <https://github.com/manuth>.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc