Skip to content

Commit

Permalink
Update dependencies (#97)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
fregante and sindresorhus authored Jul 13, 2024
1 parent 3a9c751 commit 8f6ed57
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
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

0 comments on commit 8f6ed57

Please sign in to comment.