Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 6, 2023
1 parent 1f9c8e2 commit 662cc0d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
20 changes: 10 additions & 10 deletions index.d.ts
@@ -1,12 +1,12 @@
import {LiteralUnion} from 'type-fest';
import {BoxStyle, Boxes as CLIBoxes} from 'cli-boxes';
import {type LiteralUnion} from 'type-fest';
import {type BoxStyle, type Boxes as CLIBoxes} from 'cli-boxes';

/**
All box styles.
*/
interface Boxes extends CLIBoxes {
type Boxes = {
readonly none: BoxStyle;
}
} & CLIBoxes;

/**
Characters used for custom border.
Expand All @@ -29,7 +29,7 @@ const border: CustomBorderStyle = {
};
```
*/
export interface CustomBorderStyle extends BoxStyle {
export type CustomBorderStyle = {
/**
@deprecated Use `top` and `bottom` instead.
*/
Expand All @@ -39,19 +39,19 @@ export interface CustomBorderStyle extends BoxStyle {
@deprecated Use `left` and `right` instead.
*/
vertical?: string;
}
} & BoxStyle;

/**
Spacing used for `padding` and `margin`.
*/
export interface Spacing {
export type Spacing = {
readonly top?: number;
readonly right?: number;
readonly bottom?: number;
readonly left?: number;
}
};

export interface Options {
export type Options = {
/**
Color of the box border.
*/
Expand Down Expand Up @@ -235,7 +235,7 @@ export interface Options {
```
*/
readonly fullscreen?: boolean | ((width: number, height: number) => [width: number, height: number]);
}
};

/**
Creates a box in the terminal.
Expand Down
33 changes: 24 additions & 9 deletions index.js
Expand Up @@ -101,13 +101,17 @@ const makeTitle = (text, horizontal, alignement) => {
const textWidth = stringWidth(text);

switch (alignement) {
case 'left':
case 'left': {
title = text + horizontal.slice(textWidth);
break;
case 'right':
}

case 'right': {
title = horizontal.slice(textWidth) + text;
break;
default:
}

default: {
horizontal = horizontal.slice(textWidth);

if (horizontal.length % 2 === 1) { // This is needed in case the length is odd
Expand All @@ -119,6 +123,7 @@ const makeTitle = (text, horizontal, alignement) => {
}

break;
}
}

return title;
Expand All @@ -142,15 +147,20 @@ const makeContentText = (text, {padding, width, textAlignment, height}) => {
for (const alignedLine of alignedLinesArray) {
let paddedLine;
switch (textAlignment) {
case 'center':
case 'center': {
paddedLine = PAD.repeat((max - longestLength) / 2) + alignedLine;
break;
case 'right':
}

case 'right': {
paddedLine = PAD.repeat(max - longestLength) + alignedLine;
break;
default:
}

default: {
paddedLine = alignedLine;
break;
}
}

newLines.push(paddedLine);
Expand All @@ -174,12 +184,17 @@ const makeContentText = (text, {padding, width, textAlignment, height}) => {
lines = lines.map(line => {
if (width - stringWidth(line) > 0) {
switch (textAlignment) {
case 'center':
case 'center': {
return line + PAD.repeat(width - stringWidth(line));
case 'right':
}

case 'right': {
return line + PAD.repeat(width - stringWidth(line));
default:
}

default: {
return line + PAD.repeat(width - stringWidth(line));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import boxen, {Spacing, CustomBorderStyle} from './index.js';
import boxen, {type Spacing, type CustomBorderStyle} from './index.js';

const border: CustomBorderStyle = {
topLeft: ' ',
Expand Down
19 changes: 13 additions & 6 deletions package.json
Expand Up @@ -36,25 +36,32 @@
],
"dependencies": {
"ansi-align": "^3.0.1",
"camelcase": "^7.0.0",
"chalk": "^5.0.1",
"camelcase": "^7.0.1",
"chalk": "^5.2.0",
"cli-boxes": "^3.0.0",
"string-width": "^5.1.2",
"type-fest": "^2.13.0",
"widest-line": "^4.0.1",
"wrap-ansi": "^8.0.1"
"wrap-ansi": "^8.1.0"
},
"devDependencies": {
"ava": "^4.3.0",
"ava": "^5.2.0",
"nyc": "^15.1.0",
"tsd": "^0.21.0",
"xo": "^0.50.0"
"tsd": "^0.28.1",
"xo": "^0.54.2"
},
"ava": {
"snapshotDir": "tests/snapshots",
"environmentVariables": {
"COLUMNS": "60",
"FORCE_COLOR": "0"
}
},
"xo": {
"rules": {
"@typescript-eslint/no-redundant-type-constituents": "off",
"unicorn/prefer-logical-operator-over-ternary": "off",
"@typescript-eslint/no-unsafe-assignment": "off"
}
}
}
12 changes: 0 additions & 12 deletions readme.md
Expand Up @@ -301,15 +301,3 @@ Align the text in the box based on the widest line.
- [boxen-cli](https://github.com/sindresorhus/boxen-cli) - CLI for this module
- [cli-boxes](https://github.com/sindresorhus/cli-boxes) - Boxes for use in the terminal
- [ink-box](https://github.com/sindresorhus/ink-box) - Box component for Ink that uses this package

---

<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-boxen?utm_source=npm-boxen&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>

0 comments on commit 662cc0d

Please sign in to comment.