markdown-table
Advanced tools
Comparing version 1.1.2 to 1.1.3
87
index.js
'use strict' | ||
/* Expose. */ | ||
module.exports = markdownTable | ||
/* Expressions. */ | ||
var EXPRESSION_DOT = /\./ | ||
var EXPRESSION_LAST_DOT = /\.[^.]*$/ | ||
var dotRe = /\./ | ||
var lastDotRe = /\.[^.]*$/ | ||
/* Allowed alignment values. */ | ||
var LEFT = 'l' | ||
var RIGHT = 'r' | ||
var CENTER = 'c' | ||
var DOT = '.' | ||
var NULL = '' | ||
// Characters. | ||
var space = ' ' | ||
var lineFeed = '\n' | ||
var dash = '-' | ||
var dot = '.' | ||
var colon = ':' | ||
var lowercaseC = 'c' | ||
var lowercaseL = 'l' | ||
var lowercaseR = 'r' | ||
var verticalBar = '|' | ||
var ALLIGNMENT = [LEFT, RIGHT, CENTER, DOT, NULL] | ||
var MIN_CELL_SIZE = 3 | ||
var minCellSize = 3 | ||
/* Characters. */ | ||
var COLON = ':' | ||
var DASH = '-' | ||
var PIPE = '|' | ||
var SPACE = ' ' | ||
var NEW_LINE = '\n' | ||
/* Create a table from a matrix of strings. */ | ||
// Create a table from a matrix of strings. | ||
function markdownTable(table, options) { | ||
@@ -55,11 +49,11 @@ var settings = options || {} | ||
if (delimiter === null || delimiter === undefined) { | ||
delimiter = SPACE + PIPE + SPACE | ||
delimiter = space + verticalBar + space | ||
} | ||
if (start === null || start === undefined) { | ||
start = PIPE + SPACE | ||
start = verticalBar + space | ||
} | ||
if (end === null || end === undefined) { | ||
end = SPACE + PIPE | ||
end = space + verticalBar | ||
} | ||
@@ -80,3 +74,3 @@ | ||
if (!sizes[index]) { | ||
sizes[index] = MIN_CELL_SIZE | ||
sizes[index] = minCellSize | ||
} | ||
@@ -94,3 +88,3 @@ | ||
/* Make sure only valid alignments are used. */ | ||
// Make sure only valid alignments are used. | ||
index = -1 | ||
@@ -105,4 +99,9 @@ | ||
if (ALLIGNMENT.indexOf(align) === -1) { | ||
align = NULL | ||
if ( | ||
align !== lowercaseL && | ||
align !== lowercaseR && | ||
align !== lowercaseC && | ||
align !== dot | ||
) { | ||
align = '' | ||
} | ||
@@ -127,3 +126,3 @@ | ||
if (alignment[index] === DOT) { | ||
if (alignment[index] === dot) { | ||
position = dotindex(value) | ||
@@ -133,3 +132,3 @@ | ||
sizes[index] + | ||
(EXPRESSION_DOT.test(value) ? 0 : 1) - | ||
(dotRe.test(value) ? 0 : 1) - | ||
(calculateStringLength(value) - position) | ||
@@ -158,3 +157,3 @@ | ||
if (!sizes[index]) { | ||
sizes[index] = MIN_CELL_SIZE | ||
sizes[index] = minCellSize | ||
} | ||
@@ -184,5 +183,5 @@ | ||
if (alignment[index] === RIGHT || alignment[index] === DOT) { | ||
if (alignment[index] === lowercaseR || alignment[index] === dot) { | ||
value = spacing + value | ||
} else if (alignment[index] === CENTER) { | ||
} else if (alignment[index] === lowercaseC) { | ||
position /= 2 | ||
@@ -215,7 +214,7 @@ | ||
while (++index < cellCount) { | ||
/* When `pad` is false, make the rule the same size as the first row. */ | ||
// When `pad` is false, make the rule the same size as the first row. | ||
if (settings.pad === false) { | ||
value = table[0][index] | ||
spacing = calculateStringLength(stringify(value)) | ||
spacing = spacing > MIN_CELL_SIZE ? spacing : MIN_CELL_SIZE | ||
spacing = spacing > minCellSize ? spacing : minCellSize | ||
} else { | ||
@@ -227,6 +226,6 @@ spacing = sizes[index] | ||
/* When `align` is left, don't add colons. */ | ||
value = align === RIGHT || align === NULL ? DASH : COLON | ||
value += pad(spacing - 2, DASH) | ||
value += align !== LEFT && align !== NULL ? COLON : DASH | ||
// When `align` is left, don't add colons. | ||
value = align === lowercaseR || align === '' ? dash : colon | ||
value += pad(spacing - 2, dash) | ||
value += align !== lowercaseL && align !== '' ? colon : dash | ||
@@ -239,3 +238,3 @@ rule[index] = value | ||
return start + rows.join(end + NEW_LINE + start) + end | ||
return start + rows.join(end + lineFeed + start) + end | ||
} | ||
@@ -247,3 +246,3 @@ | ||
/* Get the length of `value`. */ | ||
// Get the length of `value`. | ||
function lengthNoop(value) { | ||
@@ -253,12 +252,12 @@ return String(value).length | ||
/* Get a string consisting of `length` `character`s. */ | ||
// Get a string consisting of `length` `character`s. | ||
function pad(length, character) { | ||
return new Array(length + 1).join(character || SPACE) | ||
return new Array(length + 1).join(character || space) | ||
} | ||
/* Get the position of the last dot in `value`. */ | ||
// Get the position of the last dot in `value`. | ||
function dotindex(value) { | ||
var match = EXPRESSION_LAST_DOT.exec(value) | ||
var match = lastDotRe.exec(value) | ||
return match ? match.index + 1 : value.length | ||
} |
{ | ||
"name": "markdown-table", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Markdown/ASCII tables", | ||
@@ -17,5 +17,5 @@ "license": "MIT", | ||
"bugs": "https://github.com/wooorm/markdown-table/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)" | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" | ||
], | ||
@@ -29,15 +29,15 @@ "files": [ | ||
"chalk": "^2.0.0", | ||
"esmangle": "^1.0.0", | ||
"nyc": "^11.0.0", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.12.1", | ||
"remark-cli": "^5.0.0", | ||
"remark-cli": "^6.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"strip-ansi": "^4.0.0", | ||
"strip-ansi": "^5.0.0", | ||
"tape": "^4.4.0", | ||
"xo": "^0.20.0" | ||
"tinyify": "^2.5.0", | ||
"xo": "^0.24.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"build-bundle": "browserify index.js -s markdownTable > markdown-table.js", | ||
"build-mangle": "esmangle markdown-table.js > markdown-table.min.js", | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && 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", | ||
@@ -66,6 +66,3 @@ "test-api": "node test", | ||
"complexity": "off", | ||
"max-depth": "off", | ||
"object-shorthand": "off", | ||
"prefer-arrow-callback": "off", | ||
"no-var": "off" | ||
"max-depth": "off" | ||
}, | ||
@@ -72,0 +69,0 @@ "ignores": [ |
@@ -1,3 +0,8 @@ | ||
# markdown-table [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
# markdown-table | ||
[![Build][build-badge]][build] | ||
[![Coverage][coverage-badge]][coverage] | ||
[![Downloads][downloads-badge]][downloads] | ||
[![Size][size-badge]][size] | ||
Generate fancy [Markdown][fancy]/ASCII tables. | ||
@@ -151,15 +156,23 @@ | ||
[travis-badge]: https://img.shields.io/travis/wooorm/markdown-table.svg | ||
[build-badge]: https://img.shields.io/travis/wooorm/markdown-table.svg | ||
[travis]: https://travis-ci.org/wooorm/markdown-table | ||
[build]: https://travis-ci.org/wooorm/markdown-table | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/markdown-table.svg | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/markdown-table.svg | ||
[codecov]: https://codecov.io/github/wooorm/markdown-table | ||
[coverage]: https://codecov.io/github/wooorm/markdown-table | ||
[downloads-badge]: https://img.shields.io/npm/dm/markdown-table.svg | ||
[downloads]: https://www.npmjs.com/package/markdown-table | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/markdown-table.svg | ||
[size]: https://bundlephobia.com/result?p=markdown-table | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[license]: LICENSE | ||
[license]: license | ||
[author]: http://wooorm.com | ||
[author]: https://wooorm.com | ||
@@ -166,0 +179,0 @@ [fancy]: https://help.github.com/articles/github-flavored-markdown/#tables |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11970
181
0