Skip to content

Commit

Permalink
upgrade deps, drop heavy dev deps, github actions, node 10+
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonmoeller committed Sep 23, 2021
1 parent b9e986b commit 5da2489
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 37 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
@@ -0,0 +1,27 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions color.js
@@ -1,6 +1,7 @@
const chalk = require('chalk');
const columns = require('.');

// prettier-ignore
const values = [
'blue' + chalk.bgBlue('berry'),
'笔菠萝' + chalk.yellow('苹果笔'),
Expand Down
9 changes: 4 additions & 5 deletions index.js
Expand Up @@ -9,7 +9,7 @@ const defaults = {
newline: '\n',
padding: 2,
sort: true,
width: 0
width: 0,
};

function byPlainText(a, b) {
Expand Down Expand Up @@ -56,16 +56,15 @@ function columns(values, options) {
values = concat.apply([], values);
options = Object.assign({}, defaults, options);

let cells = values
.filter(Boolean)
.map(String);
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 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;

Expand Down
90 changes: 90 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 19 additions & 11 deletions package.json
@@ -1,10 +1,10 @@
{
"name": "cli-columns",
"version": "3.1.2",
"version": "4.0.0",
"description": "Columnated lists for the CLI.",
"scripts": {
"report": "nyc report -r text-lcov | coveralls",
"test": "xo && nyc ava"
"lint": "npx eslint --fix '*.js' && npx prettier --write '*.js'",
"test": "node test.js && node color.js"
},
"keywords": [
"ansi",
Expand All @@ -30,17 +30,25 @@
"*.js"
],
"dependencies": {
"string-width": "^2.0.0",
"strip-ansi": "^3.0.1"
"string-width": "^4.2.3",
"strip-ansi": "^6.0.1"
},
"devDependencies": {
"ava": "^0.19.1",
"chalk": "^1.1.3",
"coveralls": "^2.13.1",
"nyc": "^11.0.2",
"xo": "^0.18.2"
"chalk": "^4.1.2"
},
"engines": {
"node": ">= 4"
"node": ">= 10"
},
"eslintConfig": {
"extends": "eslint:recommended",
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 8
}
},
"prettier": {
"singleQuote": true
}
}
39 changes: 31 additions & 8 deletions test.js
@@ -1,8 +1,28 @@
import test from 'ava';
import chalk from 'chalk';
import stripAnsi from 'strip-ansi';
import columns from './index';
'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
Expand All @@ -15,9 +35,10 @@ test('should print one column list', t => {
'foo\n' +
'qux';

t.is(cols, expected);
t.equal(cols, expected);
});

// prettier-ignore
test('should print three column list', t => {
const cols = columns(['foo', ['bar', 'baz'], ['bat', 'qux']], {
width: 16
Expand All @@ -27,9 +48,10 @@ test('should print three column list', t => {
'bar baz qux \n' +
'bat foo ';

t.is(cols, expected);
t.equal(cols, expected);
});

// prettier-ignore
test('should print complex list', t => {
const cols = columns(
[
Expand All @@ -50,9 +72,10 @@ test('should print complex list', t => {
'apricot baz foo 嶜憃撊 噾噿嚁 \n' +
'banana pineapple blueberry pomegranate ';

t.is(stripAnsi(cols), expected);
t.equal(stripAnsi(cols), expected);
});

// prettier-ignore
test('should optionally not sort', t => {
const cols = columns(
[
Expand All @@ -74,5 +97,5 @@ test('should optionally not sort', t => {
'bar blueberry durian banana pineapple \n' +
'baz apple star fruit ';

t.is(stripAnsi(cols), expected);
t.equal(stripAnsi(cols), expected);
});

0 comments on commit 5da2489

Please sign in to comment.