Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 18, 2021
1 parent 05b187b commit f1a3411
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 52 deletions.
3 changes: 0 additions & 3 deletions .gitignore
@@ -1,8 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
markdown-table.js
markdown-table.min.js
yarn.lock
3 changes: 0 additions & 3 deletions .prettierignore
@@ -1,5 +1,2 @@
coverage/
markdown-table.js
markdown-table.min.js
*.json
*.md
8 changes: 2 additions & 6 deletions 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
Expand Down
25 changes: 11 additions & 14 deletions package.json
Expand Up @@ -21,32 +21,31 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
"dependencies": {
"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",
"remark-cli": "^9.0.0",
"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": [
Expand All @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions readme.md
Expand Up @@ -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
Expand All @@ -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']
Expand All @@ -41,7 +44,7 @@ Yields:
With align:

```js
table(
markdownTable(
[
['Beep', 'No.', 'Boop'],
['beep', '1024', 'xyz'],
Expand All @@ -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.
Expand Down Expand Up @@ -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']
Expand All @@ -200,7 +206,7 @@ With [`string-width`][string-width]:
```js
var width = require('string-width')

table(
markdownTable(
[
['Alpha', 'Bravo'],
['中文', 'Charlie'],
Expand Down
40 changes: 19 additions & 21 deletions 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']
Expand All @@ -22,7 +20,7 @@ test('table()', function (t) {
)

t.equal(
table([
markdownTable([
['Type', 'Value'],
['string', 'alpha'],
['number', 1],
Expand All @@ -45,7 +43,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['A', 'B', 'C'],
['a', 'b', 'c'],
Expand Down Expand Up @@ -77,7 +75,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['Beep', 'No.'],
['boop', '33450'],
Expand All @@ -97,7 +95,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['Beep', 'No.', 'Boop'],
['beep', '1024', 'xyz'],
Expand All @@ -119,7 +117,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['Very long', 'Even longer'],
['boop', '33450'],
Expand All @@ -139,7 +137,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['Beep', 'No.', 'Boop'],
['beep', '1024', 'xyz'],
Expand All @@ -161,7 +159,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['Branch', 'Commit'],
['main', '0123456789abcdef'],
Expand All @@ -179,7 +177,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['Branch', 'Commit', 'Beep', 'No.', 'Boop'],
['main', '0123456789abcdef', 'beep', '1024', 'xyz'],
Expand All @@ -197,7 +195,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['A'],
['', '0123456789abcdef'],
Expand All @@ -217,7 +215,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['Branch', 'Commit'],
['main', '0123456789abcdef'],
Expand All @@ -237,7 +235,7 @@ test('table()', function (t) {
)

t.equal(
table(
markdownTable(
[
['Branch', 'Commit'],
['main', '0123456789abcdef'],
Expand All @@ -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')],
Expand All @@ -270,7 +268,7 @@ test('table()', function (t) {
],
['bar', '45', 'lmno']
],
{align: ['', 'c', 'r'], stringLength: stringLength}
{align: ['', 'c', 'r'], stringLength}
)
),
[
Expand Down

0 comments on commit f1a3411

Please sign in to comment.