diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 919ccb1..6f30c81 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,12 +10,12 @@ jobs: fail-fast: false matrix: node-version: + - 16 - 14 - 12 - - 10 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/example.js b/example.js index 26bfb51..8aad4d4 100644 --- a/example.js +++ b/example.js @@ -1,25 +1,25 @@ -'use strict'; -const chalk = require('chalk'); -const boxen = require('.'); +import process from 'node:process'; +import chalk from 'chalk'; +import boxen from './index.js'; console.log('\n\n' + boxen(chalk.cyan('unicorn'), { padding: 1, margin: 1, - borderColor: 'yellow' + borderColor: 'yellow', }) + '\n'); console.log('\n\n' + boxen(chalk.cyan('unicorn'), { padding: 1, margin: 1, borderColor: 'yellow', - borderStyle: 'double' + borderStyle: 'double', }) + '\n'); console.log('\n\n' + boxen(chalk.cyan('unicorn'), { padding: 1, margin: 1, borderColor: '#eebbaa', - borderStyle: 'double' + borderStyle: 'double', }) + '\n'); console.log('\n\n' + boxen(chalk.black('unicorn'), { @@ -27,7 +27,7 @@ console.log('\n\n' + boxen(chalk.black('unicorn'), { margin: 1, borderColor: '#ffc0cb', backgroundColor: '#00ffff', - borderStyle: 'double' + borderStyle: 'double', }) + '\n'); console.log('\n\n' + boxen(chalk.black('unicorn'), { @@ -41,8 +41,8 @@ console.log('\n\n' + boxen(chalk.black('unicorn'), { bottomLeft: '+', bottomRight: '+', horizontal: '-', - vertical: '|' - } + vertical: '|', + }, }) + '\n'); const sentences = 'Unbreakable_text_because_it_has_no_spaces '.repeat(5); diff --git a/index.d.ts b/index.d.ts index 69ebd42..1ae2e7c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,171 +1,169 @@ import {LiteralUnion} from 'type-fest'; import {BoxStyle, Boxes} from 'cli-boxes'; -declare namespace boxen { +/** +Characters used for custom border. + +@example +``` +// affffb +// e e +// dffffc + +const border: CustomBorderStyle = { + topLeft: 'a', + topRight: 'b', + bottomRight: 'c', + bottomLeft: 'd', + vertical: 'e', + horizontal: 'f' +}; +``` +*/ +export interface CustomBorderStyle extends BoxStyle {} + +/** +Spacing used for `padding` and `margin`. +*/ +export interface Spacing { + readonly top: number; + readonly right: number; + readonly bottom: number; + readonly left: number; +} + +export interface Options { + /** + Color of the box border. + */ + readonly borderColor?: LiteralUnion< + | 'black' + | 'red' + | 'green' + | 'yellow' + | 'blue' + | 'magenta' + | 'cyan' + | 'white' + | 'gray' + | 'grey' + | 'blackBright' + | 'redBright' + | 'greenBright' + | 'yellowBright' + | 'blueBright' + | 'magentaBright' + | 'cyanBright' + | 'whiteBright', + string + >; + + /** + Style of the box border. + + @default 'single' + */ + readonly borderStyle?: keyof Boxes | CustomBorderStyle; + + /** + Reduce opacity of the border. + + @default false + */ + readonly dimBorder?: boolean; + + /** + Space between the text and box border. + + @default 0 + */ + readonly padding?: number | Spacing; + /** - Characters used for custom border. + Space around the box. + + @default 0 + */ + readonly margin?: number | Spacing; + + /** + Float the box on the available terminal screen space. + + @default 'left' + */ + readonly float?: 'left' | 'right' | 'center'; + + /** + Color of the background. + */ + readonly backgroundColor?: LiteralUnion< + | 'black' + | 'red' + | 'green' + | 'yellow' + | 'blue' + | 'magenta' + | 'cyan' + | 'white' + | 'blackBright' + | 'redBright' + | 'greenBright' + | 'yellowBright' + | 'blueBright' + | 'magentaBright' + | 'cyanBright' + | 'whiteBright', + string + >; + + /** + Align the text in the box based on the widest line. + + @default 'left' + @deprecated Use `textAlignment` instead. + */ + readonly align?: 'left' | 'right' | 'center'; + + /** + Align the text in the box based on the widest line. + + @default 'left' + */ + readonly textAlignment?: 'left' | 'right' | 'center'; + + /** + Display a title at the top of the box. + If needed, the box will horizontally expand to fit the title. @example ``` - // affffb - // e e - // dffffc - - const border: CustomBorderStyle = { - topLeft: 'a', - topRight: 'b', - bottomRight: 'c', - bottomLeft: 'd', - vertical: 'e', - horizontal: 'f' - }; + console.log(boxen('foo bar', {title: 'example'})); + // ┌ example ┐ + // │foo bar │ + // └─────────┘ ``` */ - interface CustomBorderStyle extends BoxStyle {} + readonly title?: string; /** - Spacing used for `padding` and `margin`. + Align the title in the top bar. + + @default 'left' + + @example + ``` + console.log(boxen('foo bar foo bar', {title: 'example', titleAlignment: 'center'})); + // ┌─── example ───┐ + // │foo bar foo bar│ + // └───────────────┘ + + console.log(boxen('foo bar foo bar', {title: 'example', titleAlignment: 'right'})); + // ┌────── example ┐ + // │foo bar foo bar│ + // └───────────────┘ + ``` */ - interface Spacing { - readonly top: number; - readonly right: number; - readonly bottom: number; - readonly left: number; - } - - interface Options { - /** - Color of the box border. - */ - readonly borderColor?: LiteralUnion< - | 'black' - | 'red' - | 'green' - | 'yellow' - | 'blue' - | 'magenta' - | 'cyan' - | 'white' - | 'gray' - | 'grey' - | 'blackBright' - | 'redBright' - | 'greenBright' - | 'yellowBright' - | 'blueBright' - | 'magentaBright' - | 'cyanBright' - | 'whiteBright', - string - >; - - /** - Style of the box border. - - @default 'single' - */ - readonly borderStyle?: keyof Boxes | CustomBorderStyle; - - /** - Reduce opacity of the border. - - @default false - */ - readonly dimBorder?: boolean; - - /** - Space between the text and box border. - - @default 0 - */ - readonly padding?: number | Spacing; - - /** - Space around the box. - - @default 0 - */ - readonly margin?: number | Spacing; - - /** - Float the box on the available terminal screen space. - - @default 'left' - */ - readonly float?: 'left' | 'right' | 'center'; - - /** - Color of the background. - */ - readonly backgroundColor?: LiteralUnion< - | 'black' - | 'red' - | 'green' - | 'yellow' - | 'blue' - | 'magenta' - | 'cyan' - | 'white' - | 'blackBright' - | 'redBright' - | 'greenBright' - | 'yellowBright' - | 'blueBright' - | 'magentaBright' - | 'cyanBright' - | 'whiteBright', - string - >; - - /** - Align the text in the box based on the widest line. - - @default 'left' - @deprecated Use `textAlignment` instead. - */ - readonly align?: 'left' | 'right' | 'center'; - - /** - Align the text in the box based on the widest line. - - @default 'left' - */ - readonly textAlignment?: 'left' | 'right' | 'center'; - - /** - Display a title at the top of the box. - If needed, the box will horizontally expand to fit the title. - - @example - ``` - console.log(boxen('foo bar', {title: 'example'})); - // ┌ example ┐ - // │foo bar │ - // └─────────┘ - ``` - */ - readonly title?: string; - - /** - Align the title in the top bar. - - @default 'left' - - @example - ``` - console.log(boxen('foo bar foo bar', {title: 'example', titleAlignment: 'center'})); - // ┌─── example ───┐ - // │foo bar foo bar│ - // └───────────────┘ - - console.log(boxen('foo bar foo bar', {title: 'example', titleAlignment: 'right'})); - // ┌────── example ┐ - // │foo bar foo bar│ - // └───────────────┘ - ``` - */ - readonly titleAlignment?: 'left' | 'right' | 'center'; - } + readonly titleAlignment?: 'left' | 'right' | 'center'; } /** @@ -176,7 +174,7 @@ Creates a box in the terminal. @example ``` -import boxen = require('boxen'); +import boxen from 'boxen'; console.log(boxen('unicorn', {padding: 1})); // ┌─────────────┐ @@ -195,6 +193,5 @@ console.log(boxen('unicorn', {padding: 1, margin: 1, borderStyle: 'double'})); // ``` */ -declare const boxen: (text: string, options?: boxen.Options) => string; +export default function boxen(text: string, options?: Options): string; -export = boxen; diff --git a/index.js b/index.js index 1489145..e23d282 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,11 @@ -'use strict'; -const stringWidth = require('string-width'); -const chalk = require('chalk'); -const widestLine = require('widest-line'); -const cliBoxes = require('cli-boxes'); -const camelCase = require('camelcase'); -const ansiAlign = require('ansi-align'); -const wrapAnsi = require('wrap-ansi'); +import process from 'node:process'; +import stringWidth from 'string-width'; +import chalk from 'chalk'; +import widestLine from 'widest-line'; +import cliBoxes from 'cli-boxes'; +import camelCase from 'camelcase'; +import ansiAlign from 'ansi-align'; +import wrapAnsi from 'wrap-ansi'; const NEWLINE = '\n'; const PAD = ' '; @@ -28,19 +28,17 @@ const terminalColumns = () => { return 80; }; -const getObject = detail => { - return typeof detail === 'number' ? { - top: detail, - right: detail * 3, - bottom: detail, - left: detail * 3 - } : { - top: 0, - right: 0, - bottom: 0, - left: 0, - ...detail - }; +const getObject = detail => typeof detail === 'number' ? { + top: detail, + right: detail * 3, + bottom: detail, + left: detail * 3, +} : { + top: 0, + right: 0, + bottom: 0, + left: 0, + ...detail, }; const getBorderChars = borderStyle => { @@ -50,7 +48,7 @@ const getBorderChars = borderStyle => { 'bottomRight', 'bottomLeft', 'vertical', - 'horizontal' + 'horizontal', ]; let characters; @@ -166,11 +164,11 @@ const makeContentText = (text, padding, columns, align) => { }); if (padding.top > 0) { - lines = new Array(padding.top).fill(PAD.repeat(columns)).concat(lines); + lines = [...Array.from({length: padding.top}).fill(PAD.repeat(columns)), ...lines]; } if (padding.bottom > 0) { - lines = lines.concat(new Array(padding.bottom).fill(PAD.repeat(columns))); + lines = [...lines, ...Array.from({length: padding.bottom}).fill(PAD.repeat(columns))]; } return lines.join(NEWLINE); @@ -181,7 +179,7 @@ const isColorValid = color => typeof color === 'string' && ((chalk[color]) || is const getColorFn = color => isHex(color) ? chalk.hex(color) : chalk[color]; const getBGColorFn = color => isHex(color) ? chalk.bgHex(color) : chalk[camelCase(['bg', color])]; -module.exports = (text, options) => { +export default function boxen(text, options) { options = { padding: 0, borderStyle: 'single', @@ -189,7 +187,7 @@ module.exports = (text, options) => { textAlignment: 'left', float: 'left', titleAlignment: 'left', - ...options + ...options, }; // This option is deprecated @@ -269,11 +267,9 @@ module.exports = (text, options) => { const lines = text.split(NEWLINE); - const middle = lines.map(line => { - return marginLeft + side + colorizeContent(line) + side; - }).join(LINE_SEPARATOR); + const middle = lines.map(line => marginLeft + side + colorizeContent(line) + side).join(LINE_SEPARATOR); return top + LINE_SEPARATOR + middle + LINE_SEPARATOR + bottom; -}; +} -module.exports._borderStyles = cliBoxes; +export const _borderStyles = cliBoxes; diff --git a/index.test-d.ts b/index.test-d.ts index bf6b370..3f821fe 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,6 +1,5 @@ import {expectType} from 'tsd'; -import boxen = require('.'); -import {Spacing, CustomBorderStyle} from '.'; +import boxen, {Spacing, CustomBorderStyle} from './index.js'; const border: CustomBorderStyle = { topLeft: ' ', @@ -8,14 +7,14 @@ const border: CustomBorderStyle = { bottomLeft: ' ', bottomRight: ' ', horizontal: ' ', - vertical: ' ' + vertical: ' ', }; const spacing: Spacing = { top: 1, right: 0, bottom: 1, - left: 0 + left: 0, }; expectType(boxen('unicorns')); diff --git a/package.json b/package.json index 5ed1c4a..da6364f 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,10 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=10" + "node": ">=12.17" }, "scripts": { "test": "xo && nyc ava && tsd" @@ -35,19 +37,19 @@ "dependencies": { "ansi-align": "^3.0.0", "camelcase": "^6.2.0", - "chalk": "^4.1.0", + "chalk": "^4.1.2", "cli-boxes": "^2.2.1", - "string-width": "^4.2.2", - "type-fest": "^0.20.2", - "typescript": "^4.4.3", - "widest-line": "^3.1.0", - "wrap-ansi": "^7.0.0" + "string-width": "^5.0.1", + "type-fest": "^2.3.4", + "widest-line": "^4.0.0", + "wrap-ansi": "^8.0.1" }, "devDependencies": { "ava": "^3.15.0", "nyc": "^15.1.0", "tsd": "^0.17.0", - "xo": "^0.36.1" + "typescript": "^4.4.3", + "xo": "^0.44.0" }, "ava": { "snapshotDir": "tests/snapshots", diff --git a/readme.md b/readme.md index 4827fac..720121f 100644 --- a/readme.md +++ b/readme.md @@ -7,13 +7,13 @@ ## Install ``` -$ npm install boxen +npm install boxen ``` ## Usage ```js -const boxen = require('boxen'); +import boxen from 'boxen'; console.log(boxen('unicorn', {padding: 1})); /* diff --git a/tests/background-option.js b/tests/background-option.js index fbc8324..53fb998 100644 --- a/tests/background-option.js +++ b/tests/background-option.js @@ -1,5 +1,5 @@ -const test = require('ava'); -const boxen = require('..'); +import test from 'ava'; +import boxen from '../index.js'; test('backgroundColor option', t => { const box = boxen('foo', {backgroundColor: 'red'}); diff --git a/tests/border-option.js b/tests/border-option.js index 5971618..e801604 100644 --- a/tests/border-option.js +++ b/tests/border-option.js @@ -1,9 +1,9 @@ -const test = require('ava'); -const boxen = require('..'); +import test from 'ava'; +import boxen from '../index.js'; test('border color (red)', t => { const box = boxen('foo', { - borderColor: 'red' + borderColor: 'red', }); t.snapshot(box); @@ -11,7 +11,7 @@ test('border color (red)', t => { test('border color (blue)', t => { const box = boxen('foo', { - borderColor: 'blue' + borderColor: 'blue', }); t.snapshot(box); @@ -19,7 +19,7 @@ test('border color (blue)', t => { test('border color (green)', t => { const box = boxen('foo', { - borderColor: 'green' + borderColor: 'green', }); t.snapshot(box); @@ -28,7 +28,7 @@ test('border color (green)', t => { test('border color (yellow + dim)', t => { const box = boxen('foo', { borderColor: 'green', - dimBorder: true + dimBorder: true, }); t.snapshot(box); @@ -37,7 +37,7 @@ test('border color (yellow + dim)', t => { test('border color (hex)', t => { const box = boxen('foo', { borderColor: '#FF00FF', - dimBorder: true + dimBorder: true, }); t.snapshot(box); @@ -51,7 +51,7 @@ test('throws on unexpected borderColor', t => { test('border style (single)', t => { const box = boxen('foo', { - borderStyle: 'single' + borderStyle: 'single', }); t.snapshot(box); @@ -59,7 +59,7 @@ test('border style (single)', t => { test('border style (singleDouble)', t => { const box = boxen('foo', { - borderStyle: 'singleDouble' + borderStyle: 'singleDouble', }); t.snapshot(box); @@ -67,7 +67,7 @@ test('border style (singleDouble)', t => { test('border style (doubleSingle)', t => { const box = boxen('foo', { - borderStyle: 'doubleSingle' + borderStyle: 'doubleSingle', }); t.snapshot(box); @@ -75,7 +75,7 @@ test('border style (doubleSingle)', t => { test('border style (double)', t => { const box = boxen('foo', { - borderStyle: 'double' + borderStyle: 'double', }); t.snapshot(box); @@ -83,7 +83,7 @@ test('border style (double)', t => { test('border style (classic)', t => { const box = boxen('foo', { - borderStyle: 'classic' + borderStyle: 'classic', }); t.snapshot(box); @@ -91,7 +91,7 @@ test('border style (classic)', t => { test('border style (bold)', t => { const box = boxen('foo', { - borderStyle: 'bold' + borderStyle: 'bold', }); t.snapshot(box); @@ -99,7 +99,7 @@ test('border style (bold)', t => { test('border style (round)', t => { const box = boxen('foo', { - borderStyle: 'round' + borderStyle: 'round', }); t.snapshot(box); @@ -113,8 +113,8 @@ test('border style (custom ascii style)', t => { bottomLeft: '3', bottomRight: '4', horizontal: '-', - vertical: '|' - } + vertical: '|', + }, }); t.snapshot(box); @@ -137,7 +137,7 @@ test('throws on unexpected borderStyle as object', t => { topRight: '2', bottomLeft: '3', horizontal: '-', - vertical: '|' + vertical: '|', }; t.throws(() => { diff --git a/tests/float-option.js b/tests/float-option.js index 85ad35b..b8c04ae 100644 --- a/tests/float-option.js +++ b/tests/float-option.js @@ -1,9 +1,10 @@ -const test = require('ava'); -const boxen = require('..'); +import process from 'node:process'; +import test from 'ava'; +import boxen from '../index.js'; test('float option (left)', t => { const box = boxen('foo', { - float: 'left' + float: 'left', }); t.snapshot(box); @@ -11,7 +12,7 @@ test('float option (left)', t => { test('float option (center)', t => { const box = boxen('foo', { - float: 'center' + float: 'center', }); t.snapshot(box); @@ -19,7 +20,7 @@ test('float option (center)', t => { test('float option (right)', t => { const box = boxen('foo', { - float: 'right' + float: 'right', }); t.snapshot(box); @@ -30,8 +31,8 @@ test('float option (center) with margin', t => { float: 'right', margin: { left: 3, - top: 4 - } + top: 4, + }, }); t.snapshot(box); @@ -42,8 +43,8 @@ test('float option (right) with margin', t => { float: 'right', margin: { right: 2, - bottom: 5 - } + bottom: 5, + }, }); t.snapshot(box); @@ -54,12 +55,12 @@ test('float option (center) when content > columns', t => { t.notThrows(() => { boxen(longContent, { - float: 'center' + float: 'center', }); }); const box = boxen(longContent, { - float: 'center' + float: 'center', }); t.snapshot(box); @@ -70,12 +71,12 @@ test('float option (right) when content > columns', t => { t.notThrows(() => { boxen(longContent, { - float: 'right' + float: 'right', }); }); const box = boxen(longContent, { - float: 'right' + float: 'right', }); t.snapshot(box); diff --git a/tests/main.js b/tests/main.js index 7617aaf..20df42e 100644 --- a/tests/main.js +++ b/tests/main.js @@ -1,6 +1,7 @@ -const test = require('ava'); -const chalk = require('chalk'); -const boxen = require('..'); +import process from 'node:process'; +import test from 'ava'; +import chalk from 'chalk'; +import boxen from '../index.js'; const longText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas id erat arcu. Integer urna mauris, sodales vel egestas eu, consequat id turpis. Vivamus faucibus est mattis tincidunt lobortis. In aliquam placerat nunc eget viverra. Duis aliquet faucibus diam, blandit tincidunt magna congue eu. Sed vel ante vestibulum, maximus risus eget, iaculis velit. Quisque id dapibus purus, ut sodales lorem. Aenean laoreet iaculis tellus at malesuada. Donec imperdiet eu lacus vitae fringilla.'; @@ -34,7 +35,7 @@ test('box not overflowing terminal', t => { test('box not overflowing terminal with padding', t => { const box = boxen('foo'.repeat(process.env.COLUMNS), { - padding: 3 + padding: 3, }); t.snapshot(box); @@ -48,7 +49,7 @@ test('box not overflowing terminal with words', t => { test('box not overflowing terminal with words + padding', t => { const box = boxen('foo '.repeat(process.env.COLUMNS), { - padding: 2 + padding: 2, }); t.snapshot(box); @@ -57,7 +58,7 @@ test('box not overflowing terminal with words + padding', t => { test('box not overflowing terminal with words + padding + margin', t => { const box = boxen('foo '.repeat(process.env.COLUMNS), { padding: 2, - magin: 1 + magin: 1, }); t.snapshot(box); diff --git a/tests/margin-option.js b/tests/margin-option.js index 1526606..e85191a 100644 --- a/tests/margin-option.js +++ b/tests/margin-option.js @@ -1,9 +1,10 @@ -const test = require('ava'); -const boxen = require('..'); +import process from 'node:process'; +import test from 'ava'; +import boxen from '../index.js'; test('margin option works', t => { const box = boxen('foo', { - margin: 2 + margin: 2, }); t.snapshot(box); @@ -15,8 +16,8 @@ test('margin option with custom margins', t => { top: 1, left: 2, right: 3, - bottom: 4 - } + bottom: 4, + }, }); t.snapshot(box); @@ -25,7 +26,7 @@ test('margin option with custom margins', t => { test('margin option with padding', t => { const box = boxen('foo', { margin: 1, - padding: 1 + padding: 1, }); t.snapshot(box); @@ -34,21 +35,21 @@ test('margin option with padding', t => { test('margin proportionally decreases when content <= columns', t => { // Plenty space let box = boxen('x'.repeat((process.env.COLUMNS / 2) - 2), { - margin: 2 + margin: 2, }); t.snapshot(box); // A bit of space box = boxen('x'.repeat(process.env.COLUMNS - 6 - 2), { - margin: 2 + margin: 2, }); t.snapshot(box); // No room box = boxen('ax'.repeat(process.env.COLUMNS - 2), { - margin: 2 + margin: 2, }); t.snapshot(box); diff --git a/tests/padding-option.js b/tests/padding-option.js index 262b6cc..0550c70 100644 --- a/tests/padding-option.js +++ b/tests/padding-option.js @@ -1,9 +1,9 @@ -const test = require('ava'); -const boxen = require('..'); +import test from 'ava'; +import boxen from '../index.js'; test('padding option works', t => { const box = boxen('foo', { - padding: 2 + padding: 2, }); t.snapshot(box); @@ -15,8 +15,8 @@ test('padding option advanced', t => { top: 0, bottom: 2, left: 5, - right: 10 - } + right: 10, + }, }); t.snapshot(box); diff --git a/tests/text-align-option.js b/tests/text-align-option.js index 005bbcc..aaab8e7 100644 --- a/tests/text-align-option.js +++ b/tests/text-align-option.js @@ -1,11 +1,11 @@ -const test = require('ava'); -const boxen = require('..'); +import test from 'ava'; +import boxen from '../index.js'; const longText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas id erat arcu. Integer urna mauris, sodales vel egestas eu, consequat id turpis. Vivamus faucibus est mattis tincidunt lobortis. In aliquam placerat nunc eget viverra. Duis aliquet faucibus diam, blandit tincidunt magna congue eu. Sed vel ante vestibulum, maximus risus eget, iaculis velit. Quisque id dapibus purus, ut sodales lorem. Aenean laoreet iaculis tellus at malesuada. Donec imperdiet eu lacus vitae fringilla.'; test('text alignement option (left)', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { - textAlignment: 'left' + textAlignment: 'left', }); t.snapshot(box); @@ -13,7 +13,7 @@ test('text alignement option (left)', t => { test('text alignement option (center)', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { - textAlignment: 'center' + textAlignment: 'center', }); t.snapshot(box); @@ -21,7 +21,7 @@ test('text alignement option (center)', t => { test('text alignement option (right)', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { - textAlignment: 'right' + textAlignment: 'right', }); t.snapshot(box); @@ -30,7 +30,7 @@ test('text alignement option (right)', t => { test('text alignement option (left) + padding', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { textAlignment: 'left', - padding: 1 + padding: 1, }); t.snapshot(box); @@ -39,7 +39,7 @@ test('text alignement option (left) + padding', t => { test('text alignement option (center) + padding', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { textAlignment: 'center', - padding: 1 + padding: 1, }); t.snapshot(box); @@ -48,7 +48,7 @@ test('text alignement option (center) + padding', t => { test('text alignement option (right) + padding', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { textAlignment: 'right', - padding: 1 + padding: 1, }); t.snapshot(box); @@ -57,7 +57,7 @@ test('text alignement option (right) + padding', t => { test('text alignement option (left) + long title', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { textAlignment: 'left', - title: 'This is a famous movie quote:' + title: 'This is a famous movie quote:', }); t.snapshot(box); @@ -66,7 +66,7 @@ test('text alignement option (left) + long title', t => { test('text alignement option (center) + long title', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { textAlignment: 'center', - title: 'This is a famous movie quote:' + title: 'This is a famous movie quote:', }); t.snapshot(box); @@ -75,7 +75,7 @@ test('text alignement option (center) + long title', t => { test('text alignement option (right) + long title', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { textAlignment: 'right', - title: 'This is a famous movie quote:' + title: 'This is a famous movie quote:', }); t.snapshot(box); @@ -85,7 +85,7 @@ test('text alignement option (left) + long title + padding', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { textAlignment: 'left', title: 'This is a famous movie quote:', - padding: 1 + padding: 1, }); t.snapshot(box); @@ -95,7 +95,7 @@ test('text alignement option (center) + long title + padding', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { textAlignment: 'center', title: 'This is a famous movie quote:', - padding: 1 + padding: 1, }); t.snapshot(box); @@ -105,7 +105,7 @@ test('text alignement option (right) + long title + padding', t => { const box = boxen('Hello there !\nGeneral Kenobi !', { textAlignment: 'right', title: 'This is a famous movie quote:', - padding: 1 + padding: 1, }); t.snapshot(box); @@ -116,7 +116,7 @@ test('text alignement option (left) + long title + padding + margin', t => { textAlignment: 'left', title: 'This is a famous movie quote:', margin: 1, - padding: 1 + padding: 1, }); t.snapshot(box); @@ -127,7 +127,7 @@ test('text alignement option (center) + long title + padding + margin', t => { textAlignment: 'center', title: 'This is a famous movie quote:', margin: 1, - padding: 1 + padding: 1, }); t.snapshot(box); @@ -138,7 +138,7 @@ test('text alignement option (right) + long title + padding + margin', t => { textAlignment: 'right', title: 'This is a famous movie quote:', margin: 1, - padding: 1 + padding: 1, }); t.snapshot(box); @@ -146,7 +146,7 @@ test('text alignement option (right) + long title + padding + margin', t => { test('text alignement option (center) after wrapping', t => { const box = boxen(longText, { - textAlignment: 'center' + textAlignment: 'center', }); t.snapshot(box); @@ -154,7 +154,7 @@ test('text alignement option (center) after wrapping', t => { test('text alignement option (right) after wrapping', t => { const box = boxen(longText, { - textAlignment: 'right' + textAlignment: 'right', }); t.snapshot(box); @@ -163,7 +163,7 @@ test('text alignement option (right) after wrapping', t => { test('text alignement option (center) after wrapping + padding', t => { const box = boxen(longText, { textAlignment: 'center', - padding: 1 + padding: 1, }); t.snapshot(box); @@ -173,7 +173,7 @@ test('text alignement option (right) after wrapping + padding + margin', t => { const box = boxen(longText, { textAlignment: 'center', margin: 1, - padding: 1 + padding: 1, }); t.snapshot(box); diff --git a/tests/title-option.js b/tests/title-option.js index ed31e19..bc02600 100644 --- a/tests/title-option.js +++ b/tests/title-option.js @@ -1,9 +1,9 @@ -const test = require('ava'); -const boxen = require('..'); +import test from 'ava'; +import boxen from '../index.js'; test('title option works', t => { const box = boxen('foo', { - title: 'title' + title: 'title', }); t.snapshot(box); @@ -12,7 +12,7 @@ test('title option works', t => { test('title align left', t => { const box = boxen('foo bar foo bar', { title: 'title', - titleAlignment: 'left' + titleAlignment: 'left', }); t.snapshot(box); @@ -21,7 +21,7 @@ test('title align left', t => { test('title align center', t => { const box = boxen('foo bar foo bar', { title: 'title', - titleAlignment: 'center' + titleAlignment: 'center', }); t.snapshot(box); @@ -30,7 +30,7 @@ test('title align center', t => { test('title align right', t => { const box = boxen('foo bar foo bar', { title: 'title', - titleAlignment: 'right' + titleAlignment: 'right', }); t.snapshot(box); @@ -38,7 +38,7 @@ test('title align right', t => { test('long title expands box', t => { const box = boxen('foo', { - title: 'very long title' + title: 'very long title', }); t.snapshot(box);