This commit is contained in:
2025-08-18 23:06:34 +08:00
parent 0bc04fb659
commit ed18af0cad
1926 changed files with 275098 additions and 0 deletions

16
package/node_modules/cli-columns/color.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
const chalk = require('chalk');
const columns = require('.');
// prettier-ignore
const values = [
'blue' + chalk.bgBlue('berry'),
'笔菠萝' + chalk.yellow('苹果笔'),
chalk.red('apple'), 'pomegranate',
'durian', chalk.green('star fruit'),
'パイナップル', 'apricot', 'banana',
'pineapple', chalk.bgRed.yellow('orange')
];
console.log('');
console.log(columns(values));
console.log('');

82
package/node_modules/cli-columns/index.js generated vendored Normal file
View File

@@ -0,0 +1,82 @@
'use strict';
const stringWidth = require('string-width');
const stripAnsi = require('strip-ansi');
const concat = Array.prototype.concat;
const defaults = {
character: ' ',
newline: '\n',
padding: 2,
sort: true,
width: 0,
};
function byPlainText(a, b) {
const plainA = stripAnsi(a);
const plainB = stripAnsi(b);
if (plainA === plainB) {
return 0;
}
if (plainA > plainB) {
return 1;
}
return -1;
}
function makeArray() {
return [];
}
function makeList(count) {
return Array.apply(null, Array(count));
}
function padCell(fullWidth, character, value) {
const valueWidth = stringWidth(value);
const filler = makeList(fullWidth - valueWidth + 1);
return value + filler.join(character);
}
function toRows(rows, cell, i) {
rows[i % rows.length].push(cell);
return rows;
}
function toString(arr) {
return arr.join('');
}
function columns(values, options) {
values = concat.apply([], values);
options = Object.assign({}, defaults, options);
let cells = values.filter(Boolean).map(String);
if (options.sort !== false) {
cells = cells.sort(byPlainText);
}
const termWidth = options.width || process.stdout.columns;
const cellWidth =
Math.max.apply(null, cells.map(stringWidth)) + options.padding;
const columnCount = Math.floor(termWidth / cellWidth) || 1;
const rowCount = Math.ceil(cells.length / columnCount) || 1;
if (columnCount === 1) {
return cells.join(options.newline);
}
return cells
.map(padCell.bind(null, cellWidth, options.character))
.reduce(toRows, makeList(rowCount).map(makeArray))
.map(toString)
.join(options.newline);
}
module.exports = columns;

20
package/node_modules/cli-columns/license generated vendored Normal file
View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) Shannon Moeller <me@shannonmoeller.com> (shannonmoeller.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

54
package/node_modules/cli-columns/package.json generated vendored Normal file
View File

@@ -0,0 +1,54 @@
{
"name": "cli-columns",
"version": "4.0.0",
"description": "Columnated lists for the CLI.",
"scripts": {
"lint": "npx eslint --fix '*.js' && npx prettier --write '*.js'",
"test": "node test.js && node color.js"
},
"keywords": [
"ansi",
"cli",
"column",
"columnate",
"columns",
"grid",
"list",
"log",
"ls",
"row",
"rows",
"unicode",
"unix"
],
"author": "Shannon Moeller <me@shannonmoeller> (http://shannonmoeller.com)",
"homepage": "https://github.com/shannonmoeller/cli-columns#readme",
"repository": "shannonmoeller/cli-columns",
"license": "MIT",
"main": "index.js",
"files": [
"*.js"
],
"dependencies": {
"string-width": "^4.2.3",
"strip-ansi": "^6.0.1"
},
"devDependencies": {
"chalk": "^4.1.2"
},
"engines": {
"node": ">= 10"
},
"eslintConfig": {
"extends": "eslint:recommended",
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 8
}
},
"prettier": {
"singleQuote": true
}
}

101
package/node_modules/cli-columns/test.js generated vendored Normal file
View File

@@ -0,0 +1,101 @@
'use strict';
const assert = require('assert');
const chalk = require('chalk');
const stripAnsi = require('strip-ansi');
const columns = require('./index.js');
const tests = [];
function test(msg, fn) {
tests.push([msg, fn]);
}
process.nextTick(async function run() {
for (const [msg, fn] of tests) {
try {
await fn(assert);
console.log(`pass - ${msg}`);
} catch (error) {
console.error(`fail - ${msg}`, error);
process.exit(1);
}
}
});
// prettier-ignore
test('should print one column list', t => {
const cols = columns(['foo', ['bar', 'baz'], ['bar', 'qux']], {
width: 1
});
const expected =
'bar\n' +
'bar\n' +
'baz\n' +
'foo\n' +
'qux';
t.equal(cols, expected);
});
// prettier-ignore
test('should print three column list', t => {
const cols = columns(['foo', ['bar', 'baz'], ['bat', 'qux']], {
width: 16
});
const expected =
'bar baz qux \n' +
'bat foo ';
t.equal(cols, expected);
});
// prettier-ignore
test('should print complex list', t => {
const cols = columns(
[
'foo', 'bar', 'baz',
chalk.cyan('嶜憃撊') + ' 噾噿嚁',
'blue' + chalk.bgBlue('berry'),
chalk.red('apple'), 'pomegranate',
'durian', chalk.green('star fruit'),
'apricot', 'banana pineapple'
],
{
width: 80
}
);
const expected =
'apple bar durian star fruit \n' +
'apricot baz foo 嶜憃撊 噾噿嚁 \n' +
'banana pineapple blueberry pomegranate ';
t.equal(stripAnsi(cols), expected);
});
// prettier-ignore
test('should optionally not sort', t => {
const cols = columns(
[
'foo', 'bar', 'baz',
chalk.cyan('嶜憃撊') + ' 噾噿嚁',
'blue' + chalk.bgBlue('berry'),
chalk.red('apple'), 'pomegranate',
'durian', chalk.green('star fruit'),
'apricot', 'banana pineapple'
],
{
sort: false,
width: 80
}
);
const expected =
'foo 嶜憃撊 噾噿嚁 pomegranate apricot \n' +
'bar blueberry durian banana pineapple \n' +
'baz apple star fruit ';
t.equal(stripAnsi(cols), expected);
});