diff --git a/.gitignore b/.gitignore index a834c01..735f4af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .DS_Store *.log -.nyc_output/ coverage/ node_modules/ -markdown-table.js -markdown-table.min.js yarn.lock diff --git a/.prettierignore b/.prettierignore index 3ceaf99..cebe81f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,2 @@ coverage/ -markdown-table.js -markdown-table.min.js -*.json *.md diff --git a/index.js b/index.js index 4abae08..cfa4e7a 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,7 @@ -'use strict' - -var repeat = require('repeat-string') - -module.exports = markdownTable +import repeat from 'repeat-string' // Create a table from a matrix of strings. -function markdownTable(table, options) { +export function markdownTable(table, options) { var settings = options || {} var align = (settings.align || []).concat() var stringLength = settings.stringLength || defaultStringLength diff --git a/package.json b/package.json index 130acb0..6259508 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,9 @@ "contributors": [ "Titus Wormer (https://wooorm.com)" ], + "sideEffects": false, + "type": "module", + "main": "index.js", "files": [ "index.js" ], @@ -28,7 +31,7 @@ "repeat-string": "^1.0.0" }, "devDependencies": { - "browserify": "^17.0.0", + "c8": "^7.0.0", "chalk": "^4.0.0", "nyc": "^15.0.0", "prettier": "^2.0.0", @@ -36,17 +39,13 @@ "remark-preset-wooorm": "^8.0.0", "strip-ansi": "^6.0.0", "tape": "^5.0.0", - "tinyify": "^3.0.0", "xo": "^0.38.0" }, "scripts": { "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "build-bundle": "browserify . -s markdownTable -o markdown-table.js", - "build-mangle": "browserify . -s markdownTable -p tinyify -o markdown-table.min.js", - "build": "npm run build-bundle && npm run build-mangle", - "test-api": "node test", - "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run format && npm run build && npm run test-coverage" + "test-api": "node test.js", + "test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", + "test": "npm run format && npm run test-coverage" }, "remarkConfig": { "plugins": [ @@ -63,13 +62,11 @@ }, "xo": { "prettier": true, - "esnext": false, "rules": { - "complexity": "off" - }, - "ignores": [ - "markdown-table.js" - ] + "complexity": "off", + "no-var": "off", + "prefer-arrow-callback": "off" + } }, "nyc": { "check-coverage": true, diff --git a/readme.md b/readme.md index 2998b31..a7cf92c 100644 --- a/readme.md +++ b/readme.md @@ -9,6 +9,9 @@ Generate fancy [Markdown][fancy] tables. ## Install +This package is ESM only: Node 12+ is needed to use it and it must be `import`ed +instead of `require`d. + [npm][]: ```sh @@ -20,9 +23,9 @@ npm install markdown-table Typical usage (defaults to align left): ```js -var table = require('markdown-table') +import {markdownTable} from 'markdown-table' -table([ +markdownTable([ ['Branch', 'Commit'], ['main', '0123456789abcdef'], ['staging', 'fedcba9876543210'] @@ -41,7 +44,7 @@ Yields: With align: ```js -table( +markdownTable( [ ['Beep', 'No.', 'Boop'], ['beep', '1024', 'xyz'], @@ -66,6 +69,9 @@ Yields: ## API +This package exports the following identifiers: `markdownTable`. +There is no default export. + ### `markdownTable(table[, options])` Turns a given matrix of strings (an array of arrays of strings) into a table. @@ -179,7 +185,7 @@ length of a cell (note that what is and isn’t visible depends on your editor). Without such a function, the following: ```js -table([ +markdownTable([ ['Alpha', 'Bravo'], ['中文', 'Charlie'], ['👩‍❤️‍👩', 'Delta'] @@ -200,7 +206,7 @@ With [`string-width`][string-width]: ```js var width = require('string-width') -table( +markdownTable( [ ['Alpha', 'Bravo'], ['中文', 'Charlie'], diff --git a/test.js b/test.js index 5542334..7953b30 100644 --- a/test.js +++ b/test.js @@ -1,13 +1,11 @@ -'use strict' +import test from 'tape' +import chalk from 'chalk' +import strip from 'strip-ansi' +import {markdownTable} from './index.js' -var test = require('tape') -var chalk = require('chalk') -var strip = require('strip-ansi') -var table = require('.') - -test('table()', function (t) { +test('markdownTable()', function (t) { t.equal( - table([ + markdownTable([ ['Branch', 'Commit'], ['main', '0123456789abcdef'], ['staging', 'fedcba9876543210'] @@ -22,7 +20,7 @@ test('table()', function (t) { ) t.equal( - table([ + markdownTable([ ['Type', 'Value'], ['string', 'alpha'], ['number', 1], @@ -45,7 +43,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['A', 'B', 'C'], ['a', 'b', 'c'], @@ -77,7 +75,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['Beep', 'No.'], ['boop', '33450'], @@ -97,7 +95,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['Beep', 'No.', 'Boop'], ['beep', '1024', 'xyz'], @@ -119,7 +117,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['Very long', 'Even longer'], ['boop', '33450'], @@ -139,7 +137,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['Beep', 'No.', 'Boop'], ['beep', '1024', 'xyz'], @@ -161,7 +159,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['Branch', 'Commit'], ['main', '0123456789abcdef'], @@ -179,7 +177,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['Branch', 'Commit', 'Beep', 'No.', 'Boop'], ['main', '0123456789abcdef', 'beep', '1024', 'xyz'], @@ -197,7 +195,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['A'], ['', '0123456789abcdef'], @@ -217,7 +215,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['Branch', 'Commit'], ['main', '0123456789abcdef'], @@ -237,7 +235,7 @@ test('table()', function (t) { ) t.equal( - table( + markdownTable( [ ['Branch', 'Commit'], ['main', '0123456789abcdef'], @@ -258,7 +256,7 @@ test('table()', function (t) { t.equal( strip( - table( + markdownTable( [ ['A', 'B', 'C'], [chalk.red('Red'), chalk.green('Green'), chalk.blue('Blue')], @@ -270,7 +268,7 @@ test('table()', function (t) { ], ['bar', '45', 'lmno'] ], - {align: ['', 'c', 'r'], stringLength: stringLength} + {align: ['', 'c', 'r'], stringLength} ) ), [