Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow border to be optional. #88

Merged
merged 6 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.