Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 22, 2021
1 parent d3eb25e commit a8213b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
43 changes: 21 additions & 22 deletions index.js
Expand Up @@ -19,39 +19,37 @@ import repeat from 'repeat-string'
* @returns {string}
*/
export function markdownTable(table, options) {
var settings = options || {}
var align = (settings.align || []).concat()
var stringLength = settings.stringLength || defaultStringLength
const settings = options || {}
const align = (settings.align || []).concat()
const stringLength = settings.stringLength || defaultStringLength
/** @type {number[]} Character codes as symbols for alignment per column. */
var alignments = []
var rowIndex = -1
const alignments = []
let rowIndex = -1
/** @type {string[][]} Cells per row. */
var cellMatrix = []
const cellMatrix = []
/** @type {number[][]} Sizes of each cell per row. */
var sizeMatrix = []
const sizeMatrix = []
/** @type {number[]} */
var longestCellByColumn = []
var mostCellsPerRow = 0
const longestCellByColumn = []
let mostCellsPerRow = 0
/** @type {number} */
var columnIndex
let columnIndex
/** @type {string[]} Cells of current row */
var row
let row
/** @type {number[]} Sizes of current row */
var sizes
let sizes
/** @type {number} Sizes of current cell */
var size
let size
/** @type {string} Current cell */
var cell
/** @type {string[]} */
var lines
let cell
/** @type {string[]} Chunks of current line. */
var line
let line
/** @type {string} */
var before
let before
/** @type {string} */
var after
let after
/** @type {number} */
var code
let code

// This is a superfluous loop if we don’t align delimiters, but otherwise we’d
// do superfluous work when aligning, so optimize for aligning.
Expand Down Expand Up @@ -149,7 +147,8 @@ export function markdownTable(table, options) {
sizeMatrix.splice(1, 0, sizes)

rowIndex = -1
lines = []
/** @type {string[]} */
const lines = []

while (++rowIndex < cellMatrix.length) {
row = cellMatrix[rowIndex]
Expand Down Expand Up @@ -248,7 +247,7 @@ function defaultStringLength(value) {
* @returns {number}
*/
function toAlignment(value) {
var code = typeof value === 'string' ? value.charCodeAt(0) : 0
const code = typeof value === 'string' ? value.charCodeAt(0) : 0

return code === 67 /* `C` */ || code === 99 /* `c` */
? 99 /* `c` */
Expand Down
14 changes: 6 additions & 8 deletions package.json
Expand Up @@ -55,11 +55,6 @@
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run build && npm run format && npm run test-coverage"
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
Expand All @@ -72,11 +67,14 @@
"prettier": true,
"rules": {
"complexity": "off",
"unicorn/prefer-switch": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
"unicorn/prefer-switch": "off"
}
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
Expand Down
2 changes: 1 addition & 1 deletion test.js
Expand Up @@ -3,7 +3,7 @@ import chalk from 'chalk'
import strip from 'strip-ansi'
import {markdownTable} from './index.js'

test('markdownTable()', function (t) {
test('markdownTable()', (t) => {
t.equal(
markdownTable([
['Branch', 'Commit'],
Expand Down

0 comments on commit a8213b5

Please sign in to comment.