Installations
npm install markdown-table
Score
99.3
Supply Chain
99.5
Quality
79.4
Maintenance
100
Vulnerability
100
License
Developer
wooorm
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
Yes
Node Version
22.7.0
NPM Version
10.9.0
Statistics
270 Stars
148 Commits
24 Forks
7 Watching
1 Branches
5 Contributors
Updated on 15 Nov 2024
Bundle Size
1.76 kB
Minified
844.00 B
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
773,912,046
Last day
-21.9%
809,261
Compared to previous day
Last week
-2.4%
5,418,963
Compared to previous week
Last month
8.9%
22,802,189
Compared to previous month
Last year
50.3%
218,878,740
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
markdown-table
Generate a markdown (GFM) table.
Contents
- What is this?
- When should I use this?
- Install
- Use
- API
- Types
- Compatibility
- Security
- Inspiration
- Contribute
- License
What is this?
This is a simple package that takes table data and generates a GitHub flavored markdown (GFM) table.
When should I use this?
You can use this package when you want to generate the source code of a GFM table from some data.
This is a simple solution in that it doesn’t handle escapes or HTML or any of
that.
For a complete but heavier solution, build an AST and serialize it with
mdast-util-to-markdown
(with
mdast-util-gfm
).
Install
This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:
1npm install markdown-table
In Deno with esm.sh
:
1import {markdownTable} from 'https://esm.sh/markdown-table@3'
In browsers with esm.sh
:
1<script type="module"> 2 import {markdownTable} from 'https://esm.sh/markdown-table@3?bundle' 3</script>
Use
Typical usage (defaults to align left):
1import {markdownTable} from 'markdown-table' 2 3markdownTable([ 4 ['Branch', 'Commit'], 5 ['main', '0123456789abcdef'], 6 ['staging', 'fedcba9876543210'] 7])
Yields:
1| Branch | Commit | 2| ------- | ---------------- | 3| main | 0123456789abcdef | 4| staging | fedcba9876543210 |
With align:
1markdownTable( 2 [ 3 ['Beep', 'No.', 'Boop'], 4 ['beep', '1024', 'xyz'], 5 ['boop', '3388450', 'tuv'], 6 ['foo', '10106', 'qrstuv'], 7 ['bar', '45', 'lmno'] 8 ], 9 {align: ['l', 'c', 'r']} 10)
Yields:
1| Beep | No. | Boop | 2| :--- | :-----: | -----: | 3| beep | 1024 | xyz | 4| boop | 3388450 | tuv | 5| foo | 10106 | qrstuv | 6| bar | 45 | lmno |
API
This package exports the identifier markdownTable
.
There is no default export.
markdownTable(table[, options])
Generate a markdown table from table data (matrix of strings).
options
Configuration (optional).
options.align
One style for all columns, or styles for their respective columns (string
or
Array<string>
).
Each style is either 'l'
(left), 'r'
(right), or 'c'
(center).
Other values are treated as ''
, which doesn’t place the colon in the alignment
row but does align left.
Only the lowercased first character is used, so Right
is fine.
options.padding
Whether to add a space of padding between delimiters and cells (boolean
,
default: true
).
When true
, there is padding:
1| Alpha | B | 2| ----- | ----- | 3| C | Delta |
When false
, there is no padding:
1|Alpha|B | 2|-----|-----| 3|C |Delta|
options.delimiterStart
Whether to begin each row with the delimiter (boolean
, default: true
).
👉 Note: please don’t use this: it could create fragile structures that aren’t understandable to some markdown parsers.
When true
, there are starting delimiters:
1| Alpha | B | 2| ----- | ----- | 3| C | Delta |
When false
, there are no starting delimiters:
1Alpha | B | 2----- | ----- | 3C | Delta |
options.delimiterEnd
Whether to end each row with the delimiter (boolean
, default: true
).
👉 Note: please don’t use this: it could create fragile structures that aren’t understandable to some markdown parsers.
When true
, there are ending delimiters:
1| Alpha | B | 2| ----- | ----- | 3| C | Delta |
When false
, there are no ending delimiters:
1| Alpha | B 2| ----- | ----- 3| C | Delta
options.alignDelimiters
Whether to align the delimiters (boolean
, default: true
).
By default, they are aligned:
1| Alpha | B | 2| ----- | ----- | 3| C | Delta |
Pass false
to make them staggered:
1| Alpha | B | 2| - | - | 3| C | Delta |
options.stringLength
Function to detect the length of table cell content (Function
, default:
s => s.length
).
This is used when aligning the delimiters (|
) between table cells.
Full-width characters and emoji mess up delimiter alignment when viewing the
markdown source.
To fix this, you can pass this function, which receives the cell content and
returns its “visible” size.
Note that what is and isn’t visible depends on where the text is displayed.
Without such a function, the following:
1markdownTable([ 2 ['Alpha', 'Bravo'], 3 ['中文', 'Charlie'], 4 ['👩❤️👩', 'Delta'] 5])
Yields:
1| Alpha | Bravo | 2| - | - | 3| 中文 | Charlie | 4| 👩❤️👩 | Delta |
With string-width
:
1import stringWidth from 'string-width' 2 3markdownTable( 4 [ 5 ['Alpha', 'Bravo'], 6 ['中文', 'Charlie'], 7 ['👩❤️👩', 'Delta'] 8 ], 9 {stringLength: stringWidth} 10)
Yields:
1| Alpha | Bravo | 2| ----- | ------- | 3| 中文 | Charlie | 4| 👩❤️👩 | Delta |
Types
This package is fully typed with TypeScript.
It exports the additional type Options
.
Compatibility
This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.
Security
This package is safe.
Inspiration
The original idea and basic implementation was inspired by James Halliday’s
text-table
library.
Contribute
Yes please! See How to Contribute to Open Source.
License
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
11 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 9
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:6: update your workflow using https://app.stepsecurity.io/secureworkflow/wooorm/markdown-table/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/wooorm/markdown-table/main.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/wooorm/markdown-table/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:11
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
4.3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More