From e009d1c3c0747b1147c077e1b1ac6ef4a91f01ea Mon Sep 17 00:00:00 2001 From: Kent Wong Date: Thu, 6 Dec 2018 16:43:14 -0800 Subject: [PATCH] Typings for cli-box (https://github.com/IonicaBizau/node-cli-box). --- types/cli-box/cli-box-tests.ts | 47 +++++++++++++++++++++++ types/cli-box/index.d.ts | 70 ++++++++++++++++++++++++++++++++++ types/cli-box/tsconfig.json | 23 +++++++++++ types/cli-box/tslint.json | 1 + 4 files changed, 141 insertions(+) create mode 100644 types/cli-box/cli-box-tests.ts create mode 100644 types/cli-box/index.d.ts create mode 100644 types/cli-box/tsconfig.json create mode 100644 types/cli-box/tslint.json diff --git a/types/cli-box/cli-box-tests.ts b/types/cli-box/cli-box-tests.ts new file mode 100644 index 0000000000..a26b436e21 --- /dev/null +++ b/types/cli-box/cli-box-tests.ts @@ -0,0 +1,47 @@ +import Box = require('cli-box'); + +// Create a simple box +const b1: Box = Box("20x10"); +// console.log(b1.toString()); + +// Set custom marks +const b2: Box = new Box({ + w: 10 + , h: 10 + , stringify: false + , marks: { + nw: "╔" + , n: "══" + , ne: "╗" + , e: "║" + , se: "╝" + , s: "══" + , sw: "╚" + , w: "║" + , b: "░░" + } +}); +// console.log(b2.stringify()); + +// Box with text and use the stringify +const b3: Box = Box("20x10", "I will be \u001b[31mdis\u001b[0mplayed inside! \n A\u001b[34mnd I'm in a\u001b[0m new line!"); +// console.log(b3); + +// Box with aligned text to top-right +const b4: Box = Box("30x20", { + text: "Box content" + , stretch: true + , autoEOL: true + , vAlign: "top" + , hAlign: "right" +}); +// console.log(b4); + +// Full screen box +const b5: Box = Box({fullscreen: true, marks: {}}, "Hello World!"); +// console.log(b5.toString()); + +const b5s: string = Box({stringify: true, fullscreen: true, marks: {}}, "Hello World!"); +const b5ns: Box = Box({stringify: false, fullscreen: true, marks: {}}, "Hello World!"); + +const defaults = Box.defaults; diff --git a/types/cli-box/index.d.ts b/types/cli-box/index.d.ts new file mode 100644 index 0000000000..c2466853a6 --- /dev/null +++ b/types/cli-box/index.d.ts @@ -0,0 +1,70 @@ +// Type definitions for cli-box 6.0 +// Project: https://github.com/IonicaBizau/node-cli-box +// Definitions by: Kent Wong +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +/*~ Note that ES6 modules cannot directly export callable functions. + *~ This file should be imported using the CommonJS-style: + *~ import x = require('someLibrary'); + *~ + *~ Refer to the documentation to understand common + *~ workarounds for this limitation of ES6 modules. + */ + +/*~ This declaration specifies that the function + *~ is the exported object from the file + */ +export = Box; + +type MarksKeys = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'b'; +type Marks = Record; + +interface Options { + w?: number; + width?: number; + h?: number; + height?: number; + fullscreen?: boolean; + stringify?: boolean; + marks?: Partial; +} + +interface Text { + text?: string; + stretch?: boolean; + autoEOL?: boolean; + hAlign?: 'left' | 'middle' | 'right'; + vAlign?: 'top' | 'center' | 'bottom'; +} + +interface Box { + stringify(): string; + settings: { + width: number; + height: number; + marks: Marks; + lines: Array<{ + text: string; + offset: { + y: number; + } + }> + }; + options: { + width: number; + height: number; + marks: Marks; + fullscreen: boolean; + stringify: boolean; + }; +} + +interface BoxConstructor { + new(options: Options | string, text?: Text | string): Box; + (options: (Exclude & { stringify: true }), text?: Text | string): string; + (options: Options | string, text?: Text | string): Box; + defaults: { marks: Marks }; +} + +declare const Box: BoxConstructor; diff --git a/types/cli-box/tsconfig.json b/types/cli-box/tsconfig.json new file mode 100644 index 0000000000..d9a3d38876 --- /dev/null +++ b/types/cli-box/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cli-box-tests.ts" + ] +} diff --git a/types/cli-box/tslint.json b/types/cli-box/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cli-box/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }