Skip to content

Commit

Permalink
Allow border to be optional (#88)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
Caesarovich and sindresorhus authored May 6, 2023
1 parent 5de2a4f commit 1f9c8e2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
9 changes: 8 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import {LiteralUnion} from 'type-fest';
import {BoxStyle, Boxes} from 'cli-boxes';
import {BoxStyle, Boxes as CLIBoxes} from 'cli-boxes';

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

/**
Characters used for custom border.
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ const getBorderChars = borderStyle => {

let characters;

// Create empty border style
if (borderStyle === 'none') {
borderStyle = {};
for (const side of sides) {
borderStyle[side] = '';
}
}

if (typeof borderStyle === 'string') {
characters = cliBoxes[borderStyle];

Expand All @@ -76,7 +84,7 @@ const getBorderChars = borderStyle => {
}

for (const side of sides) {
if (!borderStyle[side] || typeof borderStyle[side] !== 'string') {
if (borderStyle[side] === null || typeof borderStyle[side] !== 'string') {
throw new TypeError(`Invalid border style: ${side}`);
}
}
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ Values:
↘↓↓↓↙
→foo←
↗↑↑↑↖
```
- `'none'`
```
foo
```

Style of the box border.
Expand Down
8 changes: 8 additions & 0 deletions tests/border-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ test('border style (round)', t => {
t.snapshot(box);
});

test('border style (none)', t => {
const box = boxen('foo', {
borderStyle: 'none',
});

t.snapshot(box);
});

test('border style (custom ascii style)', t => {
const box = boxen('foo', {
borderStyle: {
Expand Down
8 changes: 8 additions & 0 deletions tests/snapshots/tests/border-option.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ Generated by [AVA](https://avajs.dev).
│foo│␊
╰───╯`

## border style (none)

> Snapshot 1
`␊
foo␊
`

## border style (custom ascii style)

> Snapshot 1
Expand Down
Binary file modified tests/snapshots/tests/border-option.js.snap
Binary file not shown.

0 comments on commit 1f9c8e2

Please sign in to comment.