Add types for cli-interact

This commit is contained in:
Florian Keller
2018-09-25 10:33:47 +02:00
parent adf4e18eef
commit 980bac6265
4 changed files with 73 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import * as cliInteract from 'cli-interact';
cliInteract.getChar('Tell me one of', 'abcdef');
cliInteract.getChoiceByChar('frequency', ['daily', 'weekly', 'monthly']);
cliInteract.getChoiceByChar('frequency', ['daily', 'weekly', 'monthly'], true);
cliInteract.getChoice('frequency', ['daily', 'weekly', 'monthly']);
cliInteract.getChoice('frequency', ['daily', 'weekly', 'monthly'], {
returnNumeric: true,
});
cliInteract.getIPversion(true);
cliInteract.getNumber('Case 1: You MAY give me a number: ', {allowNoAnswer: true});
cliInteract.getNumber('Case 2: You MUST give me a number: ');
cliInteract.getNumber('Case 3: You MUST give me an integer: ', true);
cliInteract.getNumber('Case 4: You MAY give me an answer. If you do, it MUST be an integer', {
allowNoAnswer: true,
requireInteger: true,
});
cliInteract.getYesNo('Is it true', true);
cliInteract.getYesNo('Is it true');
cliInteract.question('Tell me what do you want: ', {
charlist: 'yn'
});
+27
View File
@@ -0,0 +1,27 @@
// Type definitions for cli-interact 0.1
// Project: https://github.com/zhami/cli-interact
// Definitions by: Florian Keller <https://github.com/ffflorian>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { BasicOptions } from 'readline-sync';
export interface ChoiceOptions {
allowNoAnswer?: boolean;
returnNumeric?: boolean;
}
export interface NumberOptions {
allowNoAnswer?: boolean;
requireInteger?: boolean;
}
export function getChar(promptText: string, allowedCharsAsString: string, flagAllowNoAnswer?: boolean): string;
export function getChoice(title: string, choices: string[], opts: ChoiceOptions & {returnNumeric: true}): number;
export function getChoice(title: string, choices: string[], opts?: ChoiceOptions): string;
export function getChoiceByChar(title: string, choices: string[], flagAllowNoAnswer?: boolean): string;
export function getInteger(promptText: string): number;
export function getIPversion(flagAllowNoAnswer?: boolean): string;
export function getNumber(promptText: string, opts?: boolean | NumberOptions): number;
export function getYesNo(title: string, flagAllowNoAnswer: true): boolean | undefined;
export function getYesNo(title: string, flagAllowNoAnswer?: false): boolean;
export function question(prompt: string, options?: BasicOptions): string;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"cli-interact-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }