Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TypeScript #11

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions types/qoa.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/// <reference types="node" />

declare namespace qoa {
type QoaMethods =
| "prompt"
| "confirm"
| "hidden"
| "input"
| "interactive"
| "keypress"
| "quiz"
| "secure"
| "config"
| "prefix"
| "underlineQuery"
| "clearScreen";

interface QoaConstructor {
new <TTypes extends string = QoaMethods>(): Qoa<TTypes>;
}

interface SecureParams {
type: string;
query: string;
handle: string;
}

interface ConfigParams {
prefix: string;
underlineQuery: boolean;
}

interface QoaBase<TTypes extends string = QoaMethods> {
/**
* Type: Function
* Async: True
* Returns: Object
* @description Create and display a secure prompt.
* @param type {string} "secure" Indicates the type of the prompt. The option is **mandatory** when it is part of the configuration object inside the array passed to `qoa.prompt()` function. Can be considered **optional** when it is part of the object passed to the `qoa.secure()` function.
* @param query {string} The query to be displayed by the prompt.
* @param handle {string} The name of the attribute under which the prompt result will be saved, inside the returned object.
*/
secure(params: SecureParams): object;
/**
* Type: Function
* Async: False
* @description Collectively configure a qoa instance.
* @param prefix {string} "" A string to be included as prefix to the query of each prompt.
* @param underlineQuery {boolean} default false Underline the query of each prompt.
*/
config(params: ConfigParams): void;
/**
* Type: Function
* Async: False
* @description Add a string as prefix to the query of each prompt belonging to the targeted qoa instance.
* @param status {string} A string to be included as prefix to the query of each prompt.
*/
prefix(str: string): void;
/**
* **Type**: Function
* **Async**: False
* @description Underline the query of each prompt belonging to the targeted qoa instance.
* @param status {string} Underline the query of each prompt.
*/
underlineQuery(status: boolean): void;
/**
* **Type**: Function
* **Async**: False
* @description Move the cursor to the top-left corner of the console and clear everything below it.
*/
clearScreen(): void;
}

type Qoa<TTypes extends string = QoaMethods> = QoaBase<TTypes>;
}

declare const qoa: qoa.Qoa & {
Qoa: qoa.QoaConstructor;
QoaMethods: qoa.QoaMethods;
};

export = qoa;
18 changes: 18 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "./",
"typeRoots": ["./"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
},
"files": ["qoa.d.ts"]
}