sqrup
Surround text with a rectangle and draw attention to it.
const sqrup = require('sqrup');
const result = sqrup('Hello,\nworld!');
console.log(result);
Output:
************
* Hello, *
* world! *
************
Install
npm i sqrup
API
Function signature:
function sqrup(text, options)
With TypeScript types:
function sqrup(text: string | string[], options: string | sqrup.SquareUpOptions): string
type SquareUpOptions = {
default?: string;
left?: string;
right?: string;
top?: string;
bottom?: string;
topLeft?: string;
topRight?: string;
bottomLeft?: string;
bottomRight?: string;
padLeft?: number;
padRight?: number;
padBottom?: number;
padTop?: number;
}
Or you can just take a look at the included index.d.ts
file.
Examples
1. Use custom character
(Instead of the default asterisk *
)
sqrup('One,\nTwo,\nThree.', 'x');
xxxxxxxxxxxx
x One, x
x Two, x
x Three. x
xxxxxxxxxxxx
2. Control the padding between the text and the square
sqrup('WELCOME\n HOME', {
default: 'o',
padLeft: 8,
padRight: 8,
padTop: 2,
padBottom: 2,
});
ooooooooooooooooooooooooo
o o
o o
o WELCOME o
o HOME o
o o
o o
ooooooooooooooooooooooooo
3. Fine grained customization
sqrup('Look Ma,\n I\'m in a box!', {
padLeft: 8,
padRight: 2,
padBottom: 0,
padTop: 2,
left: '▶',
right: '◀',
top: '▼',
bottom: '▲',
topLeft: '◢',
topRight: '◣',
bottomLeft: '◥',
bottomRight: '◤',
});
◢▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼◣
▶ ◀
▶ ◀
▶ Look Ma, ◀
▶ I'm in a box! ◀
◥▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲◤
Defaults
type SquareUpOptions = {
default?: string;
padLeft?: number;
padRight?: number;
padBottom?: number;
padTop?: number;
left?: string;
right?: string;
top?: string;
bottom?: string;
topLeft?: string;
topRight?: string;
bottomLeft?: string;
bottomRight?: string;
}
Extra - How to produce the image at the top
sqrup('\u001b[32msqrup\u001b[39m', {
default: '\u001b[33m*\u001b[39m',
left: '\u001b[33m⁑\u001b[39m',
right: '\u001b[33m⁑\u001b[39m',
padLeft: 6,
padRight: 6,
padBottom: 2,
padTop: 2,
})
License
ISC