Socket
Socket
Sign inDemoInstall

swissqrbill

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swissqrbill - npm Package Compare versions

Comparing version 4.0.0-alpha.15 to 4.0.0-beta.1

4

package.json
{
"version": "4.0.0-alpha.15",
"version": "4.0.0-beta.1",
"type": "module",

@@ -117,3 +117,3 @@ "name": "swissqrbill",

"typescript": "^5.2.2",
"unwritten": "^0.1.1",
"unwritten": "^0.1.2",
"vite-plugin-dts": "^3.6.2",

@@ -120,0 +120,0 @@ "vite-plugin-no-bundle": "^3.0.0",

@@ -27,3 +27,3 @@ <div align="center">

[<img src="https://raw.githubusercontent.com/schoero/SwissQRBill/master/assets/qrbill.svg">](https://github.com/schoero/SwissQRBill/blob/master/assets/qrbill.pdf)
![QR bill](assets/qr-bill.svg)

@@ -35,2 +35,3 @@ <br/>

* [Migration from v3 to v4](#migration-from-v3-to-v4)
* [Features](#features)

@@ -40,3 +41,2 @@ * [Installation](#installation)

* [Quick start](#quick-start)
* [Browser usage](#browser-usage)
* [API documentation](https://github.com/schoero/SwissQRBill/blob/master/doc/api.md)

@@ -50,2 +50,8 @@ * [PDFKit documentation](http://pdfkit.org/docs/getting_started.html)

## Migration from v3 to v4
In SwissQRBill v4, large parts of the application have been rewritten to make the API more flexible. This means that you have to make some changes to your code when upgrading from v3 to v4.
Please read the [migration guide](./docs/migration-v3-to-v4.md) to learn more about the changes and how to migrate your code.
## Features

@@ -73,65 +79,49 @@

### Node.js
Depending on the environment you are using, you may need to import the library differently. Please read the [importing documentation][importing documentation] to find out the best way to import the library for your environment.
In versions prior to v4.0.0, you could include SwissQRBill like this:
```ts
// ESM. Tree-shakeable.
import { SwissQRBill } from "swissqrbill";
// CommonJS. Not tree-shakeable.
const SwissQRBill = require("swissqrbill");
```
<br/>
In SwissQRBill `>=4.0.0` this is no longer possible. Instead yo
```ts
// PDF
import { SwissQRBill } from "swissqrbill/pdf";
// SVG
import { SwissQRBill } from "swissqrbill/svg";
// utils
import { mm2pt } from "swissqrbill/utils";
```
<br/>
## Quick start
Once you have imported SwissQRBill, it is quite easy to create a simple QR bill. All you have to do is to create a new `SwissQRBill.PDF` instance and pass your billing data object as the first parameter and your output path as the second parameter.
Once you have imported SwissQRBill, it is quite easy to create a simple QR bill. All you have to do is to create a new `SwissQRBill` instance and pass your billing data object as the first parameter and your output path as the second parameter.
```js
import { PDF } from "swissqrbill/pdf";
import { createWriteStream } from "node:fs";
import PDFDocument from "pdfkit";
import { SwissQRBill } from "swissqrbill/pdf";
const data = {
amount: 1199.95,
amount: 1994.75,
creditor: {
account: "CH4431999123000889012",
address: "Rue du Lac",
buildingNumber: "1268",
city: "Biel",
account: "CH44 3199 9123 0008 8901 2",
address: "Musterstrasse",
buildingNumber: 7,
city: "Musterstadt",
country: "CH",
name: "Robert Schneider AG",
zip: 2501
name: "SwissQRBill",
zip: 1234
},
currency: "CHF",
debtor: {
address: "Grosse Marktgasse",
buildingNumber: "28",
city: "Rorschach",
address: "Musterstrasse",
buildingNumber: 1,
city: "Musterstadt",
country: "CH",
name: "Pia-Maria Rutschmann-Schnyder",
zip: 9400
name: "Peter Muster",
zip: 1234
},
reference: "210000000003139471430009017"
reference: "21 00000 00003 13947 14300 09017"
};
const pdf = new PDF(data, "qr-bill.pdf", () => {
console.log("PDF has been successfully created.");
});
const pdf = new PDFDocument({ size: "A4" });
const qrBill = new SwissQRBill(data);
const stream = createWriteStream("qr-bill.pdf");
pdf.pipe(stream);
qrBill.attachTo(pdf);
pdf.end();
```
This will create the PDF file above. You can pass an optional third parameter containing options such as language or size etc. as well as a callback function that gets called right after the file has finished writing.
A complete documentation for all methods and parameters can be found in [doc/api.md](https://github.com/schoero/SwissQRBill/blob/master/doc/api.md).
This will create the PDF file above. You can pass an optional parameter containing options to the `SwissQRBill` constructor.
A complete documentation for all methods and parameters can be found in the [docs/][repository docs] directory of this repository.

@@ -141,29 +131,8 @@ <br/>

## Browser usage
> **Note:** Please read the [importing the library](#importing-the-library) section above, how you should import the library for browser usage.
To use SwissQRBill inside browsers, you have to pass a writableStream in the second parameter, instead of the output path. To create a writableStream in the browser you can use the built in `SwissQRBill.BlobStream()` function.
```js
import { BlobStream, PDF } from "swissqrbill/pdf";
const stream = new BlobStream();
const pdf = new PDF(data, stream);
pdf.on("finish", () => {
const iframe = document.getElementById("iframe");
if(iframe){
iframe.src = stream.toBlobURL("application/pdf");
}
console.log("PDF has been successfully created.");
});
```
Alternatively, you could render the QR Bill as a scalable vector graphic (SVG). But keep in mind, using SVG you can only render the QR Bill part and not an entire invoice.
```js
import { SVG } from "swissqrbill/svg";
import { SwissQRBill } from "swissqrbill/svg";
const svg = new SVG(data);
const svg = new SwissQRBill(data);
document.body.appendChild(svg.element);

@@ -177,7 +146,11 @@ ```

SwissQRBill.PDF extends [PDFKit](https://github.com/foliojs/pdfkit) to generate PDF files and adds a few extra methods. You can generate a complete PDF bill using the original PDFKit methods and the additional methods documented in [doc/api.md](https://github.com/schoero/SwissQRBill/tree/master/doc/api.md#methods).
SwissQRBill uses [PDFKit](https://github.com/foliojs/pdfkit) to generate the PDF files.
The documentation for PDFKit can be found [here](http://pdfkit.org/docs/getting_started.html).
A simple guide how to generate a complete bill can be found in [doc/how-to-create-a-complete-bill.md](https://github.com/schoero/SwissQRBill/blob/master/doc/how-to-create-a-complete-bill.md). You will learn how to create a PDF that looks like this:
A simple guide how to generate a complete bill can be found in [docs/how-to-create-a-complete-bill.md][how to create a complete bill]. You will learn how to create a PDF that looks like this:
[<img src="https://raw.githubusercontent.com/schoero/SwissQRBill/master/assets/complete-qr-bill.png">](https://github.com/schoero/SwissQRBill/tree/master/doc/how-to-create-a-complete-bill.md)
![Complete QR bill](assets/complete-qr-bill.png)
[importing documentation]: ./docs/importing.md
[repository docs]: ./docs/
[how to create a complete bill]: ./docs/how-to-create-a-complete-bill.md

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc