{"_id":"@bayaweaver/report-weaver-core","name":"@bayaweaver/report-weaver-core","dist-tags":{"latest":"1.0.38"},"versions":{"1.0.38":{"name":"@bayaweaver/report-weaver-core","version":"1.0.38","type":"commonjs","main":"src/index.js","publishConfig":{"access":"public"},"scripts":{"test":"node --test"},"dependencies":{"@sparticuz/chromium":"133.0.0","dayjs":"1.11.13","jsdom":"26.0.0","nunjucks":"3.2.4","puppeteer-core":"24.3.1","xlsx-js-style":"1.2.0"},"devDependencies":{"pdf-lib":"1.17.1"},"_id":"@bayaweaver/report-weaver-core@1.0.38","gitHead":"fc004d735a684e536443f869ada1e2fe9731bf0a","description":"The library is aimed to generate either PDF or XLSX documents based on HTML-template and JSON-data. The HTML-template processing is powered by Nunjunks engine.","_nodeVersion":"23.6.0","_npmVersion":"11.0.0","dist":{"integrity":"sha512-cVvvS3sLFgkgJH0RcIsT1xDs7zcIGag8ES6uT9n0ZO0yQSIGtUM8YNCxfUJzzJhAZUnf4CSZBjKVzpd8qjQBag==","shasum":"8cc74a2fda5a91c7118a9f91a0b2fbb7951af7c3","tarball":"https://registry.npmjs.org/@bayaweaver/report-weaver-core/-/report-weaver-core-1.0.38.tgz","fileCount":9,"unpackedSize":1000539,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCmxk0YwFibSa51R70jxTgmO7TsKfFrJgn+P41l1UzJDQIgJFze68KS5nRF1JHYVasKt1xj86BCoHLw7T3xXtGSOrQ="}]},"_npmUser":{"name":"bayaweaver","email":"serhii.yatskovskyi@gmail.com"},"directories":{},"maintainers":[{"name":"bayaweaver","email":"serhii.yatskovskyi@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/report-weaver-core_1.0.38_1770352628925_0.6244742200866531"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-06T04:37:08.789Z","1.0.38":"2026-02-06T04:37:09.085Z","modified":"2026-02-06T04:37:09.279Z"},"maintainers":[{"name":"bayaweaver","email":"serhii.yatskovskyi@gmail.com"}],"description":"The library is aimed to generate either PDF or XLSX documents based on HTML-template and JSON-data. The HTML-template processing is powered by Nunjunks engine.","readme":"# Overview\n\nThe library is aimed to generate either PDF or XLSX documents based on HTML-template and JSON-data. The HTML-template\nprocessing is powered by Nunjunks engine.\n\n## Key features and advantages\n\n- Allows to use the same template file to generate both PDF and XLSX documents. In case of XLSX, all tags but `<table>`\n  tag are ignored.\n- Supports Excel formulas.\n- Formats Excel Sheets based on data types, i.e. numbers will be numbers, not a plain text.\n\n## Expected Behavior\n\n- Every `<table>` will be converted into a separate Excel Sheet.\n- A name of a sheet can be set by specifying a `title` attribute of a `<table>` tag.\n  ```html\n  <table title=\"Details\">...</table>\n  <table title=\"Summary\">...</table>\n  ```\n- To manually control a data format in Excel, use classes `date`, `string`:\n  ```html\n  <td class=\"date\">2012-01-01</td>\n  <td class=\"string\">1</td>\n  ```\n- When XLSX generation, every value which starts from `=` will be converted to a formula. To avoid conversion, use\n  `string` class.\n- When PDF generation, a page style can be set by providing the `@page` CSS attribute in the HTML-template (See more\n  about `@page` on [MDN's pages](https://developer.mozilla.org/en-US/docs/Web/CSS/@page)):\n  ```css\n  @page {\n    size: A4 landscape;\n    margin: 10mm;\n  }\n  ```\n- External fonts and CSS-files are supported:\n  ```html\n  <link href=\"https://fonts.googleapis.com/css2?family=Fira+Mono&display=swap\" rel=\"stylesheet\">\n  ```\n- Supports [`paged.js`](https://github.com/pagedjs/pagedjs) library.\n\n## Tips\n\n- How to display a page number:\n  ```css\n  @page {\n    @bottom-center {\n      content: \"Page \" counter(page) \" of \" counter(pages);\n    }\n  }\n  ```\n- In case, complex header and footer are required, use `paged.js` library.\n- How to display generation time:\n  ```html\n  <h1>{{ (now() | date('YYYY-MM-DD HH:mm:ss')) }}</h1>\n  ```\n\n# Build\n\n## Prepare Windows\n\n1. Open `PowerShell` and execute `wsl -d Ubuntu` or `wsl --install`.\n2. Run the following commands:\n   ```shell\n   sudo apt update\n   sudo apt install -y nodejs npm\n   sudo apt install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libxkbcommon-x11-0 libgbm1 \\\n     build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev\n   ```\n3. Navigate to the `bnc-report` directory (project root) and execute:\n   ```\n   npm install\n   ```\n\n## Running Tests\n\n> **Note:**\n> For Windows OS, all runs must be performed in the `wsl` terminal, not in the `PowerShell`.\n\nTo run a certain test set, execute\n\n```shell\nnode tests/html-to-pdf-converter.test.js\n```\n\nTo enable debugging, add the flag `--inspect-brk`:\n\n```shell\nnode --inspect-brk tests/html-to-pdf-converter.test.js\n```\n\nTo manually build a report, use `.report.js`\n\n```shell\nnode tests/.report.js PDF <njk-file-path> <json-file-path>\n```\n\n# Paged.JS Specifics\n\n- Does not support `{size: landscape}`. Requires an explicit format: `{size: A4 landscape}`\n- Does not support `{size: 100px}`. Requires both dimensions: `{size: 100px 100px}`\n- It is recommended to add `body { margin: 0 }` to avoid extra `8px` of margin\n- A default margin is `96px 96px`\n\n# HtmlToXlsxConverter\n\nConverts HTML tables (and optional text elements) into `.xlsx` Excel files. Uses Puppeteer to render HTML and extract computed styles, then generates Excel output via `xlsx-js-style`.\n\n## Usage\n\n```js\nconst HtmlToXlsxConverter = require(\"./html-to-xlsx-converter\");\n\nconst converter = new HtmlToXlsxConverter();\nconst buffer = await converter.convert(html);\nfs.writeFileSync(\"report.xlsx\", buffer);\n```\n\n`convert(html)` accepts an HTML string and returns a `Buffer` with the `.xlsx` file content.\n\n## Tables\n\nEach `<table>` becomes a separate Excel sheet. The sheet name is taken from the `title` attribute, falling back to `Sheet1`, `Sheet2`, etc.\n\n```html\n<table title=\"Sales Report\">\n  <thead>\n    <tr><th>Product</th><th>Revenue</th></tr>\n  </thead>\n  <tbody>\n    <tr><td>Widget</td><td>1000</td></tr>\n  </tbody>\n</table>\n\n<table title=\"Inventory\">\n  <tr><td>Item</td><td>Count</td></tr>\n</table>\n```\n\n### Supported cell features\n\n- **Numbers** - pure numeric text is stored as Excel numbers\n- **Dates** - cells with class `date` or text matching `YYYY-MM-DD` / `DD.MM.YYYY` are stored as Excel dates\n- **Currency** - text starting with `$`, ``, ``, `` is parsed as numeric with currency format\n- **Formulas** - text starting with `=` is stored as an Excel formula\n- **Merges** - `rowspan` and `colspan` attributes are preserved\n\n### Supported styles\n\nStyles are extracted via `getComputedStyle()`, so CSS classes, inline styles, and inherited styles all work.\n\n| CSS Property | Excel Effect |\n|---|---|\n| `font-weight: bold` | Bold text |\n| `font-style: italic` | Italic text |\n| `font-size` | Font size (converted px to pt) |\n| `color` | Text color |\n| `background-color` | Cell fill color |\n| `text-align` | Horizontal alignment |\n| `vertical-align` | Vertical alignment |\n| `border`, `border-*` | Cell borders (thin/medium/thick) |\n\nColors can be specified as named colors, hex (`#FF0000`), `rgb()`, or `rgba()`.\n\n## Text elements (`data-xlsx-text`)\n\nNon-table content (report headers, footers, titles) can be included in Excel output using the `data-xlsx-text` attribute.\n\n```html\n<div data-xlsx-text data-xlsx-sheet=\"Report\"\n     style=\"font-size: 18px; font-weight: bold;\">\n  Quarterly Sales Report\n</div>\n\n<table title=\"Report\">\n  <tr><td>Q1</td><td>Q2</td><td>Q3</td></tr>\n  <tr><td>100</td><td>200</td><td>300</td></tr>\n</table>\n\n<div data-xlsx-text data-xlsx-sheet=\"Report\"\n     style=\"font-style: italic;\">\n  Generated: 2024-01-15\n</div>\n```\n\nThis produces:\n\n| | A | B | C |\n|---|---|---|---|\n| 1 | Quarterly Sales Report (bold, 18px, merged across A-C) |||\n| 2 | Q1 | Q2 | Q3 |\n| 3 | 100 | 200 | 300 |\n| 4 | Generated: 2024-01-15 (italic, merged across A-C) |||\n\n### Attributes\n\n| Attribute | Required | Description |\n|---|---|---|\n| `data-xlsx-text` | Yes | Marks the element for Excel export |\n| `data-xlsx-sheet` | No | Associates with a sheet (matches `<table title=\"...\">`) |\n\n### Placement rules\n\n- **DOM order** determines whether text appears before or after the table\n- Elements **before** their matching table in the DOM become rows above the table data\n- Elements **after** their matching table become rows below the table data\n- Multiple text elements maintain their DOM order\n- Text rows are **merged across all table columns**\n\n### Standalone text\n\nText elements with no matching table (or without `data-xlsx-sheet`) create their own sheet:\n\n```html\n<div data-xlsx-text data-xlsx-sheet=\"Notes\"\n     style=\"font-weight: bold;\">Important Note</div>\n<div data-xlsx-text data-xlsx-sheet=\"Notes\">Details here</div>\n```\n\nThis creates a \"Notes\" sheet with two rows. Elements without `data-xlsx-sheet` are grouped into a default \"Sheet1\".\n\n### Styling\n\nText elements support the same CSS styling as table cells. Styles are extracted via `getComputedStyle()`, so class-based styling works:\n\n```html\n<style>\n  .report-title { font-size: 20px; font-weight: bold; color: navy; }\n</style>\n<div class=\"report-title\" data-xlsx-text data-xlsx-sheet=\"Report\">\n  Styled Title\n</div>\n```\n\n### Borders\n\nText row borders automatically match the border color of the associated table's cells.\n","readmeFilename":"README.md","_rev":"1-8e89fae7161ea541728dfa98c4f8d63c"}