From 1f9c8e272a8d3398ed520b8b939502f482cc3ae4 Mon Sep 17 00:00:00 2001 From: Caesarovich <38408878+Caesarovich@users.noreply.github.com> Date: Sat, 6 May 2023 21:50:29 +0200 Subject: [PATCH] Allow border to be optional (#88) Co-authored-by: Sindre Sorhus --- index.d.ts | 9 ++++++++- index.js | 10 +++++++++- readme.md | 6 ++++++ tests/border-option.js | 8 ++++++++ tests/snapshots/tests/border-option.js.md | 8 ++++++++ tests/snapshots/tests/border-option.js.snap | Bin 415 -> 429 bytes 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 289e3dd..570505b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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. diff --git a/index.js b/index.js index 70d3e16..9c5e25d 100644 --- a/index.js +++ b/index.js @@ -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]; @@ -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}`); } } diff --git a/readme.md b/readme.md index aea69ac..547d245 100644 --- a/readme.md +++ b/readme.md @@ -116,6 +116,12 @@ Values: ↘↓↓↓↙ →foo← ↗↑↑↑↖ +``` +- `'none'` +``` + +foo + ``` Style of the box border. diff --git a/tests/border-option.js b/tests/border-option.js index 4bd4b39..5c7f30f 100644 --- a/tests/border-option.js +++ b/tests/border-option.js @@ -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: { diff --git a/tests/snapshots/tests/border-option.js.md b/tests/snapshots/tests/border-option.js.md index b2e84d7..33203d8 100644 --- a/tests/snapshots/tests/border-option.js.md +++ b/tests/snapshots/tests/border-option.js.md @@ -100,6 +100,14 @@ Generated by [AVA](https://avajs.dev). │foo│␊ ╰───╯` +## border style (none) + +> Snapshot 1 + + `␊ + foo␊ + ` + ## border style (custom ascii style) > Snapshot 1 diff --git a/tests/snapshots/tests/border-option.js.snap b/tests/snapshots/tests/border-option.js.snap index d22c02bb498741d4198b88d99ac14142234e0f58..20c6afe68a880fe8d6d612953fe78a6d462a17c6 100644 GIT binary patch literal 429 zcmV;e0aE@!RzV|4y1>0Z&(tSzsIAU4HFi;(o93n`xnIt?z3YyHiF?X!ULZ#tL+TI;AT?cr z2{r2!f(Bxqea3o(v+)`Lo7*QxTcz#N<|$W7)p8>YuEXFmsi_eLR~EMo@K z84mVg@er;3h>*9Y{&v$Sd z=a~3TE}EGC%oO)VC}ta)n91%zQJ#LGfr!)2>rLE+Vw#jty@{owtg<5nxlIMiu!Uyo zQBj^_%(;$nvCSBAGdQ~%r`l|_T1{glXOE1iPn~5v&mlP1?cavMIH|eJW)fvHk=;U3 zR;ja$A(Z%D9*THXw)&=R;6qW~v#of<%gDd2F)D_fXe9qjEtRd$IO&@OkoVqNOn{6o#_%^GtaX+>n4B6_FuCSJ9P^bU)p5beAm;6aSRmyg-gPhSVbzKx+8} z6Kd5d1P#Oj_l$K2XTv1`E_Y83H;gS~^;I^FYNZiJ*Ku^2)!2-qs}>>hFS|%l<|%{e z3=fB}df~6 zj!5VgqKWCxOmT0N}<>?n1NI1tucN2H97-uEa-Nal`7V9kpg_nwyVKZ&1 zM@4x~G3PqQ$1Y>YU&GnaI90pZY})2P&K{UapF7KRo=0$@+rN#YVOCS=%_#9^B)gfS zEOKX=LMRD?A{6ner23{M@S!O0S>CmrHzDJsYq`uv=