From d1a1ebaf8487d564e069760586f9958ad672f608 Mon Sep 17 00:00:00 2001 From: "Joydip Roy (rjoydip)" Date: Sun, 17 Mar 2019 20:12:41 +0530 Subject: [PATCH] chore: initial type declaration --- types/qoa.d.ts | 82 +++++++++++++++++++++++++++++++++++++++++++++ types/tsconfig.json | 18 ++++++++++ 2 files changed, 100 insertions(+) create mode 100644 types/qoa.d.ts create mode 100644 types/tsconfig.json diff --git a/types/qoa.d.ts b/types/qoa.d.ts new file mode 100644 index 0000000..6706e66 --- /dev/null +++ b/types/qoa.d.ts @@ -0,0 +1,82 @@ +/// + +declare namespace qoa { + type QoaMethods = + | "prompt" + | "confirm" + | "hidden" + | "input" + | "interactive" + | "keypress" + | "quiz" + | "secure" + | "config" + | "prefix" + | "underlineQuery" + | "clearScreen"; + + interface QoaConstructor { + new (): Qoa; + } + + interface SecureParams { + type: string; + query: string; + handle: string; + } + + interface ConfigParams { + prefix: string; + underlineQuery: boolean; + } + + interface QoaBase { + /** + * 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 = QoaBase; +} + +declare const qoa: qoa.Qoa & { + Qoa: qoa.QoaConstructor; + QoaMethods: qoa.QoaMethods; +}; + +export = qoa; \ No newline at end of file diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..a0a9f36 --- /dev/null +++ b/types/tsconfig.json @@ -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"] + } \ No newline at end of file