From 44edbc65edf8ab214eefa483c35201fec0b9e9db Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 31 Dec 2018 18:48:38 +0000 Subject: [PATCH] [boxen] Add types (#31812) --- types/boxen/boxen-tests.ts | 37 ++++++++++++ types/boxen/index.d.ts | 114 +++++++++++++++++++++++++++++++++++++ types/boxen/tsconfig.json | 23 ++++++++ types/boxen/tslint.json | 1 + 4 files changed, 175 insertions(+) create mode 100644 types/boxen/boxen-tests.ts create mode 100644 types/boxen/index.d.ts create mode 100644 types/boxen/tsconfig.json create mode 100644 types/boxen/tslint.json diff --git a/types/boxen/boxen-tests.ts b/types/boxen/boxen-tests.ts new file mode 100644 index 0000000000..303e5dd7fa --- /dev/null +++ b/types/boxen/boxen-tests.ts @@ -0,0 +1,37 @@ +import boxen = require('boxen'); + +boxen('unicorn'); // $ExpectType string +boxen('unicorn', { borderColor: 'black' }); // $ExpectType string +boxen('unicorn', { borderStyle: 'double' }); // $ExpectType string +boxen('unicorn', { borderStyle: 'foo' }); // $ExpectError +// $ExpectType string +boxen('unicorn', { + borderStyle: { + topLeft: '+', + topRight: '+', + bottomLeft: '+', + bottomRight: '+', + horizontal: '-', + vertical: '|', + }, +}); +boxen('unicorn', { dimBorder: true }); // $ExpectType string +boxen('unicorn', { padding: 1 }); // $ExpectType string +boxen('unicorn', { padding: { top: 1 } }); // $ExpectType string +boxen('unicorn', { padding: { right: 1 } }); // $ExpectType string +boxen('unicorn', { padding: { bottom: 1 } }); // $ExpectType string +boxen('unicorn', { padding: { left: 1 } }); // $ExpectType string +boxen('unicorn', { margin: 1 }); // $ExpectType string +boxen('unicorn', { margin: { top: 1 } }); // $ExpectType string +boxen('unicorn', { margin: { right: 1 } }); // $ExpectType string +boxen('unicorn', { margin: { bottom: 1 } }); // $ExpectType string +boxen('unicorn', { margin: { left: 1 } }); // $ExpectType string +boxen('unicorn', { float: 'right' }); // $ExpectType string +boxen('unicorn', { float: 'center' }); // $ExpectType string +boxen('unicorn', { float: 'left' }); // $ExpectType string +boxen('unicorn', { float: 'foo' }); // $ExpectError +boxen('unicorn', { backgroundColor: 'white' }); // $ExpectType string +boxen('unicorn', { align: 'left' }); // $ExpectType string +boxen('unicorn', { align: 'center' }); // $ExpectType string +boxen('unicorn', { align: 'right' }); // $ExpectType string +boxen('unicorn', { align: 'foo' }); // $ExpectError diff --git a/types/boxen/index.d.ts b/types/boxen/index.d.ts new file mode 100644 index 0000000000..94b68bb5c7 --- /dev/null +++ b/types/boxen/index.d.ts @@ -0,0 +1,114 @@ +// Type definitions for boxen 2.1 +// Project: https://github.com/sindresorhus/boxen#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import { BoxDefinition, BoxNames } from 'cli-boxes'; + +export = boxen; + +/** + * Create boxes in the terminal + * @param input Text inside the box. + */ +declare function boxen(input: string, options?: boxen.Options): string; + +declare namespace boxen { + interface Options { + /** + * Color of the box border. + * Values: `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white` `gray` or a hex value like `#ff0000` + */ + borderColor?: string; + + /** + * Style of the box border. + * Can be any of the above predefined styles or an object. + * + * Predefined values: + * - `single` + * ``` + * ┌───┐ + * │foo│ + * └───┘ + * ``` + * - `double` + * ``` + * ╔═══╗ + * ║foo║ + * ╚═══╝ + * ``` + * - `round` (`single` sides with round corners) + * ``` + * ╭───╮ + * │foo│ + * ╰───╯ + * ``` + * - `single-double` (`single` on top and bottom, `double` on right and left) + * ``` + * ╓───╖ + * ║foo║ + * ╙───╜ + * ``` + * - `double-single` (`double` on top and bottom, `single` on right and left) + * ``` + * ╒═══╕ + * │foo│ + * ╘═══╛ + * ``` + * - `classic` + * ``` + * +---+ + * |foo| + * +---+ + * ``` + */ + borderStyle?: BoxNames | BoxDefinition; + + /** + * Reduce opacity of the border. + * @default false + */ + dimBorder?: boolean; + + /** + * Space between the text and box border. + * When a number is specified, the left/right padding is 3 times the top/bottom to make it look nice. + * @default 0 + */ + padding?: number | PositionOptions; + + /** + * Space around the box. + * When a number is specified, the left/right margin is 3 times the top/bottom to make it look nice. + * @default 0 + */ + margin?: number | PositionOptions; + + /** + * Float the box on the available terminal screen space. + * @default 'left' + */ + float?: 'right' | 'center' | 'left'; + + /** + * Color of the background. + * Values: `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white` `gray` or a hex value like `#ff0000` + */ + backgroundColor?: string; + + /** + * Align the text in the box based on the widest line. + * @default 'left' + */ + align?: 'left' | 'center' | 'right'; + } + + interface PositionOptions { + top?: number; + right?: number; + bottom?: number; + left?: number; + } +} diff --git a/types/boxen/tsconfig.json b/types/boxen/tsconfig.json new file mode 100644 index 0000000000..6d34147e83 --- /dev/null +++ b/types/boxen/tsconfig.json @@ -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", + "boxen-tests.ts" + ] +} diff --git a/types/boxen/tslint.json b/types/boxen/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/boxen/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }