Comparing version 1.10.0 to 1.11.0
@@ -142,17 +142,54 @@ "use strict"; | ||
// add spaces around column name if necessary (side(s) depends on alignment) | ||
var column_names = input.headers.map(function (header, index) { | ||
if (input.pretty === true) { | ||
// update preferred_lengths considering rows' cells length | ||
input.rows.forEach(function (row) { | ||
(Array.isArray(row) ? row : input.headers.map(function (col_id) { | ||
return row[col_id]; | ||
})).forEach(function (cell, index) { | ||
preferred_lengths[index] = Math.max(preferred_lengths[index], cell.length - 2); | ||
}); | ||
}); | ||
} | ||
var fill_right = function fill_right(diff, header) { | ||
return " ".repeat(diff) + header; | ||
}; | ||
var fill_left = function fill_left(diff, header) { | ||
return header + " ".repeat(diff); | ||
}; | ||
var fill_center = function fill_center(diff, header) { | ||
return " ".repeat(Math.floor(diff / 2)) + header + " ".repeat(Math.ceil(diff / 2)); | ||
}; | ||
var fill_th = function fill_th(header, index) { | ||
var diff = preferred_lengths[index] + 2 - header.length; | ||
switch (alignment[index]) { | ||
case ALIGNMENT.RIGHT: | ||
return " ".repeat(diff) + header; | ||
return fill_right(diff, header); | ||
case ALIGNMENT.LEFT: | ||
return header + " ".repeat(diff); | ||
return fill_left(diff, header); | ||
case ALIGNMENT.CENTER: | ||
case ALIGNMENT.NONE: | ||
default: | ||
return " ".repeat(Math.floor(diff / 2)) + header + " ".repeat(Math.ceil(diff / 2)); | ||
return fill_center(diff, header); | ||
} | ||
}); | ||
}; | ||
var fill_td = function fill_td(header, index) { | ||
var diff = preferred_lengths[index] + 2 - header.length; | ||
switch (alignment[index]) { | ||
case ALIGNMENT.RIGHT: | ||
return fill_right(diff, header); | ||
case ALIGNMENT.NONE: | ||
case ALIGNMENT.LEFT: | ||
return fill_left(diff, header); | ||
case ALIGNMENT.CENTER: | ||
default: | ||
return fill_center(diff, header); | ||
} | ||
}; | ||
// add spaces around column name if necessary (side(s) depends on alignment) | ||
var column_names = input.headers.map(fill_th); | ||
var header = "| " + column_names.join(" | ") + " |"; | ||
@@ -175,4 +212,9 @@ | ||
var data = "| " + input.rows.map(function (row) { | ||
return (Array.isArray(row) ? row : input.headers.map(function (col_id) { | ||
var fill_tbody_cell = function fill_tbody_cell(cell, index) { | ||
if (input.pretty !== true) return cell; | ||
return fill_td(cell, index); | ||
}; | ||
var data = input.rows.map(function (row) { | ||
return "| " + (Array.isArray(row) ? row : input.headers.map(function (col_id) { | ||
return row[col_id]; | ||
@@ -185,4 +227,4 @@ })).map(function (cell) { | ||
return cell.replace(/([^\\])\|/, "$1\\|"); | ||
}).join(" | "); | ||
}).join("\n") + " |"; | ||
}).map(fill_tbody_cell).join(" | ") + " |"; | ||
}).join("\n"); | ||
@@ -189,0 +231,0 @@ return [header, spaces, data].join("\n"); |
{ | ||
"name": "json2md", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"description": "A JSON to Markdown converter.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -291,9 +291,9 @@ <!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. --> | ||
- `@microfleet/schema2md` | ||
- `@best/github-integration` | ||
- `@cypress/schema-tools` | ||
- `@best/github-integration` | ||
- `lambda-docs-2md` | ||
- `jumia-travel-changelog` | ||
- `@cobalt-engine/change-logger` | ||
- `uxcore-tools` | ||
- `@best/store` | ||
- `gatsby-source-gdocs2md` | ||
- `p2doc` | ||
@@ -324,3 +324,2 @@ - `pantheon_site_management` | ||
- `lggn` | ||
- `gatsby-source-google-docs-sheets` | ||
- `machine-ip` | ||
@@ -332,11 +331,20 @@ - `parse-google-docs-json` | ||
- `@bwagener/gridsome-source-google-docs` | ||
- `asm-auto-deploy` | ||
- `type-graphql-to-md` | ||
- `@gracexwho/model-card-generator` | ||
- `gatsby-source-google-docs` | ||
- `@e2y/bdd-dictionary-generator` | ||
- `@s-ui/changelog` | ||
- `dargstack_rgen` | ||
- `@feizheng/react-markdown-props` | ||
- `@jswork/react-markdown-props`I am using this library to generate documentation for my projects, being integrated with [blah](https://github.com/IonicaBizau/node-blah). | ||
- `gatsby-source-google-docs-sheets` | ||
- `@klarna/postgres-to-docs` | ||
- `@dididc/dc-extension` | ||
- `@e2y/bdd-dictionary-generator` | ||
- `github-repo-tools` | ||
- `uxcore-tools` | ||
- `@hitorisensei/monorepo-readme-generator` | ||
- `type-graphql-to-md` | ||
- `collman` | ||
- `gatsby-source-google-docs` | ||
- `@apica-io/asm-auto-deploy` | ||
- `heat-sfdx-tooling` | ||
- `@jswork/react-markdown-props` | ||
- `@discordoo/taapok` | ||
- `dargstack_rgen`I am using this library to generate documentation for my projects, being integrated with [blah](https://github.com/IonicaBizau/node-blah). | ||
@@ -343,0 +351,0 @@ |
36645
392
378