Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 1.2.0 to 1.3.0

31

CHANGELOG.md
# Change Log
# [v1.3.0](https://github.com/rogerrrrrrrs/swissqrbill/compare/v1.2.0...v1.3.0) - 25.06.2020
* Tables
- Added new header property on table rows to automatically insert a header row on new pages.
- Table row height is now automatically calculated if not otherwise defined.
- Added padding option to rows and cells.
* Events
- Added new beforeEnd event that could be used to add page numbers.
- Added new pageAdded event that could be used to add a header to the pages.
* Renamed `debitor` option to `debtor`.
* Improved documentation.
* TypeScript declaration improvements.
* Fixed typos in examples.
# [v1.2.0](https://github.com/rogerrrrrrrs/swissqrbill/compare/v1.1.0...v1.2.0) - 06.06.2020

@@ -9,14 +22,14 @@ * Added optional callback function that gets executed once the pdf file has completed writing.

# [v1.1.0](https://github.com/rogerrrrrrrs/swissqrbill/compare/v1.0.6...v1.1.0) - 15.03.2020
* Fixed some validation checks
* Improved error messages
* Added new method to generate tables
* Improved documentation
* Fixed some validation checks.
* Improved error messages.
* Added new method to generate tables.
* Improved documentation.
# [v1.0.6](https://github.com/rogerrrrrrrs/swissqrbill/compare/v1.0.5...v1.0.6) - 04.03.2020
* Fixed QR Code fields
* Validates user data
* Fixed QR Code fields.
* Added user data validation.
# [v1.0.5](https://github.com/rogerrrrrrrs/swissqrbill/compare/v1.0.4...v1.0.5) - 03.03.2020
* Fixed french characters
* Removes new lines in userdata
* Fixes some layout issues
* Fixed french characters.
* Removes new lines in userdata.
* Fixed some layout issues.

@@ -8,3 +8,3 @@ import PDFDocument from "pdfkit";

y?: number;
padding?: number;
padding?: number | [number, number, number, number];
lineWidth?: number;

@@ -19,4 +19,6 @@ font?: string;

height?: number;
padding?: number | [number, number, number, number];
font?: string;
fontSize?: number;
header?: boolean;
}

@@ -26,2 +28,3 @@ interface PDFColumn {

width?: number;
padding?: number | [number, number, number, number];
fillColor?: string;

@@ -28,0 +31,0 @@ strokeColor?: string;

@@ -27,11 +27,14 @@ "use strict";

const lineWidth = table.lineWidth !== undefined ? table.lineWidth : 0.3;
const padding = table.padding !== undefined ? table.padding : 5;
const defaultPadding = 5;
const basePadding = table.padding !== undefined ? table.padding : defaultPadding;
const baseFontSize = table.fontSize !== undefined ? table.fontSize : 11;
const baseFont = table.font !== undefined ? table.font : "Helvetica";
let rowY = tableY;
table.rows.forEach((row, rowIndex) => {
rowLoop: for (let rowIndex = 0; rowIndex < table.rows.length; rowIndex++) {
const row = table.rows[rowIndex];
const amountOfColumns = row.columns.length;
const columnWidth = tableWidth / amountOfColumns;
const rowHeight = row.height !== undefined ? row.height : 20;
const rowNumber = rowIndex + 1;
let rowHeight = row.height !== undefined ? row.height : 20;
let padding = row.padding !== undefined ? row.padding : basePadding;
let fillColor = row.fillColor !== undefined ? row.fillColor : "";

@@ -41,7 +44,2 @@ let strokeColor = row.strokeColor !== undefined ? row.strokeColor : "";

let font = row.font !== undefined ? row.font : baseFont;
//-- Insert new page
if (rowY + rowHeight >= this.page.height - this.page.margins.bottom) {
this.addPage();
rowY = this.page.margins.top;
}
//-- Move to start position

@@ -52,3 +50,4 @@ this.moveTo(tableX, tableY);

let columnX = tableX;
row.columns.forEach((column, columnIndex) => {
for (let columnIndex = 0; columnIndex < row.columns.length; columnIndex++) {
const column = row.columns[columnIndex];
const columnNumber = columnIndex + 1;

@@ -66,2 +65,3 @@ let remainingColumns = row.columns.length;

const columnWidth = column.width !== undefined ? column.width : (tableWidth - widthUsed) / (remainingColumns);
padding = column.padding !== undefined ? column.padding : padding;
fillColor = column.fillColor !== undefined ? column.fillColor : fillColor;

@@ -76,4 +76,4 @@ strokeColor = column.strokeColor !== undefined ? column.strokeColor : strokeColor;

width: columnWidth,
height: rowHeight,
baseline: "middle"
lineBreak: true,
baseline: "top"
};

@@ -83,2 +83,41 @@ if (column.textOptions !== undefined) {

}
this.moveTo(columnX + columnWidth, rowY);
this.font(font);
this.fontSize(fontSize);
//-- Set padding
let paddings = {
top: defaultPadding,
right: defaultPadding,
bottom: defaultPadding,
left: defaultPadding
};
if (typeof padding === "object" && padding.length === 4) {
paddings = { top: padding[0], right: padding[1], bottom: padding[2], left: padding[3] };
}
else if (typeof padding === "number") {
paddings = {
top: padding,
right: padding,
bottom: padding,
left: padding
};
}
const columnHeight = this.heightOfString(column.text + "", textOptions) + paddings.top + paddings.bottom;
if (columnHeight > rowHeight) {
rowHeight = columnHeight;
}
textOptions.height = rowHeight;
//-- Check for page overflow
if (rowY + rowHeight >= this.page.height - this.page.margins.bottom) {
//-- Insert new page
this.addPage();
rowY = this.y;
//-- Insert header
for (const headerRow of table.rows) {
if (headerRow.header === true) {
table.rows.splice(rowIndex, 0, headerRow, headerRow);
continue rowLoop;
}
}
}
//-- Draw rectangle

@@ -91,12 +130,9 @@ this.rect(columnX, rowY, columnWidth, rowHeight)

.fillAndStroke();
this.moveTo(columnX + columnWidth, rowY);
this.font(font);
this.fontSize(fontSize);
this.fillColor("black")
.fillOpacity(1)
.text(column.text + "", columnX + padding, rowY + (padding / 2) + (rowHeight / 2), textOptions);
.fillOpacity(1);
this.text(column.text + "", columnX + paddings.left, rowY + paddings.top, textOptions);
columnX = columnX + columnWidth;
});
}
rowY = rowY + rowHeight;
});
}
return this;

@@ -103,0 +139,0 @@ }

@@ -7,3 +7,4 @@ /// <reference types="pdfkit" />

creditor: creditor;
debitor?: debitor;
debtor?: debtor;
debitor?: debtor;
amount?: number;

@@ -16,3 +17,3 @@ reference?: string;

}
interface debitor {
interface debtor {
name: string;

@@ -25,3 +26,3 @@ address: string;

}
interface creditor extends debitor {
interface creditor extends debtor {
account: string;

@@ -35,2 +36,5 @@ }

}
export import PDFTable = ExtendedPDF.PDFTable;
export import PDFRow = ExtendedPDF.PDFRow;
export import PDFColumn = ExtendedPDF.PDFColumn;
type currency = "CHF" | "EUR";

@@ -131,2 +135,9 @@ type size = "A4" | "A6/5";

/**
* Finalizes the document
*
* @returns
* @memberof PDF
*/
end(): void;
/**
* Adds the QR Bill to the bottom of the current page.

@@ -185,3 +196,3 @@ * This function is automatically called when the option autoGenerate is set to true.

* @private
* @param {(debitor | creditor)} data creditor or debitor object containing the address.
* @param {(debtor | creditor)} data creditor or debtor object containing the address.
* @returns {string} string containing the formatted address.

@@ -188,0 +199,0 @@ * @memberof PDF

@@ -14,3 +14,3 @@ "use strict";

constructor(data, outputPath, optionsOrCallback, callbackOrUndefined) {
super({ autoFirstPage: false });
super({ autoFirstPage: false, bufferPages: true });
this.size = "A6/5";

@@ -39,3 +39,3 @@ this._scissors = true;

}
super.emit("finish", ev);
this.emit("finish", ev);
});

@@ -49,2 +49,5 @@ if (data === undefined || typeof data !== "object") {

this._data = data;
if (this._data.debtor === undefined && this._data.debitor !== undefined) {
this._data.debtor = this._data.debitor;
}
this._cleanData();

@@ -85,3 +88,3 @@ this._validateData();

}
this.info.Author = "SwissQRBill";
this.info.Producer = this.info.Creator = this.info.Author = "SwissQRBill";
this.addPage();

@@ -111,2 +114,12 @@ if (this._autoGenerate === true) {

/**
* Finalizes the document
*
* @returns
* @memberof PDF
*/
end() {
this.emit("beforeEnd", this);
return super.end();
}
/**
* Adds the QR Bill to the bottom of the current page.

@@ -217,4 +230,4 @@ * This function is automatically called when the option autoGenerate is set to true.

}
//-- Debitor
if (this._data.debitor !== undefined) {
//-- Debtor
if (this._data.debtor !== undefined) {
this.fontSize(9);

@@ -229,3 +242,3 @@ this.moveDown();

this.font("Helvetica");
this.text(this._formatAddress(this._data.debitor), {
this.text(this._formatAddress(this._data.debtor), {
width: this.mmToPoints(52)

@@ -374,3 +387,3 @@ });

}
if (this._data.debitor !== undefined) {
if (this._data.debtor !== undefined) {
this.fontSize(8);

@@ -383,3 +396,3 @@ this.font("Helvetica-Bold");

this.font("Helvetica");
this.text(this._formatAddress(this._data.debitor), {
this.text(this._formatAddress(this._data.debtor), {
width: this.mmToPoints(87)

@@ -470,3 +483,3 @@ });

if (typeof this._data.creditor.houseNumber !== "string" && typeof this._data.creditor.houseNumber !== "number") {
throw new Error("Debitor houseNumber must be either a string or a number.");
throw new Error("Debtor houseNumber must be either a string or a number.");
}

@@ -529,62 +542,62 @@ if (this._data.creditor.houseNumber.toString().length > 16) {

}
//-- Debitor
if (this._data.debitor !== undefined) {
//-- Debitor name
if (this._data.debitor.name === undefined) {
throw new Error("Debitor name cannot be undefined if the debitor object is available.");
//-- Debtor
if (this._data.debtor !== undefined) {
//-- Debtor name
if (this._data.debtor.name === undefined) {
throw new Error("Debtor name cannot be undefined if the debtor object is available.");
}
if (typeof this._data.debitor.name !== "string") {
throw new Error("Debitor name must be a string.");
if (typeof this._data.debtor.name !== "string") {
throw new Error("Debtor name must be a string.");
}
if (this._data.debitor.name.length > 70) {
throw new Error("Debitor name must be a maximum of 70 characters.");
if (this._data.debtor.name.length > 70) {
throw new Error("Debtor name must be a maximum of 70 characters.");
}
//-- Debitor address
if (this._data.debitor.address === undefined) {
throw new Error("Debitor address cannot be undefined if the debitor object is available.");
//-- Debtor address
if (this._data.debtor.address === undefined) {
throw new Error("Debtor address cannot be undefined if the debtor object is available.");
}
if (typeof this._data.debitor.address !== "string") {
throw new Error("Debitor address must be a string.");
if (typeof this._data.debtor.address !== "string") {
throw new Error("Debtor address must be a string.");
}
if (this._data.debitor.address.length > 70) {
throw new Error("Debitor address must be a maximum of 70 characters.");
if (this._data.debtor.address.length > 70) {
throw new Error("Debtor address must be a maximum of 70 characters.");
}
//-- Debitor houseNumber
if (this._data.debitor.houseNumber !== undefined) {
if (typeof this._data.debitor.houseNumber !== "string" && typeof this._data.debitor.houseNumber !== "number") {
throw new Error("Debitor house number must be either a string or a number.");
//-- Debtor houseNumber
if (this._data.debtor.houseNumber !== undefined) {
if (typeof this._data.debtor.houseNumber !== "string" && typeof this._data.debtor.houseNumber !== "number") {
throw new Error("Debtor house number must be either a string or a number.");
}
if (this._data.debitor.houseNumber.toString().length > 16) {
throw new Error("Debitor house number can be a maximum of 16 characters.");
if (this._data.debtor.houseNumber.toString().length > 16) {
throw new Error("Debtor house number can be a maximum of 16 characters.");
}
}
//-- Debitor zip
if (this._data.debitor.zip === undefined) {
throw new Error("Debitor zip cannot be undefined if the debitor object is available.");
//-- Debtor zip
if (this._data.debtor.zip === undefined) {
throw new Error("Debtor zip cannot be undefined if the debtor object is available.");
}
if (typeof this._data.debitor.zip !== "number") {
throw new Error("Debitor zip must be a number.");
if (typeof this._data.debtor.zip !== "number") {
throw new Error("Debtor zip must be a number.");
}
if (this._data.debitor.zip.toString().length > 16) {
throw new Error("Debitor zip must be a maximum of 16 characters.");
if (this._data.debtor.zip.toString().length > 16) {
throw new Error("Debtor zip must be a maximum of 16 characters.");
}
//-- Debitor city
if (this._data.debitor.city === undefined) {
throw new Error("Debitor city cannot be undefined if the debitor object is available.");
//-- Debtor city
if (this._data.debtor.city === undefined) {
throw new Error("Debtor city cannot be undefined if the debtor object is available.");
}
if (typeof this._data.debitor.city !== "string") {
throw new Error("Debitor city must be a string.");
if (typeof this._data.debtor.city !== "string") {
throw new Error("Debtor city must be a string.");
}
if (this._data.debitor.city.length > 35) {
throw new Error("Debitor city must be a maximum of 35 characters.");
if (this._data.debtor.city.length > 35) {
throw new Error("Debtor city must be a maximum of 35 characters.");
}
//-- Debitor country
if (this._data.debitor.country === undefined) {
throw new Error("Debitor country cannot be undefined if the debitor object is available.");
//-- Debtor country
if (this._data.debtor.country === undefined) {
throw new Error("Debtor country cannot be undefined if the debtor object is available.");
}
if (typeof this._data.debitor.country !== "string") {
throw new Error("Debitor country must be a string.");
if (typeof this._data.debtor.country !== "string") {
throw new Error("Debtor country must be a string.");
}
if ((this._data.debitor.country).length !== 2) {
throw new Error("Debitor country must be 2 characters.");
if ((this._data.debtor.country).length !== 2) {
throw new Error("Debtor country must be 2 characters.");
}

@@ -711,17 +724,17 @@ }

qrString += this._data.currency + "\n";
//-- Debitor
if (this._data.debitor !== undefined) {
if (this._data.debitor.houseNumber !== undefined) {
//-- Debtor
if (this._data.debtor !== undefined) {
if (this._data.debtor.houseNumber !== undefined) {
// Address type
qrString += "S\n";
// Name
qrString += this._data.debitor.name + "\n";
qrString += this._data.debtor.name + "\n";
// Address
qrString += this._data.debitor.address + "\n";
qrString += this._data.debtor.address + "\n";
// House number
qrString += this._data.debitor.houseNumber + "\n";
qrString += this._data.debtor.houseNumber + "\n";
// Zip
qrString += this._data.debitor.zip + "\n";
qrString += this._data.debtor.zip + "\n";
// City
qrString += this._data.debitor.city + "\n";
qrString += this._data.debtor.city + "\n";
}

@@ -732,10 +745,10 @@ else {

// Name
qrString += this._data.debitor.name + "\n";
qrString += this._data.debtor.name + "\n";
// Address
qrString += this._data.debitor.address + "\n";
qrString += this._data.debtor.address + "\n";
// Zip + city
if ((this._data.debitor.zip + " " + this._data.debitor.city).length > 70) {
throw new Error("Debitor zip plus city must be a maximum of 70 characters.");
if ((this._data.debtor.zip + " " + this._data.debtor.city).length > 70) {
throw new Error("Debtor zip plus city must be a maximum of 70 characters.");
}
qrString += this._data.debitor.zip + " " + this._data.debitor.city + "\n";
qrString += this._data.debtor.zip + " " + this._data.debtor.city + "\n";
// Empty field zip

@@ -747,3 +760,3 @@ qrString += "\n";

// Country
qrString += this._data.debitor.country + "\n";
qrString += this._data.debtor.country + "\n";
}

@@ -869,3 +882,3 @@ else {

* @private
* @param {(debitor | creditor)} data creditor or debitor object containing the address.
* @param {(debtor | creditor)} data creditor or debtor object containing the address.
* @returns {string} string containing the formatted address.

@@ -872,0 +885,0 @@ * @memberof PDF

{
"name": "swissqrbill",
"version": "1.2.0",
"version": "1.3.0",
"description": "Swiss QR Bill generation in node.js ",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -72,3 +72,3 @@ # SwissQRBill

},
debitor: {
debtor: {
name: "Pia-Maria Rutschmann-Schnyder",

@@ -75,0 +75,0 @@ address: "Grosse Marktgasse 28",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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