[boxen] Add types (#31812)

This commit is contained in:
Dimitri Benin 2018-12-31 18:48:38 +00:00 committed by Sheetal Nandi
parent a0f4fe7299
commit 44edbc65ed
4 changed files with 175 additions and 0 deletions

View File

@ -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

114
types/boxen/index.d.ts vendored Normal file
View File

@ -0,0 +1,114 @@
// Type definitions for boxen 2.1
// Project: https://github.com/sindresorhus/boxen#readme
// Definitions by: BendingBender <https://github.com/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;
}
}

23
types/boxen/tsconfig.json Normal file
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",
"boxen-tests.ts"
]
}

1
types/boxen/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }