From 4c2040028d6f5480f6ba3c70e7a35f8d5c0eab63 Mon Sep 17 00:00:00 2001 From: Krasilnikov Roman Date: Fri, 6 Dec 2024 02:43:14 +0300 Subject: [PATCH] [docs] Add page for `block-to-xlsx` --- apps/docs/astro.config.mjs | 21 ++++++--- apps/docs/src/content/docs/block-to-xlsx.mdx | 49 ++++++++++++++++++++ apps/docs/src/content/docs/index.mdx | 2 +- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 apps/docs/src/content/docs/block-to-xlsx.mdx diff --git a/apps/docs/astro.config.mjs b/apps/docs/astro.config.mjs index b814c33..a5135a3 100644 --- a/apps/docs/astro.config.mjs +++ b/apps/docs/astro.config.mjs @@ -1,5 +1,5 @@ // @ts-check -import { fileURLToPath } from 'node:url' +import { fileURLToPath } from "node:url"; import { defineConfig } from "astro/config"; import starlight from "@astrojs/starlight"; import svelte from "@astrojs/svelte"; @@ -27,14 +27,23 @@ export default defineConfig({ "data-goatcounter": "https://json-table.counter.x0k.online/count", async: true, src: "https://json-table.counter.x0k.online/count.js", - } + }, }, ], sidebar: [ - // { - // label: "Guides", - // autogenerate: { directory: "guides" }, - // }, + { + label: "Packages", + items: [ + { + label: "@json-table/core", + link: "/", + }, + { + label: "@json-table/block-to-xlsx", + link: "/block-to-xlsx/", + }, + ], + }, ], components: { Head: "./src/components/custom-head.astro", diff --git a/apps/docs/src/content/docs/block-to-xlsx.mdx b/apps/docs/src/content/docs/block-to-xlsx.mdx new file mode 100644 index 0000000..76b428b --- /dev/null +++ b/apps/docs/src/content/docs/block-to-xlsx.mdx @@ -0,0 +1,49 @@ +--- +title: Block to XLSX +--- + +import { Code, Card, CardGrid, LinkCard } from '@astrojs/starlight/components'; + +import Npm from '@/components/npm.astro'; + +Library for converting blocks to XLSX. + +## Installation + + + +## Usage + +```typescript +import { Workbook } from "exceljs"; +import { max, sum } from "@json-table/core/lib/math"; +import { makeBlockFactory } from "@json-table/core/json-to-table"; +import { renderBlockOnWorksheet } from "@json-table/block-to-xlsx"; + +const block = makeBlockFactory({ + cornerCellValue: "№", + joinPrimitiveArrayValues: true, +}); + +const wb = new Workbook(); + +/* Render table on the `Table` sheet */ +renderBlockOnWorksheet(wb.addWorksheet("Table"), block(data), { + columnWidth: (column, i, m, table) => { + const counts = column.map((cell) => cell.count); + return Math.max( + Math.ceil( + (counts.reduce(sum) / table.height + + (counts.reduce(max) * column.length) / table.height) / + 2 + ), + 10 + ); + }, +}); + +``` + +## License + +MIT diff --git a/apps/docs/src/content/docs/index.mdx b/apps/docs/src/content/docs/index.mdx index fa9dc6c..4b85962 100644 --- a/apps/docs/src/content/docs/index.mdx +++ b/apps/docs/src/content/docs/index.mdx @@ -1,7 +1,7 @@ --- title: JSON Table # description: Main page -template: splash +# template: splash hero: tagline: Set of tools for converting JSON data into tables (HTML, XLSX, ASCII). actions: