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

Update dependencies #97

Merged
merged 5 commits into from
Jul 13, 2024
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
10 changes: 9 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ console.log('\n\n' + boxen(sentences, {textAlignment: 'left'}) + '\n');

console.log('\n\n' + boxen(sentences, {textAlignment: 'center'}) + '\n');

console.log('\n\n' + boxen(sentences, {textAlignment: 'right', padding: {left: 1, right: 1, top: 0, bottom: 0}}) + '\n');
console.log('\n\n' + boxen(sentences, {
textAlignment: 'right',
padding: {
left: 1,
right: 1,
top: 0,
bottom: 0,
},
}) + '\n');

const longWord = 'x'.repeat(process.stdout.columns + 20);
console.log('\n\n' + boxen(longWord, {textAlignment: 'center'}) + '\n');
Expand Down
28 changes: 9 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ const makeContentText = (text, {padding, width, textAlignment, height}) => {

const boxContent = (content, contentWidth, options) => {
const colorizeBorder = border => {
const newBorder = options.borderColor ? getColorFn(options.borderColor)(border) : border;
const newBorder = options.borderColor ? getColorFunction(options.borderColor)(border) : border;
return options.dimBorder ? chalk.dim(newBorder) : newBorder;
};

const colorizeContent = content => options.backgroundColor ? getBGColorFn(options.backgroundColor)(content) : content;
const colorizeContent = content => options.backgroundColor ? getBGColorFunction(options.backgroundColor)(content) : content;

const chars = getBorderChars(options.borderStyle);
const columns = terminalColumns();
Expand Down Expand Up @@ -258,24 +258,16 @@ const sanitizeOptions = options => {
newDimensions = options.fullscreen(...newDimensions);
}

if (!options.width) {
options.width = newDimensions[0];
}
options.width ||= newDimensions[0];

if (!options.height) {
options.height = newDimensions[1];
}
options.height ||= newDimensions[1];
}

// If width is provided, make sure it's not below 1
if (options.width) {
options.width = Math.max(1, options.width - getBorderWidth(options.borderStyle));
}
options.width &&= Math.max(1, options.width - getBorderWidth(options.borderStyle));

// If height is provided, make sure it's not below 1
if (options.height) {
options.height = Math.max(1, options.height - getBorderWidth(options.borderStyle));
}
options.height &&= Math.max(1, options.height - getBorderWidth(options.borderStyle));

return options;
};
Expand All @@ -294,9 +286,7 @@ const determineDimensions = (text, options) => {
// If title and width are provided, title adheres to fixed width
if (options.title && widthOverride) {
options.title = options.title.slice(0, Math.max(0, options.width - 2));
if (options.title) {
options.title = formatTitle(options.title, options.borderStyle);
}
options.title &&= formatTitle(options.title, options.borderStyle);
} else if (options.title) {
options.title = options.title.slice(0, Math.max(0, maxWidth - 2));

Expand Down Expand Up @@ -346,8 +336,8 @@ const determineDimensions = (text, options) => {

const isHex = color => color.match(/^#(?:[0-f]{3}){1,2}$/i);
const isColorValid = color => typeof color === 'string' && (chalk[color] ?? isHex(color));
const getColorFn = color => isHex(color) ? chalk.hex(color) : chalk[color];
const getBGColorFn = color => isHex(color) ? chalk.bgHex(color) : chalk[camelCase(['bg', color])];
const getColorFunction = color => isHex(color) ? chalk.hex(color) : chalk[color];
const getBGColorFunction = color => isHex(color) ? chalk.bgHex(color) : chalk[camelCase(['bg', color])];

export default function boxen(text, options) {
options = {
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
],
"dependencies": {
"ansi-align": "^3.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.1.0"
"camelcase": "^8.0.0",
"chalk": "^5.3.0",
"cli-boxes": "^4.0.0",
"string-width": "^7.2.0",
"type-fest": "^4.21.0",
"widest-line": "^5.0.0",
"wrap-ansi": "^9.0.0"
},
"devDependencies": {
"ava": "^5.2.0",
"nyc": "^15.1.0",
"tsd": "^0.28.1",
"xo": "^0.54.2"
"ava": "^6.1.3",
"nyc": "^17.0.0",
"tsd": "^0.31.1",
"xo": "^0.58.0"
},
"ava": {
"snapshotDir": "tests/snapshots",
Expand Down