diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 568c251..594a0de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,4 +16,3 @@ jobs: run: | npm ci npm test - npm run build diff --git a/.vscode/settings.json b/.vscode/settings.json index 1f907bf..dd997f7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,8 @@ }, "editor.codeActionsOnSave": { "source.fixAll.eslint": true - } + }, + "javascript.preferences.importModuleSpecifierEnding": "js", + "typescript.preferences.importModuleSpecifierEnding": "js", + "liveServer.settings.port": 5501 } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f6caa0e..11aa72f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,33 @@ # Change Log +# [v3.0.0](https://github.com/schoero/swissqrbill/compare/v2.4.2...v3.0.0) - 03.10.2021 + * New features + * SVG + * Added support for SVG rendering [#343](https://github.com/schoero/SwissQRBill/issues/343). + * Added es6 module exports. + * Support for tree shaking. + * utils + * Added `mm2px()` function. + * Added `px2mm()` function. + * Added `pt2mm()` function. + * Breaking changes + * imports + * SwissQRBill is now available as a CommonJS and an ES module. This may change how the module has to be imported. Please take a look at the [importing the library](https://github.com/schoero/SwissQRBill#importing-the-library) section in the readme. + * data + * the field `houseNumber` has been renamed to `buildingNumber`. + * the deprecated field `debitor` has been removed. Use `debtor` instead. + * utils + * `mmToPoints()` function has been renamed to `mm2pt()`. + * PDF + * Removed deprecated `mmToPoints()` export. Use `utils.mm2pt()` instead. + * Fixes + * PDF + * The positioning of the box when no amount is provided has been slightly corrected. + * The positioning iban on the payment part has been slightly corrected. + * Fixed positioning of the debtor boxes when no debtor is provided and the creditor address break to multiple lines. + + # [v2.4.2](https://github.com/schoero/swissqrbill/compare/v2.4.1...v2.4.2) - 26.08.2021 * Fixed translation of `additionalInformation` and `payableByName`. [#342](https://github.com/schoero/SwissQRBill/pull/342) diff --git a/README.md b/README.md index ab10121..7ca8bb8 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,14 @@ With SwissQRBill you can easily generate the new QR Code payment slips in Node.j [](https://github.com/schoero/SwissQRBill/blob/master/assets/qrbill.pdf) +
+
+ ## Links * [Features](#features) * [Installation](#installation) + * [Importing the library](#importing-the-library) * [Quick start](#quick-start) * [Browser usage](#browser-usage) * [API documentation](https://github.com/schoero/SwissQRBill/blob/master/doc/api.md) @@ -50,15 +54,18 @@ With SwissQRBill you can easily generate the new QR Code payment slips in Node.j * [QR bill specifications](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf) +
+ ## Features - - Generates PDF with scalable vector graphics - - Works in browser and node - - Supports german, english, italian and french invoices - - Supports A4 invoices as well as A6/5 (QR bill only) - - Allows you to add other content above the invoice using [PDFKit](https://github.com/foliojs/pdfkit) - - Easy to use - - Free and open source + - Generate complete invoices, or only the QR Bill, as a PDF file. + - Generate the QR Bill as a scalable vector graphic (SVG). + - Works in browsers and Node.js. + - Supports german, english, italian and french invoices. + - Allows you to add other content above the invoice using [PDFKit](https://github.com/foliojs/pdfkit). + - Easy to use. + - Free and open source. +
## Installation @@ -66,12 +73,70 @@ With SwissQRBill you can easily generate the new QR Code payment slips in Node.j npm i swissqrbill --save ``` +
+ +## Importing the library + +### Node.js + +In versions prior to v3.0.0, you could simply include SwissQRBill like this: + +```js +const SwissQRBill = require("swissqrbill"); // CommonJS. Not tree-shakeable. +``` + +
+ +While you can still do this, it is recommended to switch to the new ES module imports to be able to take advantage of tree-shaking. SwissQRBill uses the new [conditional exports feature](https://nodejs.org/api/packages.html#packages_exports_sugar) that was added in node v12.16.0 or v13.6.0. + +This allows you to import only the parts of SwissQRBill that you actually need. + +```js +import { PDF } from "swissqrbill/pdf"; // ESM. Tree-shakeable +import { SVG } from "swissqrbill/svg"; // ESM. Tree-shakeable +import { mm2pt } from "swissqrbill/utils"; // ESM. Tree-shakeable +``` + +
+ +Unfortunately, TypeScript with a version prior to the upcoming [version 4.5](https://github.com/microsoft/TypeScript/issues/45418), and Node.js prior to v12.16.0 or v13.6.0, do not support this feature. +If you are using a TypeScript or Node.js version, that doesn't support the new export feature, you can still take advantage of tree-shaking, by importing the files directly by their path. + +```js +import { PDF } from "swissqrbill/lib/node/esm/node/pdf.js"; // ESM. Tree-shakeable +import { SVG } from "swissqrbill/lib/node/esm/node/svg.js"; // ESM. Tree-shakeable +import { mm2pt } from "swissqrbill/lib/node/esm/shared/utils.js"; // ESM. Tree-shakeable +``` + +
+ +### Browser + +For the browser it is a bit more complicated. The easiest way would be to include the pre-bundled version. + +```html + + + + + \ No newline at end of file diff --git a/tests/italian.js b/tests/italian.js index 1e28c51..9e0fb66 100644 --- a/tests/italian.js +++ b/tests/italian.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -21,4 +22,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/italian.pdf", { language: "IT" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/italian.pdf", { language: "IT" }); +const svg = new SwissQRBill.SVG(data, { language: "IT" }); +writeFileSync("./output/svg/italian.svg", svg.toString()); \ No newline at end of file diff --git a/tests/message-additional-information.js b/tests/message-additional-information.js index eb61d3e..4e4b336 100644 --- a/tests/message-additional-information.js +++ b/tests/message-additional-information.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -23,4 +24,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/message-additional-information.pdf", { "size": "A6/5" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/message-additional-information.pdf", { "size": "A6/5" }); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/message-additional-information.svg", svg.toString()); \ No newline at end of file diff --git a/tests/message.js b/tests/message.js index b9ffd3d..083f59d 100644 --- a/tests/message.js +++ b/tests/message.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -22,4 +23,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/message.pdf", { "size": "A6/5" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/message.pdf", { "size": "A6/5" }); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/message.svg", svg.toString()); \ No newline at end of file diff --git a/tests/multipage.js b/tests/multipage.js index aa14b81..408d127 100644 --- a/tests/multipage.js +++ b/tests/multipage.js @@ -21,28 +21,28 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/multipage.pdf", { "autoGenerate": false, "size": "A4" }); +const pdf = new SwissQRBill.PDF(data, "./output/pdf/multipage.pdf", { "autoGenerate": false, "size": "A4" }); pdf.fontSize(11); pdf.font("Helvetica-Bold"); -pdf.text("PAGE 1", SwissQRBill.utils.mmToPoints(5), SwissQRBill.utils.mmToPoints(20), { - width: SwissQRBill.utils.mmToPoints(210), - align: "center", +pdf.text("PAGE 1", SwissQRBill.utils.mm2pt(5), SwissQRBill.utils.mm2pt(20), { + width: SwissQRBill.utils.mm2pt(210), + align: "center" }); pdf.addPage(); -pdf.text("PAGE 2", SwissQRBill.utils.mmToPoints(5), SwissQRBill.utils.mmToPoints(20), { - width: SwissQRBill.utils.mmToPoints(210), - align: "center", +pdf.text("PAGE 2", SwissQRBill.utils.mm2pt(5), SwissQRBill.utils.mm2pt(20), { + width: SwissQRBill.utils.mm2pt(210), + align: "center" }); pdf.addPage(); -pdf.text("PAGE 3", SwissQRBill.utils.mmToPoints(5), SwissQRBill.utils.mmToPoints(20), { - width: SwissQRBill.utils.mmToPoints(210), - align: "center", +pdf.text("PAGE 3", SwissQRBill.utils.mm2pt(5), SwissQRBill.utils.mm2pt(20), { + width: SwissQRBill.utils.mm2pt(210), + align: "center" }); pdf.addQRBill(); diff --git a/tests/no-amount.js b/tests/no-amount.js index b243ece..abe9791 100644 --- a/tests/no-amount.js +++ b/tests/no-amount.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -20,4 +21,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-amount.pdf"); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-amount.pdf"); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/no-amount.svg", svg.toString()); \ No newline at end of file diff --git a/tests/no-debtor-no-amount-no-reference.js b/tests/no-debtor-no-amount-no-reference.js index 12ab444..6116d90 100644 --- a/tests/no-debtor-no-amount-no-reference.js +++ b/tests/no-debtor-no-amount-no-reference.js @@ -1,15 +1,20 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", + av1: "eBillUV;UltraPay005;12345", + av2: "eBillXY;XYService;54321", creditor: { - name: "Robert Schneider AG", - address: "Rue du Lac 1268", + name: "Robert Schneider ultra long name of the company to use multiple lines", + address: "Rue du Lac 1268 Ultra long address nam eto use multiple lines", zip: 2501, - city: "Biel", + city: "Zug ultra long city name multi line", account: "CH5800791123000889012", country: "CH" } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-debtor-no-amount-no-reference.pdf"); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-debtor-no-amount-no-reference.pdf"); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/no-debtor-no-amount-no-reference.svg", svg.toString()); \ No newline at end of file diff --git a/tests/no-debtor-no-amount.js b/tests/no-debtor-no-amount.js index a3e5bfa..2aeca7f 100644 --- a/tests/no-debtor-no-amount.js +++ b/tests/no-debtor-no-amount.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -13,4 +14,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-debtor-no-amount.pdf"); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-debtor-no-amount.pdf"); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/no-debtor-no-amount.svg", svg.toString()); \ No newline at end of file diff --git a/tests/no-debtor-no-reference.js b/tests/no-debtor-no-reference.js index 74363d4..d6710c6 100644 --- a/tests/no-debtor-no-reference.js +++ b/tests/no-debtor-no-reference.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -13,4 +14,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-debtor-no-reference.pdf"); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-debtor-no-reference.pdf"); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/no-debtor-no-reference.svg", svg.toString()); \ No newline at end of file diff --git a/tests/no-debtor.js b/tests/no-debtor.js index 5013cf5..ec9e7dd 100644 --- a/tests/no-debtor.js +++ b/tests/no-debtor.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -14,4 +15,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-debtor.pdf"); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-debtor.pdf"); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/no-debtor.svg", svg.toString()); \ No newline at end of file diff --git a/tests/no-reference-message.js b/tests/no-reference-message.js index 431b355..7358be9 100644 --- a/tests/no-reference-message.js +++ b/tests/no-reference-message.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -21,4 +22,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-reference-message.pdf", { "size": "A6/5" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-reference-message.pdf", { "size": "A6/5" }); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/no-reference-message.svg", svg.toString()); \ No newline at end of file diff --git a/tests/no-scissors-no-outlines.js b/tests/no-scissors-no-outlines.js index d5026be..f47e9ff 100644 --- a/tests/no-scissors-no-outlines.js +++ b/tests/no-scissors-no-outlines.js @@ -21,4 +21,4 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-scissors-no-outline.pdf", { "scissors" : false, "outlines": false, "size": "A4" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-scissors-no-outline.pdf", { "scissors" : false, "outlines": false, "size": "A4" }); \ No newline at end of file diff --git a/tests/no-scissors-no-separate-no-outlines.js b/tests/no-scissors-no-separate-no-outlines.js index 0f310ab..3c753e9 100644 --- a/tests/no-scissors-no-separate-no-outlines.js +++ b/tests/no-scissors-no-separate-no-outlines.js @@ -21,4 +21,4 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-scissors-no-separate-no-outline.pdf", { "scissors" : false, "separate": false, "outlines": false, "size": "A4" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-scissors-no-separate-no-outline.pdf", { "scissors" : false, "separate": false, "outlines": false, "size": "A4" }); \ No newline at end of file diff --git a/tests/no-scissors-no-separate.js b/tests/no-scissors-no-separate.js index 9ab998f..6ffb9a7 100644 --- a/tests/no-scissors-no-separate.js +++ b/tests/no-scissors-no-separate.js @@ -21,4 +21,4 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-scissors-no-separate.pdf", { "scissors" : false, "separate": false, "size": "A4" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-scissors-no-separate.pdf", { "scissors" : false, "separate": false, "size": "A4" }); \ No newline at end of file diff --git a/tests/no-scissors.js b/tests/no-scissors.js index 4707bed..330c91f 100644 --- a/tests/no-scissors.js +++ b/tests/no-scissors.js @@ -21,4 +21,4 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-scissors.pdf", { "scissors" : false, "size": "A4" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-scissors.pdf", { "scissors" : false, "size": "A4" }); \ No newline at end of file diff --git a/tests/no-separate-no-outlines.js b/tests/no-separate-no-outlines.js index 61e56b5..6f6eea3 100644 --- a/tests/no-separate-no-outlines.js +++ b/tests/no-separate-no-outlines.js @@ -21,4 +21,4 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/no-separate-no-outline.pdf", { "separate" : false, "outlines": false, "size": "A4" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/no-separate-no-outline.pdf", { "separate" : false, "outlines": false, "size": "A4" }); \ No newline at end of file diff --git a/tests/normal-iban-creditor-reference.js b/tests/normal-iban-creditor-reference.js index 00c364f..f10ed07 100644 --- a/tests/normal-iban-creditor-reference.js +++ b/tests/normal-iban-creditor-reference.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -20,4 +21,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/normal-iban.pdf"); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/normal-iban.pdf"); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/normal-iban.svg", svg.toString()); \ No newline at end of file diff --git a/tests/normal-iban-no-reference.js b/tests/normal-iban-no-reference.js index 4b7e442..d36aae9 100644 --- a/tests/normal-iban-no-reference.js +++ b/tests/normal-iban-no-reference.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -21,4 +22,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/normal-iban.pdf"); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/normal-iban-no-reference.pdf"); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/normal-iban-no-reference.svg", svg.toString()); \ No newline at end of file diff --git a/tests/not-enough-space-a4.js b/tests/not-enough-space-a4.js index 5035171..5ddd4bc 100644 --- a/tests/not-enough-space-a4.js +++ b/tests/not-enough-space-a4.js @@ -21,13 +21,13 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/not-enough-space-a4.pdf", { "autoGenerate": false, "size": "A4" }); +const pdf = new SwissQRBill.PDF(data, "./output/pdf/not-enough-space-a4.pdf", { "autoGenerate": false, "size": "A4" }); pdf.fontSize(11); pdf.font("Helvetica-Bold"); -pdf.text("PAGE 1", SwissQRBill.utils.mmToPoints(5), pdf.page.height - 50, { - width: SwissQRBill.utils.mmToPoints(210), +pdf.text("PAGE 1", SwissQRBill.utils.mm2pt(5), pdf.page.height - 50, { + width: SwissQRBill.utils.mm2pt(210), align: "center" }); diff --git a/tests/not-enough-space.js b/tests/not-enough-space.js index 969378f..a5dd66a 100644 --- a/tests/not-enough-space.js +++ b/tests/not-enough-space.js @@ -21,13 +21,13 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/not-enough-space.pdf", { "autoGenerate": false, "size": "A4" }); +const pdf = new SwissQRBill.PDF(data, "./output/pdf/not-enough-space.pdf", { "autoGenerate": false, "size": "A4" }); pdf.fontSize(11); pdf.font("Helvetica-Bold"); -pdf.text("PAGE 1", SwissQRBill.utils.mmToPoints(5), pdf.page.height - 50, { - width: SwissQRBill.utils.mmToPoints(210), +pdf.text("PAGE 1", SwissQRBill.utils.mm2pt(5), pdf.page.height - 50, { + width: SwissQRBill.utils.mm2pt(210), align: "center" }); diff --git a/tests/qr-iban.js b/tests/qr-iban.js index ab67d06..84ea7b7 100644 --- a/tests/qr-iban.js +++ b/tests/qr-iban.js @@ -1,4 +1,5 @@ const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -21,4 +22,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/qr-iban.pdf"); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/qr-iban.pdf"); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/qr-iban.svg", svg.toString()); \ No newline at end of file diff --git a/tests/run-windows.bat b/tests/run-windows.bat deleted file mode 100644 index 6f181e6..0000000 --- a/tests/run-windows.bat +++ /dev/null @@ -1,73 +0,0 @@ -if not exist output mkdir output -echo "utils" - call node utils -echo "a4" - call node a4 -echo "a6-5" - call node a6-5 -echo "a6-5-housenmuber" - call node a6-5-housenumber -echo "av1av2" - call node av1av2 -echo "english" - call node english -echo "euro" - call node euro -echo "french" - call node french -echo "italian" - call node italian -echo "message" - call message -echo "no-reference-message" - call no-reference-message -echo "message-additional-information" - call message-additional-information -echo "additional-information" - call additional-information -echo "multipage" - call node multipage -echo "no-amount" - call node no-amount -echo "no-debtor" - call node no-debtor -echo "no-debtor-no-amount" - call node no-debtor-no-amount -echo "no-debtor-no-amount-no-reference" - call node no-debtor-no-amount-no-reference -echo "no-debtor-no-reference" - call node no-debtor-no-reference -echo "normal-iban-creditor-reference" - call node normal-iban-creditor-reference -echo "normal-iban-no-reference" - call node normal-iban-no-reference -echo "not-enough-space" - call node not-enough-space -echo "not-enough-space-a4" - call node not-enough-space-a4 -echo "no-scissors" - call node no-scissors -echo "no-scissors-no-outlines" - call node no-scissors-no-outlines -echo "no-scissors-no-separate" - call node no-scissors-no-separate -echo "no-separate-no-outlines" - call node no-separate-no-outlines -echo "no-scissors-no-separate-no-outlines" - call node no-scissors-no-separate-no-outlines -echo "qr-iban" - call node qr-iban -echo "separate" - call node separate -echo "separate-scissors" - call node separate-scissors -echo "callback" - call node callback -echo "callback-with-options" - call node callback-with-options -echo "event" - call node event -echo "stream" - call node stream -echo "zip-string" -call node zip-string \ No newline at end of file diff --git a/tests/run.sh b/tests/run.sh index 4d3336b..81194ad 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,5 +1,7 @@ #!/bin/sh mkdir -p output +mkdir -p output/pdf +mkdir -p output/svg set -e @@ -8,9 +10,9 @@ echo "utils" echo "a4" node a4 echo "a6-5" - node a6-5 + node a6-5.mjs echo "a6-5-housenmuber" - node a6-5-housenumber + node a6-5-buildingnumber echo "av1av2" node av1av2 echo "english" diff --git a/tests/separate-scissors.js b/tests/separate-scissors.js index 3eb7937..4273e16 100644 --- a/tests/separate-scissors.js +++ b/tests/separate-scissors.js @@ -21,4 +21,4 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/separate-scissors.pdf", { "separate" : true, "scissors": true, "size": "A4" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/separate-scissors.pdf", { "separate" : true, "scissors": true, "size": "A4" }); \ No newline at end of file diff --git a/tests/separate.js b/tests/separate.js index 97455fa..e702b82 100644 --- a/tests/separate.js +++ b/tests/separate.js @@ -21,4 +21,4 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/separate.pdf", { "separate" : true, "size": "A4" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/separate.pdf", { "separate" : true, "size": "A4" }); \ No newline at end of file diff --git a/tests/stream.js b/tests/stream.js index 96d347b..b6250c7 100644 --- a/tests/stream.js +++ b/tests/stream.js @@ -22,5 +22,5 @@ const data = { } }; -const stream = fs.createWriteStream("./output/stream.pdf"); +const stream = fs.createWriteStream("./output/pdf/stream.pdf"); const pdf = new SwissQRBill.PDF(data, stream, { "size": "A6/5" }); \ No newline at end of file diff --git a/tests/zip-string.js b/tests/zip-string.js index fc6ac4c..07628c6 100644 --- a/tests/zip-string.js +++ b/tests/zip-string.js @@ -1,4 +1,5 @@ -const SwissQRBill = require("../lib/node"); +const SwissQRBill = require("../"); +const { writeFileSync } = require("fs"); const data = { currency: "CHF", @@ -20,4 +21,6 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/zip-string.pdf"); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/pdf/zip-string.pdf"); +const svg = new SwissQRBill.SVG(data); +writeFileSync("./output/svg/zip-string.svg", svg.toString()); \ No newline at end of file diff --git a/tsconfig.browser.esm.json b/tsconfig.browser.esm.json new file mode 100644 index 0000000..015cabc --- /dev/null +++ b/tsconfig.browser.esm.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "./lib/browser/esm", + "module": "esnext", + "target": "esnext" + }, + "include": ["src/browser/index.ts"], + "exclude": [ + "lib/", + "src/browser/bundle.ts", + "src/node/" + ] +} \ No newline at end of file diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..3b7cbc3 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "./lib/node/cjs", + "module": "CommonJS", + "target": "ES6" + }, + "include": ["src"], + "exclude": [ + "lib/", + "src/browser/" + ] +} \ No newline at end of file diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..8d05a98 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "./lib/node/esm", + "module": "esnext", + "target": "esnext" + }, + "include": ["src"], + "exclude": [ + "lib/", + "src/browser/" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index eee8c03..d60ce1a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,21 @@ { "compilerOptions": { "target": "ES6", - "lib": ["ES6", "DOM"], - "module": "commonjs", + "lib": ["ES2020", "DOM"], + "module": "ESNext", + "moduleResolution": "Node", "sourceMap": true, - "declaration": true, - "outDir": "./lib", + "declaration": false, "strict": true, "noImplicitAny": false, - "esModuleInterop": true + "esModuleInterop": true, }, - "include": ["src"], - "exclude": ["node_modules", "./src/browser.ts"] + "include": [ + "src" + ], + "exclude": [ + "node_modules", + "src/browser", + "lib" + ] } \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 6a4ec86..07180a2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,33 +1,72 @@ const webpack = require("webpack"); module.exports = { - entry: "./src/browser.ts", + entry: "./src/browser/bundle.ts", + target: "web", module: { rules: [ { - test: /\.tsx?$/, + test: /\.(js|ts)?$/, use: "ts-loader", - exclude: /node_modules/, + exclude: /node_modules/ }, - ], + // bundle and load afm files verbatim + { + test: /\.afm$/, + type: "asset/source" + }, + // convert to base64 and include inline file system binary files used by fontkit and linebreak + { + enforce: "post", + test: /fontkit[/\\]index.js$/, + loader: "transform-loader", + options: { + brfs: {} + } + }, + { + enforce: "post", + test: /linebreak[/\\]src[/\\]linebreaker.js/, + loader: "transform-loader", + options: { + brfs: {} + } + } + ] }, devtool: "inline-source-map", resolve: { - extensions: [ ".tsx", ".ts", ".js" ], + extensions: [".tsx", ".ts", ".js"], + alias: { + // maps fs to a virtual one allowing to register file content dynamically + fs: "pdfkit/js/virtual-fs.js", + // iconv-lite is used to load cid less fonts (not spec compliant) + "iconv-lite": false + }, fallback: { - "stream": require.resolve("stream-browserify"), - "util": require.resolve("util"), - "buffer": require.resolve("buffer") + crypto: false, + stream: require.resolve("readable-stream"), + util: require.resolve("util"), + buffer: require.resolve("buffer"), + zlib: require.resolve("browserify-zlib"), + assert: require.resolve("assert/") } }, plugins: [ new webpack.ProvidePlugin({ process: "process/browser", + Buffer: ["buffer", "Buffer"] }), + new webpack.NormalModuleReplacementPlugin(new RegExp(/\.js$/), function(resource) { + if(resource.context.includes("node_modules") !== true){ + resource.request = resource.request.replace(".js", ""); + } + }) ], output: { - filename: "browser.js", - path: __dirname + "/lib", - libraryTarget: "umd" - }, + filename: "index.js", + path: __dirname + "/lib/browser/bundle/", + libraryTarget: "umd", + library: "SwissQRBill" + } }; \ No newline at end of file