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 3.0.1 to 3.1.0

lib/extended-pdf.d.ts

11

lib/browser/esm/browser/svg.d.ts

@@ -5,4 +5,15 @@ import { SVG_ } from "../svg/svg.js";

constructor(data: Data, options?: SVGOptions);
/**
* Outputs the SVG as a string.
*
* @returns The outerHTML of the SVG as a `string`.
*/
toString(): string;
/**
* Returns the SVG element.
* > **Note:** This function is only available in the browser.
*
* @readonly
*/
get element(): SVGElement;
}

@@ -6,5 +6,16 @@ import { SVG_ } from "../svg/svg.js";

}
/**
* Outputs the SVG as a string.
*
* @returns The outerHTML of the SVG as a `string`.
*/
toString() {
return this.outerHTML;
}
/**
* Returns the SVG element.
* > **Note:** This function is only available in the browser.
*
* @readonly
*/
get element() {

@@ -11,0 +22,0 @@ return this.instance.element;

import PDFDocument from "pdfkit";
export interface PDFTable {
/**
* Table rows.
*/
rows: Array<PDFRow>;
/**
* Width of whole table.
*/
width?: number;
/**
* Horizontal start position of the table.
*/
x?: number;
/**
* Vertical start position of the table.
*/
y?: number;
/**
* Cell padding of the table cells.
*/
padding?: number | [number, number?, number?, number?];
/**
* Width of the border lines.
*/
lineWidth?: number;
/**
* Font of the text inside the table.
*/
font?: string;
/**
* Font size of the text inside the table.
*/
fontSize?: number;
}
export interface PDFRow {
/**
* Table columns.
*/
columns: Array<PDFColumn>;
/**
* Background color of the row.
*/
fillColor?: string;
/**
* Border color of the row.
*/
strokeColor?: string;
/**
* Height of the row.
*/
height?: number;
/**
* Cell padding of the table cells inside the row.
*/
padding?: number | [number, number?, number?, number?];
/**
* Font of the text inside the row.
*/
font?: string;
/**
* Font size of the text inside the row.
*/
fontSize?: number;
/**
* A header row gets inserted automatically on new pages. Only one header row is allowed.
*/
header?: boolean;
}
export interface PDFColumn {
/**
* Cell text.
*/
text: string | number | boolean;
/**
* Width of the cell.
*/
width?: number;
/**
* Cell padding of the table cell.
*/
padding?: number | [number, number?, number?, number?];
/**
* Background color of the cell.
*/
fillColor?: string;
/**
* Border color of the cell.
*/
strokeColor?: string;
/**
* Font of the text inside the cell.
*/
font?: string;
/**
* Font size of the text inside the cell.
*/
fontSize?: number;
/**
* Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling).
*/
textOptions?: PDFKit.Mixins.TextOptions;

@@ -34,4 +106,47 @@ }

constructor(options?: PDFKit.PDFDocumentOptions);
/**
* Inserts a table to the document.
*
* @param table - An Object which contains the table information.
* @returns `this`
* @example
* ```
* const table = {
* rows: [
* {
* fillColor: "#ECF0F1",
* columns: [
* {
* text: "Row 1 cell 1",
* }, {
* text: "Row 1 cell 2",
* }, {
* text: "Row 1 cell 3"
* }
* ]
* }, {
* columns: [
* {
* text: "Row 2 cell 1",
* }, {
* text: "Row 2 cell 2",
* }, {
* text: "Row 2 cell 3"
* }
* ]
* }
* ]
* };
* ```
*/
addTable(table: PDFTable): PDFKit.PDFDocument;
/**
* Adds a path to the document on the given position.
*
* @param path - The path data to insert. This is the same as the `d` attribute of a SVG path.
* @param x - The x position where the path should be inserted.
* @param y - The y position where the path should be inserted.
* @returns `this`
*/
addPath(path: string, x: number, y: number): PDFKit.PDFDocument;
}

@@ -7,2 +7,37 @@ import PDFDocument from "pdfkit";

}
/**
* Inserts a table to the document.
*
* @param table - An Object which contains the table information.
* @returns `this`
* @example
* ```
* const table = {
* rows: [
* {
* fillColor: "#ECF0F1",
* columns: [
* {
* text: "Row 1 cell 1",
* }, {
* text: "Row 1 cell 2",
* }, {
* text: "Row 1 cell 3"
* }
* ]
* }, {
* columns: [
* {
* text: "Row 2 cell 1",
* }, {
* text: "Row 2 cell 2",
* }, {
* text: "Row 2 cell 3"
* }
* ]
* }
* ]
* };
* ```
*/
addTable(table) {

@@ -134,2 +169,10 @@ if (table.rows === undefined) {

}
/**
* Adds a path to the document on the given position.
*
* @param path - The path data to insert. This is the same as the `d` attribute of a SVG path.
* @param x - The x position where the path should be inserted.
* @param y - The y position where the path should be inserted.
* @returns `this`
*/
addPath(path, x, y) {

@@ -136,0 +179,0 @@ path = svgpath(path)

11

lib/browser/esm/pdf/pdf.d.ts

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

constructor(data: Data, options?: PDFOptions);
/**
* Adds a new page to the PDF. This method is basically the same as the original [PDFKit `addPage()` method](https://pdfkit.org/docs/getting_started.html#adding_pages). However the default values are changed to use the default page size provided in the constructor options.
* @param options - An object containing [PDFKit document options.](https://pdfkit.org/docs/getting_started.html#adding_pages)
* @returns `this`
*/
addPage(options?: PDFKit.PDFDocumentOptions): PDFKit.PDFDocument;
end(): void;
/**
* Adds the QR Slip to the bottom of the current page if there is enough space, otherwise it will create a new page with the specified size and add it to the bottom of this page.
*
* @param size - The size of the new page if not enough space is left for the QR slip.
*/
addQRBill(size?: Size): void;

@@ -21,4 +31,3 @@ private _render;

private _formatAddress;
private _formatReference;
private _addRectangle;
}

128

lib/browser/esm/pdf/pdf.js

@@ -55,2 +55,7 @@ import { ExtendedPDF } from "./extended-pdf.js";

}
/**
* Adds a new page to the PDF. This method is basically the same as the original [PDFKit `addPage()` method](https://pdfkit.org/docs/getting_started.html#adding_pages). However the default values are changed to use the default page size provided in the constructor options.
* @param options - An object containing [PDFKit document options.](https://pdfkit.org/docs/getting_started.html#adding_pages)
* @returns `this`
*/
addPage(options) {

@@ -70,2 +75,7 @@ if (options === undefined) {

}
/**
* Adds the QR Slip to the bottom of the current page if there is enough space, otherwise it will create a new page with the specified size and add it to the bottom of this page.
*
* @param size - The size of the new page if not enough space is left for the QR slip.
*/
addQRBill(size = "A6/5") {

@@ -138,4 +148,5 @@ if (this.page.height - this.y < utils.mm2pt(105) && this.y !== this.page.margins.top) {

this.font("Helvetica-Bold");
this.text(translations[this._language].account, utils.mm2pt(5), this._marginTop + utils.mm2pt(12), {
width: utils.mm2pt(52)
this.text(translations[this._language].account, utils.mm2pt(5), this._marginTop + utils.mm2pt(12) + 3, {
width: utils.mm2pt(52),
lineGap: 1
});

@@ -146,3 +157,4 @@ //-- Creditor

this.text(`${utils.formatIBAN(this._data.creditor.account)}\n${this._formatAddress(this._data.creditor)}`, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: -.5
});

@@ -155,8 +167,10 @@ this.moveDown();

this.text(translations[this._language].reference, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: 1
});
this.fontSize(8);
this.font("Helvetica");
this.text(this._formatReference(this._data.reference), {
width: utils.mm2pt(52)
this.text(utils.formatReference(this._data.reference), {
width: utils.mm2pt(52),
lineGap: -.5
});

@@ -171,3 +185,4 @@ }

this.text(translations[this._language].payableBy, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: 1
});

@@ -177,3 +192,4 @@ this.fontSize(8);

this.text(this._formatAddress(this._data.debtor), {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: -.5
});

@@ -187,3 +203,4 @@ }

this.text(translations[this._language].payableByName, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: 1
});

@@ -197,6 +214,9 @@ //-- Add rectangle

this.text(translations[this._language].currency, utils.mm2pt(5), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});
this.text(translations[this._language].amount, utils.mm2pt(18), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(37)
const amountXPosition = this._data.amount === undefined ? 18 : 27;
this.text(translations[this._language].amount, utils.mm2pt(amountXPosition), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(52 - amountXPosition),
lineGap: 1
});

@@ -206,7 +226,9 @@ this.fontSize(8);

this.text(this._data.currency, utils.mm2pt(5), this._marginTop + utils.mm2pt(71), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: -.5
});
if (this._data.amount !== undefined) {
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(18), this._marginTop + utils.mm2pt(71), {
width: utils.mm2pt(37)
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(amountXPosition), this._marginTop + utils.mm2pt(71), {
width: utils.mm2pt(52 - amountXPosition),
lineGap: -.5
});

@@ -221,3 +243,4 @@ }

width: utils.mm2pt(52),
align: "right"
align: "right",
lineGap: 1
});

@@ -229,3 +252,4 @@ //-- Payment part middle container

width: utils.mm2pt(51),
align: "left"
align: "left",
lineGap: 1
});

@@ -239,6 +263,7 @@ //-- QR Code

this.text(translations[this._language].currency, utils.mm2pt(67), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});
this.text(translations[this._language].amount, utils.mm2pt(87), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(36)
this.text(translations[this._language].amount, utils.mm2pt(89), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(29)
});

@@ -248,7 +273,9 @@ this.fontSize(10);

this.text(this._data.currency, utils.mm2pt(67), this._marginTop + utils.mm2pt(72), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: -.5
});
if (this._data.amount !== undefined) {
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(87), this._marginTop + utils.mm2pt(72), {
width: utils.mm2pt(36)
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(89), this._marginTop + utils.mm2pt(72), {
width: utils.mm2pt(29),
lineGap: -.5
});

@@ -264,3 +291,4 @@ }

this.text("Name AV1:", utils.mm2pt(67), this._marginTop + utils.mm2pt(90), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});

@@ -270,3 +298,4 @@ this.fontSize(7);

this.text((this._data.av1.length > 87 ? this._data.av1.substr(0, 87) + "..." : this._data.av1), utils.mm2pt(81), this._marginTop + utils.mm2pt(90), {
width: utils.mm2pt(37)
width: utils.mm2pt(37),
lineGap: -.5
});

@@ -278,3 +307,4 @@ }

this.text("Name AV2:", utils.mm2pt(67), this._marginTop + utils.mm2pt(93), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});

@@ -284,3 +314,4 @@ this.fontSize(7);

this.text((this._data.av2.length > 87 ? this._data.av2.substr(0, 87) + "..." : this._data.av2), utils.mm2pt(81), this._marginTop + utils.mm2pt(93), {
width: utils.mm2pt(37)
width: utils.mm2pt(37),
lineGap: -.5
});

@@ -291,9 +322,11 @@ }

this.font("Helvetica-Bold");
this.text(translations[this._language].account, utils.mm2pt(118), this._marginTop + utils.mm2pt(5), {
width: utils.mm2pt(87)
this.text(translations[this._language].account, utils.mm2pt(118), this._marginTop + utils.mm2pt(5) + 3, {
width: utils.mm2pt(87),
lineGap: 1
});
this.fontSize(10);
this.font("Helvetica");
this.text(`${utils.formatIBAN(this._data.creditor.account)}\n${this._formatAddress(this._data.creditor)}`, utils.mm2pt(118), this._marginTop + utils.mm2pt(8), {
width: utils.mm2pt(87)
this.text(`${utils.formatIBAN(this._data.creditor.account)}\n${this._formatAddress(this._data.creditor)}`, {
width: utils.mm2pt(87),
lineGap: -.75
});

@@ -305,8 +338,10 @@ this.moveDown();

this.text(translations[this._language].reference, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});
this.fontSize(10);
this.font("Helvetica");
this.text(this._formatReference(this._data.reference), {
width: utils.mm2pt(87)
this.text(utils.formatReference(this._data.reference), {
width: utils.mm2pt(87),
lineGap: -.75
});

@@ -320,3 +355,4 @@ this.moveDown();

this.text(translations[this._language].additionalInformation, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});

@@ -326,3 +362,4 @@ this.fontSize(10);

const options = {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: -.75
};

@@ -358,3 +395,4 @@ const singleLineHeight = this.heightOfString("A", options);

this.text(translations[this._language].payableBy, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});

@@ -364,3 +402,4 @@ this.fontSize(10);

this.text(this._formatAddress(this._data.debtor), {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: -.75
});

@@ -372,3 +411,4 @@ }

this.text(translations[this._language].payableByName, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});

@@ -405,12 +445,2 @@ this._addRectangle(118, utils.pt2mm(this.y), 65, 25);

}
_formatReference(reference) {
const referenceType = utils.getReferenceType(reference);
if (referenceType === "QRR") {
return utils.formatQRReference(reference);
}
else if (referenceType === "SCOR") {
return utils.formatSCORReference(reference);
}
return reference;
}
_addRectangle(x, y, width, height) {

@@ -417,0 +447,0 @@ const length = 3;

@@ -6,33 +6,117 @@ export { PDFTable, PDFRow, PDFColumn } from "../pdf/extended-pdf";

export interface Data {
/**
* The currency to be used. **3 characters.**
*/
currency: Currency;
creditor: Creditor;
debtor?: Debtor;
/**
* The amount. **Max. 12 digits.**
*/
amount?: number;
/**
* A reference number. **Max 27 characters.**
* > QR-IBAN: Maximum 27 characters. Must be filled if a QR-IBAN is used.
* Creditor Reference (ISO 11649): Maximum 25 characters.
*/
reference?: string;
/**
* A message. **Max. 140 characters.**
* > message can be used to indicate the payment purpose or for additional textual information about payments with a structured reference.
*/
message?: string;
/**
* Additional information. **Max 140 characters.**
* > Bill information contain coded information for automated booking of the payment. The data is not forwarded with the payment.
*/
additionalInformation?: string;
/**
* Alternative scheme. **Max. 100 characters.**
* > Parameter character chain of the alternative scheme according to the syntax definition in the [“Alternative scheme” section](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf)
*/
av1?: string;
/**
* Alternative scheme. **Max. 100 characters.**
* > Parameter character chain of the alternative scheme according to the syntax definition in the [“Alternative scheme” section](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf)
*/
av2?: string;
/**
* Creditor related data.
*/
creditor: Creditor;
/**
* Debtor related data.
*/
debtor?: Debtor;
}
export interface Debtor {
/**
* Name. **Max. 70 characters.**
*/
name: string;
/**
* Address. **Max 70 characters.**
*/
address: string;
/**
* Building number. **Max 16 characters.**
*/
buildingNumber?: string | number;
/**
* Postal code. **Max 16 characters.**
*/
zip: string | number;
/**
* City. **Max 35 characters.**
*/
city: string;
/**
* Country code. **2 characters.**
*/
country: string;
buildingNumber?: string | number;
}
export interface Creditor extends Debtor {
/**
* The IBAN. **21 characters.**
*/
account: string;
}
export interface PDFOptions {
/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
/**
* The page size.
* @defaultValue `"A6/5"`
*/
size?: Size;
/**
* Whether you want to show the scissors icons or the text `Separate before paying in`.
* > **Warning:** Setting **scissors** to false sets **separate** to true. To disable scissors and separate, you have to set both options to false.
* @defaultValue `true`
*/
scissors?: boolean;
/**
* Whether you want to show the text `Separate before paying in` rather than the scissors icons.
* > **Warning:** Setting **separate** to true sets **scissors** to false. To disable scissors and separate, you have to set both options to false.
* @defaultValue `false`
*/
separate?: boolean;
/**
* Whether you want render the outlines. This option may be disabled if you use perforated paper.
* @defaultValue `true`
*/
outlines?: boolean;
/**
* Whether you want to automatically finalize the PDF. When set to false you are able to add your own content to the PDF using PDFKit.
* @defaultValue `true`
*/
autoGenerate?: boolean;
}
export interface SVGOptions {
/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
}

@@ -0,14 +1,99 @@

/**
* Checks whether the given iban is a QR-IBAN or not.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the given IBAN is a QR-IBAN and `false` otherwise.
*/
export declare function isQRIBAN(iban: string): boolean;
/**
* Validates the given IBAN.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the checksum of the given IBAN is valid and `false` otherwise.
*/
export declare function isIBANValid(iban: string): boolean;
/**
* Formats the given IBAN according the specifications to be easily readable.
*
* @param iban - The IBAN to be formatted.
* @returns The formatted IBAN.
*/
export declare function formatIBAN(iban: string): string;
/**
* Checks whether the given reference is a QR-Reference or not.
*
* @param reference - The Reference to be checked.
* @returns `true` if the given reference is a QR-Reference and `false` otherwise.
*/
export declare function isQRReference(reference: string): boolean;
/**
* Validates the given reference.
*
* @param reference - The reference to be checked.
* @returns `true` if the given reference is valid and `false` otherwise.
*/
export declare function isQRReferenceValid(reference: string): boolean;
export declare function getReferenceType(reference: string | undefined): "QRR" | "SCOR" | "NON";
/**
* Calculates the checksum according the specifications.
*
* @param reference - The 26 digits long reference (without the checksum) whose checksum should be calculated.
* @returns The calculated checksum.
*/
export declare function calculateQRReferenceChecksum(reference: string): string;
/**
* Formats the given QR-Reference according the specifications to be easily readable.
*
* @param reference - The QR-Reference to be formatted.
* @returns The formatted QR-Reference.
*/
export declare function formatQRReference(reference: string): string;
/**
* Detects the type of the given reference and formats it according the specifications to be easily readable.
*
* @param reference - The reference to be formatted.
* @returns The formatted reference.
*/
export declare function formatReference(reference: string): string;
/**
* Formats the given SCOR-Reference according the specifications to be easily readable.
*
* @param reference - The SCOR-Reference to be formatted.
* @returns The formatted SCOR-Reference.
*/
export declare function formatSCORReference(reference: string): string;
/**
* Formats the given amount according the specifications to be easily readable.
*
* @param amount - containing the amount to be formatted.
* @returns The formatted amount.
*/
export declare function formatAmount(amount: number): string;
/**
* Converts milimeters to points.
*
* @param millimeters - The millimeters you want to convert to points.
* @returns The converted millimeters in points.
*/
export declare function mm2pt(millimeters: number): number;
/**
* Converts points to millimeters.
*
* @param points - The points you want to convert to millimeters.
* @returns The converted points in millimeters.
*/
export declare function pt2mm(points: number): number;
export declare function mm2pt(millimeters: number): number;
/**
* Converts milimeters to pixels.
*
* @param millimeters - The millimeters you want to convert to pixels.
* @returns The converted millimeters in pixels.
*/
export declare function mm2px(millimeters: number): number;
/**
* Converts pixels to millimeters.
*
* @param pixels - containg the pixels you want to convert to millimeters.
* @returns The converted pixels in millimeters.
*/
export declare function px2mm(pixels: number): number;
export declare function getReferenceType(reference: string | undefined): "QRR" | "SCOR" | "NON";

@@ -0,1 +1,7 @@

/**
* Checks whether the given iban is a QR-IBAN or not.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the given IBAN is a QR-IBAN and `false` otherwise.
*/
export function isQRIBAN(iban) {

@@ -6,2 +12,8 @@ iban = iban.replace(/ /g, "");

}
/**
* Validates the given IBAN.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the checksum of the given IBAN is valid and `false` otherwise.
*/
export function isIBANValid(iban) {

@@ -24,2 +36,8 @@ iban = iban.replace(/ /g, "");

}
/**
* Formats the given IBAN according the specifications to be easily readable.
*
* @param iban - The IBAN to be formatted.
* @returns The formatted IBAN.
*/
export function formatIBAN(iban) {

@@ -31,2 +49,8 @@ var _a;

}
/**
* Checks whether the given reference is a QR-Reference or not.
*
* @param reference - The Reference to be checked.
* @returns `true` if the given reference is a QR-Reference and `false` otherwise.
*/
export function isQRReference(reference) {

@@ -44,2 +68,8 @@ reference = reference.replace(/ /g, "");

}
/**
* Validates the given reference.
*
* @param reference - The reference to be checked.
* @returns `true` if the given reference is valid and `false` otherwise.
*/
export function isQRReferenceValid(reference) {

@@ -58,16 +88,17 @@ reference = reference.replace(/ /g, "");

}
export function getReferenceType(reference) {
if (typeof reference === "undefined") {
return "NON";
}
else if (isQRReference(reference)) {
return "QRR";
}
else {
return "SCOR";
}
}
/**
* Calculates the checksum according the specifications.
*
* @param reference - The 26 digits long reference (without the checksum) whose checksum should be calculated.
* @returns The calculated checksum.
*/
export function calculateQRReferenceChecksum(reference) {
return mod10(reference);
}
/**
* Formats the given QR-Reference according the specifications to be easily readable.
*
* @param reference - The QR-Reference to be formatted.
* @returns The formatted QR-Reference.
*/
export function formatQRReference(reference) {

@@ -82,2 +113,24 @@ reference = reference.replace(/ /g, "");

}
/**
* Detects the type of the given reference and formats it according the specifications to be easily readable.
*
* @param reference - The reference to be formatted.
* @returns The formatted reference.
*/
export function formatReference(reference) {
const referenceType = getReferenceType(reference);
if (referenceType === "QRR") {
return formatQRReference(reference);
}
else if (referenceType === "SCOR") {
return formatSCORReference(reference);
}
return reference;
}
/**
* Formats the given SCOR-Reference according the specifications to be easily readable.
*
* @param reference - The SCOR-Reference to be formatted.
* @returns The formatted SCOR-Reference.
*/
export function formatSCORReference(reference) {

@@ -92,4 +145,10 @@ reference = reference.replace(/ /g, "");

}
/**
* Formats the given amount according the specifications to be easily readable.
*
* @param amount - containing the amount to be formatted.
* @returns The formatted amount.
*/
export function formatAmount(amount) {
const amountString = amount.toFixed(2) + "";
const amountString = amount.toFixed(2);
const amountArray = amountString.split(".");

@@ -104,16 +163,51 @@ let formattedAmountWithoutDecimals = "";

}
return formattedAmountWithoutDecimals + "." + amountArray[1];
return formattedAmountWithoutDecimals.trim() + "." + amountArray[1];
}
/**
* Converts milimeters to points.
*
* @param millimeters - The millimeters you want to convert to points.
* @returns The converted millimeters in points.
*/
export function mm2pt(millimeters) {
return millimeters * 2.83465;
}
/**
* Converts points to millimeters.
*
* @param points - The points you want to convert to millimeters.
* @returns The converted points in millimeters.
*/
export function pt2mm(points) {
return points / 2.83465;
}
export function mm2pt(millimeters) {
return millimeters * 2.83465;
}
/**
* Converts milimeters to pixels.
*
* @param millimeters - The millimeters you want to convert to pixels.
* @returns The converted millimeters in pixels.
*/
export function mm2px(millimeters) {
return millimeters * 960 / 254;
}
/**
* Converts pixels to millimeters.
*
* @param pixels - containg the pixels you want to convert to millimeters.
* @returns The converted pixels in millimeters.
*/
export function px2mm(pixels) {
return pixels * 254 / 960;
}
export function getReferenceType(reference) {
if (typeof reference === "undefined") {
return "NON";
}
else if (isQRReference(reference)) {
return "QRR";
}
else {
return "SCOR";
}
}
function mod9710(iban) {

@@ -120,0 +214,0 @@ let remainder = iban;

@@ -86,7 +86,7 @@ import { validateData, cleanData } from "../shared/shared.js";

.x(0)
.dy("15pt")
.dy("18pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("6pt");
receiptTextContainer.addTSpan(utils.formatIBAN(this._data.reference))
receiptTextContainer.addTSpan(utils.formatReference(this._data.reference))
.x(0)

@@ -104,3 +104,3 @@ .dy("9pt")

.x(0)
.dy("15pt")
.dy("18pt")
.fontFamily("Arial")

@@ -127,8 +127,8 @@ .fontWeight("bold")

.x(0)
.dy("15pt")
.dy("18pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("6pt");
const referenceHeight = this._data.reference !== undefined ? "15pt" : "0";
this._addRectangle(5, calc(`12mm + 9pt + (${receiptLineCount} * 9pt) + ${referenceHeight} + 15pt + 1mm`, "mm"), 52, 20);
const referenceHeight = this._data.reference !== undefined ? "18pt" : "0";
this._addRectangle(5, calc(`12mm + 9pt + (${receiptLineCount} * 9pt) + ${referenceHeight} + 18pt + 1mm`, "mm"), 52, 20);
}

@@ -144,4 +144,5 @@ //-- Amount

.fontSize("6pt");
const amountXPosition = this._data.amount === undefined ? 13 : 22;
amountContainer.addTSpan(translations[this._language].amount)
.x("13mm")
.x(amountXPosition + "mm")
.fontFamily("Arial")

@@ -158,3 +159,3 @@ .fontWeight("bold")

amountContainer.addTSpan(utils.formatAmount(this._data.amount))
.x("13mm")
.x(amountXPosition + "mm")
.fontFamily("Arial")

@@ -198,3 +199,3 @@ .fontWeight("normal")

paymentPartMiddleTextContainer.addTSpan(translations[this._language].amount)
.x("20mm")
.x("22mm")
.fontFamily("Arial")

@@ -211,3 +212,3 @@ .fontWeight("bold")

paymentPartMiddleTextContainer.addTSpan(utils.formatAmount(this._data.amount))
.x("20mm")
.x("22mm")
.fontFamily("Arial")

@@ -260,3 +261,3 @@ .fontWeight("normal")

.y(0)
.dy("8pt")
.dy("11pt")
.fontFamily("Arial")

@@ -290,7 +291,7 @@ .fontWeight("bold")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("8pt");
paymentPartRightTextContainer.addTSpan(utils.formatIBAN(this._data.reference))
paymentPartRightTextContainer.addTSpan(utils.formatReference(this._data.reference))
.x(0)

@@ -307,3 +308,3 @@ .dy("11pt")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")

@@ -375,3 +376,3 @@ .fontWeight("bold")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")

@@ -397,9 +398,9 @@ .fontWeight("bold")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("8pt");
const referenceHeight = this._data.reference !== undefined ? "19pt" : "0";
const additionalInformationHeight = this._data.additionalInformation !== undefined || this._data.message !== undefined ? "19pt" : "0";
this._addRectangle(118, calc(`5mm + 8pt + (${paymentPartLineCount} * 11pt) + ${referenceHeight} + ${additionalInformationHeight} + 19pt + 1mm`, "mm"), 65, 25);
const referenceHeight = this._data.reference !== undefined ? "22pt" : "0";
const additionalInformationHeight = this._data.additionalInformation !== undefined || this._data.message !== undefined ? "22pt" : "0";
this._addRectangle(118, calc(`5mm + 11pt + (${paymentPartLineCount} * 11pt) + ${referenceHeight} + ${additionalInformationHeight} + 22pt + 1mm`, "mm"), 65, 25);
}

@@ -406,0 +407,0 @@ }

import PDFDocument from "pdfkit";
export interface PDFTable {
/**
* Table rows.
*/
rows: Array<PDFRow>;
/**
* Width of whole table.
*/
width?: number;
/**
* Horizontal start position of the table.
*/
x?: number;
/**
* Vertical start position of the table.
*/
y?: number;
/**
* Cell padding of the table cells.
*/
padding?: number | [number, number?, number?, number?];
/**
* Width of the border lines.
*/
lineWidth?: number;
/**
* Font of the text inside the table.
*/
font?: string;
/**
* Font size of the text inside the table.
*/
fontSize?: number;
}
export interface PDFRow {
/**
* Table columns.
*/
columns: Array<PDFColumn>;
/**
* Background color of the row.
*/
fillColor?: string;
/**
* Border color of the row.
*/
strokeColor?: string;
/**
* Height of the row.
*/
height?: number;
/**
* Cell padding of the table cells inside the row.
*/
padding?: number | [number, number?, number?, number?];
/**
* Font of the text inside the row.
*/
font?: string;
/**
* Font size of the text inside the row.
*/
fontSize?: number;
/**
* A header row gets inserted automatically on new pages. Only one header row is allowed.
*/
header?: boolean;
}
export interface PDFColumn {
/**
* Cell text.
*/
text: string | number | boolean;
/**
* Width of the cell.
*/
width?: number;
/**
* Cell padding of the table cell.
*/
padding?: number | [number, number?, number?, number?];
/**
* Background color of the cell.
*/
fillColor?: string;
/**
* Border color of the cell.
*/
strokeColor?: string;
/**
* Font of the text inside the cell.
*/
font?: string;
/**
* Font size of the text inside the cell.
*/
fontSize?: number;
/**
* Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling).
*/
textOptions?: PDFKit.Mixins.TextOptions;

@@ -34,4 +106,47 @@ }

constructor(options?: PDFKit.PDFDocumentOptions);
/**
* Inserts a table to the document.
*
* @param table - An Object which contains the table information.
* @returns `this`
* @example
* ```
* const table = {
* rows: [
* {
* fillColor: "#ECF0F1",
* columns: [
* {
* text: "Row 1 cell 1",
* }, {
* text: "Row 1 cell 2",
* }, {
* text: "Row 1 cell 3"
* }
* ]
* }, {
* columns: [
* {
* text: "Row 2 cell 1",
* }, {
* text: "Row 2 cell 2",
* }, {
* text: "Row 2 cell 3"
* }
* ]
* }
* ]
* };
* ```
*/
addTable(table: PDFTable): PDFKit.PDFDocument;
/**
* Adds a path to the document on the given position.
*
* @param path - The path data to insert. This is the same as the `d` attribute of a SVG path.
* @param x - The x position where the path should be inserted.
* @param y - The y position where the path should be inserted.
* @returns `this`
*/
addPath(path: string, x: number, y: number): PDFKit.PDFDocument;
}

@@ -13,2 +13,37 @@ "use strict";

}
/**
* Inserts a table to the document.
*
* @param table - An Object which contains the table information.
* @returns `this`
* @example
* ```
* const table = {
* rows: [
* {
* fillColor: "#ECF0F1",
* columns: [
* {
* text: "Row 1 cell 1",
* }, {
* text: "Row 1 cell 2",
* }, {
* text: "Row 1 cell 3"
* }
* ]
* }, {
* columns: [
* {
* text: "Row 2 cell 1",
* }, {
* text: "Row 2 cell 2",
* }, {
* text: "Row 2 cell 3"
* }
* ]
* }
* ]
* };
* ```
*/
addTable(table) {

@@ -140,2 +175,10 @@ if (table.rows === undefined) {

}
/**
* Adds a path to the document on the given position.
*
* @param path - The path data to insert. This is the same as the `d` attribute of a SVG path.
* @param x - The x position where the path should be inserted.
* @param y - The y position where the path should be inserted.
* @returns `this`
*/
addPath(path, x, y) {

@@ -142,0 +185,0 @@ path = (0, svgpath_1.default)(path)

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

constructor(data: Data, options?: PDFOptions);
/**
* Adds a new page to the PDF. This method is basically the same as the original [PDFKit `addPage()` method](https://pdfkit.org/docs/getting_started.html#adding_pages). However the default values are changed to use the default page size provided in the constructor options.
* @param options - An object containing [PDFKit document options.](https://pdfkit.org/docs/getting_started.html#adding_pages)
* @returns `this`
*/
addPage(options?: PDFKit.PDFDocumentOptions): PDFKit.PDFDocument;
end(): void;
/**
* Adds the QR Slip to the bottom of the current page if there is enough space, otherwise it will create a new page with the specified size and add it to the bottom of this page.
*
* @param size - The size of the new page if not enough space is left for the QR slip.
*/
addQRBill(size?: Size): void;

@@ -21,4 +31,3 @@ private _render;

private _formatAddress;
private _formatReference;
private _addRectangle;
}

@@ -80,2 +80,7 @@ "use strict";

}
/**
* Adds a new page to the PDF. This method is basically the same as the original [PDFKit `addPage()` method](https://pdfkit.org/docs/getting_started.html#adding_pages). However the default values are changed to use the default page size provided in the constructor options.
* @param options - An object containing [PDFKit document options.](https://pdfkit.org/docs/getting_started.html#adding_pages)
* @returns `this`
*/
addPage(options) {

@@ -95,2 +100,7 @@ if (options === undefined) {

}
/**
* Adds the QR Slip to the bottom of the current page if there is enough space, otherwise it will create a new page with the specified size and add it to the bottom of this page.
*
* @param size - The size of the new page if not enough space is left for the QR slip.
*/
addQRBill(size = "A6/5") {

@@ -163,4 +173,5 @@ if (this.page.height - this.y < utils.mm2pt(105) && this.y !== this.page.margins.top) {

this.font("Helvetica-Bold");
this.text(translations_js_1.default[this._language].account, utils.mm2pt(5), this._marginTop + utils.mm2pt(12), {
width: utils.mm2pt(52)
this.text(translations_js_1.default[this._language].account, utils.mm2pt(5), this._marginTop + utils.mm2pt(12) + 3, {
width: utils.mm2pt(52),
lineGap: 1
});

@@ -171,3 +182,4 @@ //-- Creditor

this.text(`${utils.formatIBAN(this._data.creditor.account)}\n${this._formatAddress(this._data.creditor)}`, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: -.5
});

@@ -180,8 +192,10 @@ this.moveDown();

this.text(translations_js_1.default[this._language].reference, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: 1
});
this.fontSize(8);
this.font("Helvetica");
this.text(this._formatReference(this._data.reference), {
width: utils.mm2pt(52)
this.text(utils.formatReference(this._data.reference), {
width: utils.mm2pt(52),
lineGap: -.5
});

@@ -196,3 +210,4 @@ }

this.text(translations_js_1.default[this._language].payableBy, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: 1
});

@@ -202,3 +217,4 @@ this.fontSize(8);

this.text(this._formatAddress(this._data.debtor), {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: -.5
});

@@ -212,3 +228,4 @@ }

this.text(translations_js_1.default[this._language].payableByName, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: 1
});

@@ -222,6 +239,9 @@ //-- Add rectangle

this.text(translations_js_1.default[this._language].currency, utils.mm2pt(5), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});
this.text(translations_js_1.default[this._language].amount, utils.mm2pt(18), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(37)
const amountXPosition = this._data.amount === undefined ? 18 : 27;
this.text(translations_js_1.default[this._language].amount, utils.mm2pt(amountXPosition), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(52 - amountXPosition),
lineGap: 1
});

@@ -231,7 +251,9 @@ this.fontSize(8);

this.text(this._data.currency, utils.mm2pt(5), this._marginTop + utils.mm2pt(71), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: -.5
});
if (this._data.amount !== undefined) {
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(18), this._marginTop + utils.mm2pt(71), {
width: utils.mm2pt(37)
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(amountXPosition), this._marginTop + utils.mm2pt(71), {
width: utils.mm2pt(52 - amountXPosition),
lineGap: -.5
});

@@ -246,3 +268,4 @@ }

width: utils.mm2pt(52),
align: "right"
align: "right",
lineGap: 1
});

@@ -254,3 +277,4 @@ //-- Payment part middle container

width: utils.mm2pt(51),
align: "left"
align: "left",
lineGap: 1
});

@@ -264,6 +288,7 @@ //-- QR Code

this.text(translations_js_1.default[this._language].currency, utils.mm2pt(67), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});
this.text(translations_js_1.default[this._language].amount, utils.mm2pt(87), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(36)
this.text(translations_js_1.default[this._language].amount, utils.mm2pt(89), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(29)
});

@@ -273,7 +298,9 @@ this.fontSize(10);

this.text(this._data.currency, utils.mm2pt(67), this._marginTop + utils.mm2pt(72), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: -.5
});
if (this._data.amount !== undefined) {
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(87), this._marginTop + utils.mm2pt(72), {
width: utils.mm2pt(36)
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(89), this._marginTop + utils.mm2pt(72), {
width: utils.mm2pt(29),
lineGap: -.5
});

@@ -289,3 +316,4 @@ }

this.text("Name AV1:", utils.mm2pt(67), this._marginTop + utils.mm2pt(90), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});

@@ -295,3 +323,4 @@ this.fontSize(7);

this.text((this._data.av1.length > 87 ? this._data.av1.substr(0, 87) + "..." : this._data.av1), utils.mm2pt(81), this._marginTop + utils.mm2pt(90), {
width: utils.mm2pt(37)
width: utils.mm2pt(37),
lineGap: -.5
});

@@ -303,3 +332,4 @@ }

this.text("Name AV2:", utils.mm2pt(67), this._marginTop + utils.mm2pt(93), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});

@@ -309,3 +339,4 @@ this.fontSize(7);

this.text((this._data.av2.length > 87 ? this._data.av2.substr(0, 87) + "..." : this._data.av2), utils.mm2pt(81), this._marginTop + utils.mm2pt(93), {
width: utils.mm2pt(37)
width: utils.mm2pt(37),
lineGap: -.5
});

@@ -316,9 +347,11 @@ }

this.font("Helvetica-Bold");
this.text(translations_js_1.default[this._language].account, utils.mm2pt(118), this._marginTop + utils.mm2pt(5), {
width: utils.mm2pt(87)
this.text(translations_js_1.default[this._language].account, utils.mm2pt(118), this._marginTop + utils.mm2pt(5) + 3, {
width: utils.mm2pt(87),
lineGap: 1
});
this.fontSize(10);
this.font("Helvetica");
this.text(`${utils.formatIBAN(this._data.creditor.account)}\n${this._formatAddress(this._data.creditor)}`, utils.mm2pt(118), this._marginTop + utils.mm2pt(8), {
width: utils.mm2pt(87)
this.text(`${utils.formatIBAN(this._data.creditor.account)}\n${this._formatAddress(this._data.creditor)}`, {
width: utils.mm2pt(87),
lineGap: -.75
});

@@ -330,8 +363,10 @@ this.moveDown();

this.text(translations_js_1.default[this._language].reference, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});
this.fontSize(10);
this.font("Helvetica");
this.text(this._formatReference(this._data.reference), {
width: utils.mm2pt(87)
this.text(utils.formatReference(this._data.reference), {
width: utils.mm2pt(87),
lineGap: -.75
});

@@ -345,3 +380,4 @@ this.moveDown();

this.text(translations_js_1.default[this._language].additionalInformation, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});

@@ -351,3 +387,4 @@ this.fontSize(10);

const options = {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: -.75
};

@@ -383,3 +420,4 @@ const singleLineHeight = this.heightOfString("A", options);

this.text(translations_js_1.default[this._language].payableBy, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});

@@ -389,3 +427,4 @@ this.fontSize(10);

this.text(this._formatAddress(this._data.debtor), {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: -.75
});

@@ -397,3 +436,4 @@ }

this.text(translations_js_1.default[this._language].payableByName, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});

@@ -430,12 +470,2 @@ this._addRectangle(118, utils.pt2mm(this.y), 65, 25);

}
_formatReference(reference) {
const referenceType = utils.getReferenceType(reference);
if (referenceType === "QRR") {
return utils.formatQRReference(reference);
}
else if (referenceType === "SCOR") {
return utils.formatSCORReference(reference);
}
return reference;
}
_addRectangle(x, y, width, height) {

@@ -442,0 +472,0 @@ const length = 3;

@@ -6,33 +6,117 @@ export { PDFTable, PDFRow, PDFColumn } from "../pdf/extended-pdf";

export interface Data {
/**
* The currency to be used. **3 characters.**
*/
currency: Currency;
creditor: Creditor;
debtor?: Debtor;
/**
* The amount. **Max. 12 digits.**
*/
amount?: number;
/**
* A reference number. **Max 27 characters.**
* > QR-IBAN: Maximum 27 characters. Must be filled if a QR-IBAN is used.
* Creditor Reference (ISO 11649): Maximum 25 characters.
*/
reference?: string;
/**
* A message. **Max. 140 characters.**
* > message can be used to indicate the payment purpose or for additional textual information about payments with a structured reference.
*/
message?: string;
/**
* Additional information. **Max 140 characters.**
* > Bill information contain coded information for automated booking of the payment. The data is not forwarded with the payment.
*/
additionalInformation?: string;
/**
* Alternative scheme. **Max. 100 characters.**
* > Parameter character chain of the alternative scheme according to the syntax definition in the [“Alternative scheme” section](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf)
*/
av1?: string;
/**
* Alternative scheme. **Max. 100 characters.**
* > Parameter character chain of the alternative scheme according to the syntax definition in the [“Alternative scheme” section](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf)
*/
av2?: string;
/**
* Creditor related data.
*/
creditor: Creditor;
/**
* Debtor related data.
*/
debtor?: Debtor;
}
export interface Debtor {
/**
* Name. **Max. 70 characters.**
*/
name: string;
/**
* Address. **Max 70 characters.**
*/
address: string;
/**
* Building number. **Max 16 characters.**
*/
buildingNumber?: string | number;
/**
* Postal code. **Max 16 characters.**
*/
zip: string | number;
/**
* City. **Max 35 characters.**
*/
city: string;
/**
* Country code. **2 characters.**
*/
country: string;
buildingNumber?: string | number;
}
export interface Creditor extends Debtor {
/**
* The IBAN. **21 characters.**
*/
account: string;
}
export interface PDFOptions {
/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
/**
* The page size.
* @defaultValue `"A6/5"`
*/
size?: Size;
/**
* Whether you want to show the scissors icons or the text `Separate before paying in`.
* > **Warning:** Setting **scissors** to false sets **separate** to true. To disable scissors and separate, you have to set both options to false.
* @defaultValue `true`
*/
scissors?: boolean;
/**
* Whether you want to show the text `Separate before paying in` rather than the scissors icons.
* > **Warning:** Setting **separate** to true sets **scissors** to false. To disable scissors and separate, you have to set both options to false.
* @defaultValue `false`
*/
separate?: boolean;
/**
* Whether you want render the outlines. This option may be disabled if you use perforated paper.
* @defaultValue `true`
*/
outlines?: boolean;
/**
* Whether you want to automatically finalize the PDF. When set to false you are able to add your own content to the PDF using PDFKit.
* @defaultValue `true`
*/
autoGenerate?: boolean;
}
export interface SVGOptions {
/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
}

@@ -0,14 +1,99 @@

/**
* Checks whether the given iban is a QR-IBAN or not.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the given IBAN is a QR-IBAN and `false` otherwise.
*/
export declare function isQRIBAN(iban: string): boolean;
/**
* Validates the given IBAN.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the checksum of the given IBAN is valid and `false` otherwise.
*/
export declare function isIBANValid(iban: string): boolean;
/**
* Formats the given IBAN according the specifications to be easily readable.
*
* @param iban - The IBAN to be formatted.
* @returns The formatted IBAN.
*/
export declare function formatIBAN(iban: string): string;
/**
* Checks whether the given reference is a QR-Reference or not.
*
* @param reference - The Reference to be checked.
* @returns `true` if the given reference is a QR-Reference and `false` otherwise.
*/
export declare function isQRReference(reference: string): boolean;
/**
* Validates the given reference.
*
* @param reference - The reference to be checked.
* @returns `true` if the given reference is valid and `false` otherwise.
*/
export declare function isQRReferenceValid(reference: string): boolean;
export declare function getReferenceType(reference: string | undefined): "QRR" | "SCOR" | "NON";
/**
* Calculates the checksum according the specifications.
*
* @param reference - The 26 digits long reference (without the checksum) whose checksum should be calculated.
* @returns The calculated checksum.
*/
export declare function calculateQRReferenceChecksum(reference: string): string;
/**
* Formats the given QR-Reference according the specifications to be easily readable.
*
* @param reference - The QR-Reference to be formatted.
* @returns The formatted QR-Reference.
*/
export declare function formatQRReference(reference: string): string;
/**
* Detects the type of the given reference and formats it according the specifications to be easily readable.
*
* @param reference - The reference to be formatted.
* @returns The formatted reference.
*/
export declare function formatReference(reference: string): string;
/**
* Formats the given SCOR-Reference according the specifications to be easily readable.
*
* @param reference - The SCOR-Reference to be formatted.
* @returns The formatted SCOR-Reference.
*/
export declare function formatSCORReference(reference: string): string;
/**
* Formats the given amount according the specifications to be easily readable.
*
* @param amount - containing the amount to be formatted.
* @returns The formatted amount.
*/
export declare function formatAmount(amount: number): string;
/**
* Converts milimeters to points.
*
* @param millimeters - The millimeters you want to convert to points.
* @returns The converted millimeters in points.
*/
export declare function mm2pt(millimeters: number): number;
/**
* Converts points to millimeters.
*
* @param points - The points you want to convert to millimeters.
* @returns The converted points in millimeters.
*/
export declare function pt2mm(points: number): number;
export declare function mm2pt(millimeters: number): number;
/**
* Converts milimeters to pixels.
*
* @param millimeters - The millimeters you want to convert to pixels.
* @returns The converted millimeters in pixels.
*/
export declare function mm2px(millimeters: number): number;
/**
* Converts pixels to millimeters.
*
* @param pixels - containg the pixels you want to convert to millimeters.
* @returns The converted pixels in millimeters.
*/
export declare function px2mm(pixels: number): number;
export declare function getReferenceType(reference: string | undefined): "QRR" | "SCOR" | "NON";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.px2mm = exports.mm2px = exports.mm2pt = exports.pt2mm = exports.formatAmount = exports.formatSCORReference = exports.formatQRReference = exports.calculateQRReferenceChecksum = exports.getReferenceType = exports.isQRReferenceValid = exports.isQRReference = exports.formatIBAN = exports.isIBANValid = exports.isQRIBAN = void 0;
exports.getReferenceType = exports.px2mm = exports.mm2px = exports.pt2mm = exports.mm2pt = exports.formatAmount = exports.formatSCORReference = exports.formatReference = exports.formatQRReference = exports.calculateQRReferenceChecksum = exports.isQRReferenceValid = exports.isQRReference = exports.formatIBAN = exports.isIBANValid = exports.isQRIBAN = void 0;
/**
* Checks whether the given iban is a QR-IBAN or not.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the given IBAN is a QR-IBAN and `false` otherwise.
*/
function isQRIBAN(iban) {

@@ -10,2 +16,8 @@ iban = iban.replace(/ /g, "");

exports.isQRIBAN = isQRIBAN;
/**
* Validates the given IBAN.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the checksum of the given IBAN is valid and `false` otherwise.
*/
function isIBANValid(iban) {

@@ -29,2 +41,8 @@ iban = iban.replace(/ /g, "");

exports.isIBANValid = isIBANValid;
/**
* Formats the given IBAN according the specifications to be easily readable.
*
* @param iban - The IBAN to be formatted.
* @returns The formatted IBAN.
*/
function formatIBAN(iban) {

@@ -37,2 +55,8 @@ var _a;

exports.formatIBAN = formatIBAN;
/**
* Checks whether the given reference is a QR-Reference or not.
*
* @param reference - The Reference to be checked.
* @returns `true` if the given reference is a QR-Reference and `false` otherwise.
*/
function isQRReference(reference) {

@@ -51,2 +75,8 @@ reference = reference.replace(/ /g, "");

exports.isQRReference = isQRReference;
/**
* Validates the given reference.
*
* @param reference - The reference to be checked.
* @returns `true` if the given reference is valid and `false` otherwise.
*/
function isQRReferenceValid(reference) {

@@ -66,14 +96,8 @@ reference = reference.replace(/ /g, "");

exports.isQRReferenceValid = isQRReferenceValid;
function getReferenceType(reference) {
if (typeof reference === "undefined") {
return "NON";
}
else if (isQRReference(reference)) {
return "QRR";
}
else {
return "SCOR";
}
}
exports.getReferenceType = getReferenceType;
/**
* Calculates the checksum according the specifications.
*
* @param reference - The 26 digits long reference (without the checksum) whose checksum should be calculated.
* @returns The calculated checksum.
*/
function calculateQRReferenceChecksum(reference) {

@@ -83,2 +107,8 @@ return mod10(reference);

exports.calculateQRReferenceChecksum = calculateQRReferenceChecksum;
/**
* Formats the given QR-Reference according the specifications to be easily readable.
*
* @param reference - The QR-Reference to be formatted.
* @returns The formatted QR-Reference.
*/
function formatQRReference(reference) {

@@ -94,2 +124,25 @@ reference = reference.replace(/ /g, "");

exports.formatQRReference = formatQRReference;
/**
* Detects the type of the given reference and formats it according the specifications to be easily readable.
*
* @param reference - The reference to be formatted.
* @returns The formatted reference.
*/
function formatReference(reference) {
const referenceType = getReferenceType(reference);
if (referenceType === "QRR") {
return formatQRReference(reference);
}
else if (referenceType === "SCOR") {
return formatSCORReference(reference);
}
return reference;
}
exports.formatReference = formatReference;
/**
* Formats the given SCOR-Reference according the specifications to be easily readable.
*
* @param reference - The SCOR-Reference to be formatted.
* @returns The formatted SCOR-Reference.
*/
function formatSCORReference(reference) {

@@ -105,4 +158,10 @@ reference = reference.replace(/ /g, "");

exports.formatSCORReference = formatSCORReference;
/**
* Formats the given amount according the specifications to be easily readable.
*
* @param amount - containing the amount to be formatted.
* @returns The formatted amount.
*/
function formatAmount(amount) {
const amountString = amount.toFixed(2) + "";
const amountString = amount.toFixed(2);
const amountArray = amountString.split(".");

@@ -117,5 +176,21 @@ let formattedAmountWithoutDecimals = "";

}
return formattedAmountWithoutDecimals + "." + amountArray[1];
return formattedAmountWithoutDecimals.trim() + "." + amountArray[1];
}
exports.formatAmount = formatAmount;
/**
* Converts milimeters to points.
*
* @param millimeters - The millimeters you want to convert to points.
* @returns The converted millimeters in points.
*/
function mm2pt(millimeters) {
return millimeters * 2.83465;
}
exports.mm2pt = mm2pt;
/**
* Converts points to millimeters.
*
* @param points - The points you want to convert to millimeters.
* @returns The converted points in millimeters.
*/
function pt2mm(points) {

@@ -125,6 +200,8 @@ return points / 2.83465;

exports.pt2mm = pt2mm;
function mm2pt(millimeters) {
return millimeters * 2.83465;
}
exports.mm2pt = mm2pt;
/**
* Converts milimeters to pixels.
*
* @param millimeters - The millimeters you want to convert to pixels.
* @returns The converted millimeters in pixels.
*/
function mm2px(millimeters) {

@@ -134,2 +211,8 @@ return millimeters * 960 / 254;

exports.mm2px = mm2px;
/**
* Converts pixels to millimeters.
*
* @param pixels - containg the pixels you want to convert to millimeters.
* @returns The converted pixels in millimeters.
*/
function px2mm(pixels) {

@@ -139,2 +222,14 @@ return pixels * 254 / 960;

exports.px2mm = px2mm;
function getReferenceType(reference) {
if (typeof reference === "undefined") {
return "NON";
}
else if (isQRReference(reference)) {
return "QRR";
}
else {
return "SCOR";
}
}
exports.getReferenceType = getReferenceType;
function mod9710(iban) {

@@ -141,0 +236,0 @@ let remainder = iban;

@@ -111,7 +111,7 @@ "use strict";

.x(0)
.dy("15pt")
.dy("18pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("6pt");
receiptTextContainer.addTSpan(utils.formatIBAN(this._data.reference))
receiptTextContainer.addTSpan(utils.formatReference(this._data.reference))
.x(0)

@@ -129,3 +129,3 @@ .dy("9pt")

.x(0)
.dy("15pt")
.dy("18pt")
.fontFamily("Arial")

@@ -152,8 +152,8 @@ .fontWeight("bold")

.x(0)
.dy("15pt")
.dy("18pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("6pt");
const referenceHeight = this._data.reference !== undefined ? "15pt" : "0";
this._addRectangle(5, (0, svg_engine_1.calc)(`12mm + 9pt + (${receiptLineCount} * 9pt) + ${referenceHeight} + 15pt + 1mm`, "mm"), 52, 20);
const referenceHeight = this._data.reference !== undefined ? "18pt" : "0";
this._addRectangle(5, (0, svg_engine_1.calc)(`12mm + 9pt + (${receiptLineCount} * 9pt) + ${referenceHeight} + 18pt + 1mm`, "mm"), 52, 20);
}

@@ -169,4 +169,5 @@ //-- Amount

.fontSize("6pt");
const amountXPosition = this._data.amount === undefined ? 13 : 22;
amountContainer.addTSpan(translations_js_1.default[this._language].amount)
.x("13mm")
.x(amountXPosition + "mm")
.fontFamily("Arial")

@@ -183,3 +184,3 @@ .fontWeight("bold")

amountContainer.addTSpan(utils.formatAmount(this._data.amount))
.x("13mm")
.x(amountXPosition + "mm")
.fontFamily("Arial")

@@ -223,3 +224,3 @@ .fontWeight("normal")

paymentPartMiddleTextContainer.addTSpan(translations_js_1.default[this._language].amount)
.x("20mm")
.x("22mm")
.fontFamily("Arial")

@@ -236,3 +237,3 @@ .fontWeight("bold")

paymentPartMiddleTextContainer.addTSpan(utils.formatAmount(this._data.amount))
.x("20mm")
.x("22mm")
.fontFamily("Arial")

@@ -285,3 +286,3 @@ .fontWeight("normal")

.y(0)
.dy("8pt")
.dy("11pt")
.fontFamily("Arial")

@@ -315,7 +316,7 @@ .fontWeight("bold")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("8pt");
paymentPartRightTextContainer.addTSpan(utils.formatIBAN(this._data.reference))
paymentPartRightTextContainer.addTSpan(utils.formatReference(this._data.reference))
.x(0)

@@ -332,3 +333,3 @@ .dy("11pt")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")

@@ -400,3 +401,3 @@ .fontWeight("bold")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")

@@ -422,9 +423,9 @@ .fontWeight("bold")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("8pt");
const referenceHeight = this._data.reference !== undefined ? "19pt" : "0";
const additionalInformationHeight = this._data.additionalInformation !== undefined || this._data.message !== undefined ? "19pt" : "0";
this._addRectangle(118, (0, svg_engine_1.calc)(`5mm + 8pt + (${paymentPartLineCount} * 11pt) + ${referenceHeight} + ${additionalInformationHeight} + 19pt + 1mm`, "mm"), 65, 25);
const referenceHeight = this._data.reference !== undefined ? "22pt" : "0";
const additionalInformationHeight = this._data.additionalInformation !== undefined || this._data.message !== undefined ? "22pt" : "0";
this._addRectangle(118, (0, svg_engine_1.calc)(`5mm + 11pt + (${paymentPartLineCount} * 11pt) + ${referenceHeight} + ${additionalInformationHeight} + 22pt + 1mm`, "mm"), 65, 25);
}

@@ -431,0 +432,0 @@ }

import PDFDocument from "pdfkit";
export interface PDFTable {
/**
* Table rows.
*/
rows: Array<PDFRow>;
/**
* Width of whole table.
*/
width?: number;
/**
* Horizontal start position of the table.
*/
x?: number;
/**
* Vertical start position of the table.
*/
y?: number;
/**
* Cell padding of the table cells.
*/
padding?: number | [number, number?, number?, number?];
/**
* Width of the border lines.
*/
lineWidth?: number;
/**
* Font of the text inside the table.
*/
font?: string;
/**
* Font size of the text inside the table.
*/
fontSize?: number;
}
export interface PDFRow {
/**
* Table columns.
*/
columns: Array<PDFColumn>;
/**
* Background color of the row.
*/
fillColor?: string;
/**
* Border color of the row.
*/
strokeColor?: string;
/**
* Height of the row.
*/
height?: number;
/**
* Cell padding of the table cells inside the row.
*/
padding?: number | [number, number?, number?, number?];
/**
* Font of the text inside the row.
*/
font?: string;
/**
* Font size of the text inside the row.
*/
fontSize?: number;
/**
* A header row gets inserted automatically on new pages. Only one header row is allowed.
*/
header?: boolean;
}
export interface PDFColumn {
/**
* Cell text.
*/
text: string | number | boolean;
/**
* Width of the cell.
*/
width?: number;
/**
* Cell padding of the table cell.
*/
padding?: number | [number, number?, number?, number?];
/**
* Background color of the cell.
*/
fillColor?: string;
/**
* Border color of the cell.
*/
strokeColor?: string;
/**
* Font of the text inside the cell.
*/
font?: string;
/**
* Font size of the text inside the cell.
*/
fontSize?: number;
/**
* Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling).
*/
textOptions?: PDFKit.Mixins.TextOptions;

@@ -34,4 +106,47 @@ }

constructor(options?: PDFKit.PDFDocumentOptions);
/**
* Inserts a table to the document.
*
* @param table - An Object which contains the table information.
* @returns `this`
* @example
* ```
* const table = {
* rows: [
* {
* fillColor: "#ECF0F1",
* columns: [
* {
* text: "Row 1 cell 1",
* }, {
* text: "Row 1 cell 2",
* }, {
* text: "Row 1 cell 3"
* }
* ]
* }, {
* columns: [
* {
* text: "Row 2 cell 1",
* }, {
* text: "Row 2 cell 2",
* }, {
* text: "Row 2 cell 3"
* }
* ]
* }
* ]
* };
* ```
*/
addTable(table: PDFTable): PDFKit.PDFDocument;
/**
* Adds a path to the document on the given position.
*
* @param path - The path data to insert. This is the same as the `d` attribute of a SVG path.
* @param x - The x position where the path should be inserted.
* @param y - The y position where the path should be inserted.
* @returns `this`
*/
addPath(path: string, x: number, y: number): PDFKit.PDFDocument;
}

@@ -7,2 +7,37 @@ import PDFDocument from "pdfkit";

}
/**
* Inserts a table to the document.
*
* @param table - An Object which contains the table information.
* @returns `this`
* @example
* ```
* const table = {
* rows: [
* {
* fillColor: "#ECF0F1",
* columns: [
* {
* text: "Row 1 cell 1",
* }, {
* text: "Row 1 cell 2",
* }, {
* text: "Row 1 cell 3"
* }
* ]
* }, {
* columns: [
* {
* text: "Row 2 cell 1",
* }, {
* text: "Row 2 cell 2",
* }, {
* text: "Row 2 cell 3"
* }
* ]
* }
* ]
* };
* ```
*/
addTable(table) {

@@ -134,2 +169,10 @@ if (table.rows === undefined) {

}
/**
* Adds a path to the document on the given position.
*
* @param path - The path data to insert. This is the same as the `d` attribute of a SVG path.
* @param x - The x position where the path should be inserted.
* @param y - The y position where the path should be inserted.
* @returns `this`
*/
addPath(path, x, y) {

@@ -136,0 +179,0 @@ path = svgpath(path)

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

constructor(data: Data, options?: PDFOptions);
/**
* Adds a new page to the PDF. This method is basically the same as the original [PDFKit `addPage()` method](https://pdfkit.org/docs/getting_started.html#adding_pages). However the default values are changed to use the default page size provided in the constructor options.
* @param options - An object containing [PDFKit document options.](https://pdfkit.org/docs/getting_started.html#adding_pages)
* @returns `this`
*/
addPage(options?: PDFKit.PDFDocumentOptions): PDFKit.PDFDocument;
end(): void;
/**
* Adds the QR Slip to the bottom of the current page if there is enough space, otherwise it will create a new page with the specified size and add it to the bottom of this page.
*
* @param size - The size of the new page if not enough space is left for the QR slip.
*/
addQRBill(size?: Size): void;

@@ -21,4 +31,3 @@ private _render;

private _formatAddress;
private _formatReference;
private _addRectangle;
}

@@ -55,2 +55,7 @@ import { ExtendedPDF } from "./extended-pdf.js";

}
/**
* Adds a new page to the PDF. This method is basically the same as the original [PDFKit `addPage()` method](https://pdfkit.org/docs/getting_started.html#adding_pages). However the default values are changed to use the default page size provided in the constructor options.
* @param options - An object containing [PDFKit document options.](https://pdfkit.org/docs/getting_started.html#adding_pages)
* @returns `this`
*/
addPage(options) {

@@ -70,2 +75,7 @@ if (options === undefined) {

}
/**
* Adds the QR Slip to the bottom of the current page if there is enough space, otherwise it will create a new page with the specified size and add it to the bottom of this page.
*
* @param size - The size of the new page if not enough space is left for the QR slip.
*/
addQRBill(size = "A6/5") {

@@ -138,4 +148,5 @@ if (this.page.height - this.y < utils.mm2pt(105) && this.y !== this.page.margins.top) {

this.font("Helvetica-Bold");
this.text(translations[this._language].account, utils.mm2pt(5), this._marginTop + utils.mm2pt(12), {
width: utils.mm2pt(52)
this.text(translations[this._language].account, utils.mm2pt(5), this._marginTop + utils.mm2pt(12) + 3, {
width: utils.mm2pt(52),
lineGap: 1
});

@@ -146,3 +157,4 @@ //-- Creditor

this.text(`${utils.formatIBAN(this._data.creditor.account)}\n${this._formatAddress(this._data.creditor)}`, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: -.5
});

@@ -155,8 +167,10 @@ this.moveDown();

this.text(translations[this._language].reference, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: 1
});
this.fontSize(8);
this.font("Helvetica");
this.text(this._formatReference(this._data.reference), {
width: utils.mm2pt(52)
this.text(utils.formatReference(this._data.reference), {
width: utils.mm2pt(52),
lineGap: -.5
});

@@ -171,3 +185,4 @@ }

this.text(translations[this._language].payableBy, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: 1
});

@@ -177,3 +192,4 @@ this.fontSize(8);

this.text(this._formatAddress(this._data.debtor), {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: -.5
});

@@ -187,3 +203,4 @@ }

this.text(translations[this._language].payableByName, {
width: utils.mm2pt(52)
width: utils.mm2pt(52),
lineGap: 1
});

@@ -197,6 +214,9 @@ //-- Add rectangle

this.text(translations[this._language].currency, utils.mm2pt(5), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});
this.text(translations[this._language].amount, utils.mm2pt(18), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(37)
const amountXPosition = this._data.amount === undefined ? 18 : 27;
this.text(translations[this._language].amount, utils.mm2pt(amountXPosition), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(52 - amountXPosition),
lineGap: 1
});

@@ -206,7 +226,9 @@ this.fontSize(8);

this.text(this._data.currency, utils.mm2pt(5), this._marginTop + utils.mm2pt(71), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: -.5
});
if (this._data.amount !== undefined) {
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(18), this._marginTop + utils.mm2pt(71), {
width: utils.mm2pt(37)
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(amountXPosition), this._marginTop + utils.mm2pt(71), {
width: utils.mm2pt(52 - amountXPosition),
lineGap: -.5
});

@@ -221,3 +243,4 @@ }

width: utils.mm2pt(52),
align: "right"
align: "right",
lineGap: 1
});

@@ -229,3 +252,4 @@ //-- Payment part middle container

width: utils.mm2pt(51),
align: "left"
align: "left",
lineGap: 1
});

@@ -239,6 +263,7 @@ //-- QR Code

this.text(translations[this._language].currency, utils.mm2pt(67), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});
this.text(translations[this._language].amount, utils.mm2pt(87), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(36)
this.text(translations[this._language].amount, utils.mm2pt(89), this._marginTop + utils.mm2pt(68), {
width: utils.mm2pt(29)
});

@@ -248,7 +273,9 @@ this.fontSize(10);

this.text(this._data.currency, utils.mm2pt(67), this._marginTop + utils.mm2pt(72), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: -.5
});
if (this._data.amount !== undefined) {
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(87), this._marginTop + utils.mm2pt(72), {
width: utils.mm2pt(36)
this.text(utils.formatAmount(this._data.amount), utils.mm2pt(89), this._marginTop + utils.mm2pt(72), {
width: utils.mm2pt(29),
lineGap: -.5
});

@@ -264,3 +291,4 @@ }

this.text("Name AV1:", utils.mm2pt(67), this._marginTop + utils.mm2pt(90), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});

@@ -270,3 +298,4 @@ this.fontSize(7);

this.text((this._data.av1.length > 87 ? this._data.av1.substr(0, 87) + "..." : this._data.av1), utils.mm2pt(81), this._marginTop + utils.mm2pt(90), {
width: utils.mm2pt(37)
width: utils.mm2pt(37),
lineGap: -.5
});

@@ -278,3 +307,4 @@ }

this.text("Name AV2:", utils.mm2pt(67), this._marginTop + utils.mm2pt(93), {
width: utils.mm2pt(15)
width: utils.mm2pt(15),
lineGap: 1
});

@@ -284,3 +314,4 @@ this.fontSize(7);

this.text((this._data.av2.length > 87 ? this._data.av2.substr(0, 87) + "..." : this._data.av2), utils.mm2pt(81), this._marginTop + utils.mm2pt(93), {
width: utils.mm2pt(37)
width: utils.mm2pt(37),
lineGap: -.5
});

@@ -291,9 +322,11 @@ }

this.font("Helvetica-Bold");
this.text(translations[this._language].account, utils.mm2pt(118), this._marginTop + utils.mm2pt(5), {
width: utils.mm2pt(87)
this.text(translations[this._language].account, utils.mm2pt(118), this._marginTop + utils.mm2pt(5) + 3, {
width: utils.mm2pt(87),
lineGap: 1
});
this.fontSize(10);
this.font("Helvetica");
this.text(`${utils.formatIBAN(this._data.creditor.account)}\n${this._formatAddress(this._data.creditor)}`, utils.mm2pt(118), this._marginTop + utils.mm2pt(8), {
width: utils.mm2pt(87)
this.text(`${utils.formatIBAN(this._data.creditor.account)}\n${this._formatAddress(this._data.creditor)}`, {
width: utils.mm2pt(87),
lineGap: -.75
});

@@ -305,8 +338,10 @@ this.moveDown();

this.text(translations[this._language].reference, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});
this.fontSize(10);
this.font("Helvetica");
this.text(this._formatReference(this._data.reference), {
width: utils.mm2pt(87)
this.text(utils.formatReference(this._data.reference), {
width: utils.mm2pt(87),
lineGap: -.75
});

@@ -320,3 +355,4 @@ this.moveDown();

this.text(translations[this._language].additionalInformation, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});

@@ -326,3 +362,4 @@ this.fontSize(10);

const options = {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: -.75
};

@@ -358,3 +395,4 @@ const singleLineHeight = this.heightOfString("A", options);

this.text(translations[this._language].payableBy, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});

@@ -364,3 +402,4 @@ this.fontSize(10);

this.text(this._formatAddress(this._data.debtor), {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: -.75
});

@@ -372,3 +411,4 @@ }

this.text(translations[this._language].payableByName, {
width: utils.mm2pt(87)
width: utils.mm2pt(87),
lineGap: 1
});

@@ -405,12 +445,2 @@ this._addRectangle(118, utils.pt2mm(this.y), 65, 25);

}
_formatReference(reference) {
const referenceType = utils.getReferenceType(reference);
if (referenceType === "QRR") {
return utils.formatQRReference(reference);
}
else if (referenceType === "SCOR") {
return utils.formatSCORReference(reference);
}
return reference;
}
_addRectangle(x, y, width, height) {

@@ -417,0 +447,0 @@ const length = 3;

@@ -6,33 +6,117 @@ export { PDFTable, PDFRow, PDFColumn } from "../pdf/extended-pdf";

export interface Data {
/**
* The currency to be used. **3 characters.**
*/
currency: Currency;
creditor: Creditor;
debtor?: Debtor;
/**
* The amount. **Max. 12 digits.**
*/
amount?: number;
/**
* A reference number. **Max 27 characters.**
* > QR-IBAN: Maximum 27 characters. Must be filled if a QR-IBAN is used.
* Creditor Reference (ISO 11649): Maximum 25 characters.
*/
reference?: string;
/**
* A message. **Max. 140 characters.**
* > message can be used to indicate the payment purpose or for additional textual information about payments with a structured reference.
*/
message?: string;
/**
* Additional information. **Max 140 characters.**
* > Bill information contain coded information for automated booking of the payment. The data is not forwarded with the payment.
*/
additionalInformation?: string;
/**
* Alternative scheme. **Max. 100 characters.**
* > Parameter character chain of the alternative scheme according to the syntax definition in the [“Alternative scheme” section](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf)
*/
av1?: string;
/**
* Alternative scheme. **Max. 100 characters.**
* > Parameter character chain of the alternative scheme according to the syntax definition in the [“Alternative scheme” section](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf)
*/
av2?: string;
/**
* Creditor related data.
*/
creditor: Creditor;
/**
* Debtor related data.
*/
debtor?: Debtor;
}
export interface Debtor {
/**
* Name. **Max. 70 characters.**
*/
name: string;
/**
* Address. **Max 70 characters.**
*/
address: string;
/**
* Building number. **Max 16 characters.**
*/
buildingNumber?: string | number;
/**
* Postal code. **Max 16 characters.**
*/
zip: string | number;
/**
* City. **Max 35 characters.**
*/
city: string;
/**
* Country code. **2 characters.**
*/
country: string;
buildingNumber?: string | number;
}
export interface Creditor extends Debtor {
/**
* The IBAN. **21 characters.**
*/
account: string;
}
export interface PDFOptions {
/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
/**
* The page size.
* @defaultValue `"A6/5"`
*/
size?: Size;
/**
* Whether you want to show the scissors icons or the text `Separate before paying in`.
* > **Warning:** Setting **scissors** to false sets **separate** to true. To disable scissors and separate, you have to set both options to false.
* @defaultValue `true`
*/
scissors?: boolean;
/**
* Whether you want to show the text `Separate before paying in` rather than the scissors icons.
* > **Warning:** Setting **separate** to true sets **scissors** to false. To disable scissors and separate, you have to set both options to false.
* @defaultValue `false`
*/
separate?: boolean;
/**
* Whether you want render the outlines. This option may be disabled if you use perforated paper.
* @defaultValue `true`
*/
outlines?: boolean;
/**
* Whether you want to automatically finalize the PDF. When set to false you are able to add your own content to the PDF using PDFKit.
* @defaultValue `true`
*/
autoGenerate?: boolean;
}
export interface SVGOptions {
/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
}

@@ -0,14 +1,99 @@

/**
* Checks whether the given iban is a QR-IBAN or not.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the given IBAN is a QR-IBAN and `false` otherwise.
*/
export declare function isQRIBAN(iban: string): boolean;
/**
* Validates the given IBAN.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the checksum of the given IBAN is valid and `false` otherwise.
*/
export declare function isIBANValid(iban: string): boolean;
/**
* Formats the given IBAN according the specifications to be easily readable.
*
* @param iban - The IBAN to be formatted.
* @returns The formatted IBAN.
*/
export declare function formatIBAN(iban: string): string;
/**
* Checks whether the given reference is a QR-Reference or not.
*
* @param reference - The Reference to be checked.
* @returns `true` if the given reference is a QR-Reference and `false` otherwise.
*/
export declare function isQRReference(reference: string): boolean;
/**
* Validates the given reference.
*
* @param reference - The reference to be checked.
* @returns `true` if the given reference is valid and `false` otherwise.
*/
export declare function isQRReferenceValid(reference: string): boolean;
export declare function getReferenceType(reference: string | undefined): "QRR" | "SCOR" | "NON";
/**
* Calculates the checksum according the specifications.
*
* @param reference - The 26 digits long reference (without the checksum) whose checksum should be calculated.
* @returns The calculated checksum.
*/
export declare function calculateQRReferenceChecksum(reference: string): string;
/**
* Formats the given QR-Reference according the specifications to be easily readable.
*
* @param reference - The QR-Reference to be formatted.
* @returns The formatted QR-Reference.
*/
export declare function formatQRReference(reference: string): string;
/**
* Detects the type of the given reference and formats it according the specifications to be easily readable.
*
* @param reference - The reference to be formatted.
* @returns The formatted reference.
*/
export declare function formatReference(reference: string): string;
/**
* Formats the given SCOR-Reference according the specifications to be easily readable.
*
* @param reference - The SCOR-Reference to be formatted.
* @returns The formatted SCOR-Reference.
*/
export declare function formatSCORReference(reference: string): string;
/**
* Formats the given amount according the specifications to be easily readable.
*
* @param amount - containing the amount to be formatted.
* @returns The formatted amount.
*/
export declare function formatAmount(amount: number): string;
/**
* Converts milimeters to points.
*
* @param millimeters - The millimeters you want to convert to points.
* @returns The converted millimeters in points.
*/
export declare function mm2pt(millimeters: number): number;
/**
* Converts points to millimeters.
*
* @param points - The points you want to convert to millimeters.
* @returns The converted points in millimeters.
*/
export declare function pt2mm(points: number): number;
export declare function mm2pt(millimeters: number): number;
/**
* Converts milimeters to pixels.
*
* @param millimeters - The millimeters you want to convert to pixels.
* @returns The converted millimeters in pixels.
*/
export declare function mm2px(millimeters: number): number;
/**
* Converts pixels to millimeters.
*
* @param pixels - containg the pixels you want to convert to millimeters.
* @returns The converted pixels in millimeters.
*/
export declare function px2mm(pixels: number): number;
export declare function getReferenceType(reference: string | undefined): "QRR" | "SCOR" | "NON";

@@ -0,1 +1,7 @@

/**
* Checks whether the given iban is a QR-IBAN or not.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the given IBAN is a QR-IBAN and `false` otherwise.
*/
export function isQRIBAN(iban) {

@@ -6,2 +12,8 @@ iban = iban.replace(/ /g, "");

}
/**
* Validates the given IBAN.
*
* @param iban - The IBAN to be checked.
* @returns `true` if the checksum of the given IBAN is valid and `false` otherwise.
*/
export function isIBANValid(iban) {

@@ -24,2 +36,8 @@ iban = iban.replace(/ /g, "");

}
/**
* Formats the given IBAN according the specifications to be easily readable.
*
* @param iban - The IBAN to be formatted.
* @returns The formatted IBAN.
*/
export function formatIBAN(iban) {

@@ -31,2 +49,8 @@ var _a;

}
/**
* Checks whether the given reference is a QR-Reference or not.
*
* @param reference - The Reference to be checked.
* @returns `true` if the given reference is a QR-Reference and `false` otherwise.
*/
export function isQRReference(reference) {

@@ -44,2 +68,8 @@ reference = reference.replace(/ /g, "");

}
/**
* Validates the given reference.
*
* @param reference - The reference to be checked.
* @returns `true` if the given reference is valid and `false` otherwise.
*/
export function isQRReferenceValid(reference) {

@@ -58,16 +88,17 @@ reference = reference.replace(/ /g, "");

}
export function getReferenceType(reference) {
if (typeof reference === "undefined") {
return "NON";
}
else if (isQRReference(reference)) {
return "QRR";
}
else {
return "SCOR";
}
}
/**
* Calculates the checksum according the specifications.
*
* @param reference - The 26 digits long reference (without the checksum) whose checksum should be calculated.
* @returns The calculated checksum.
*/
export function calculateQRReferenceChecksum(reference) {
return mod10(reference);
}
/**
* Formats the given QR-Reference according the specifications to be easily readable.
*
* @param reference - The QR-Reference to be formatted.
* @returns The formatted QR-Reference.
*/
export function formatQRReference(reference) {

@@ -82,2 +113,24 @@ reference = reference.replace(/ /g, "");

}
/**
* Detects the type of the given reference and formats it according the specifications to be easily readable.
*
* @param reference - The reference to be formatted.
* @returns The formatted reference.
*/
export function formatReference(reference) {
const referenceType = getReferenceType(reference);
if (referenceType === "QRR") {
return formatQRReference(reference);
}
else if (referenceType === "SCOR") {
return formatSCORReference(reference);
}
return reference;
}
/**
* Formats the given SCOR-Reference according the specifications to be easily readable.
*
* @param reference - The SCOR-Reference to be formatted.
* @returns The formatted SCOR-Reference.
*/
export function formatSCORReference(reference) {

@@ -92,4 +145,10 @@ reference = reference.replace(/ /g, "");

}
/**
* Formats the given amount according the specifications to be easily readable.
*
* @param amount - containing the amount to be formatted.
* @returns The formatted amount.
*/
export function formatAmount(amount) {
const amountString = amount.toFixed(2) + "";
const amountString = amount.toFixed(2);
const amountArray = amountString.split(".");

@@ -104,16 +163,51 @@ let formattedAmountWithoutDecimals = "";

}
return formattedAmountWithoutDecimals + "." + amountArray[1];
return formattedAmountWithoutDecimals.trim() + "." + amountArray[1];
}
/**
* Converts milimeters to points.
*
* @param millimeters - The millimeters you want to convert to points.
* @returns The converted millimeters in points.
*/
export function mm2pt(millimeters) {
return millimeters * 2.83465;
}
/**
* Converts points to millimeters.
*
* @param points - The points you want to convert to millimeters.
* @returns The converted points in millimeters.
*/
export function pt2mm(points) {
return points / 2.83465;
}
export function mm2pt(millimeters) {
return millimeters * 2.83465;
}
/**
* Converts milimeters to pixels.
*
* @param millimeters - The millimeters you want to convert to pixels.
* @returns The converted millimeters in pixels.
*/
export function mm2px(millimeters) {
return millimeters * 960 / 254;
}
/**
* Converts pixels to millimeters.
*
* @param pixels - containg the pixels you want to convert to millimeters.
* @returns The converted pixels in millimeters.
*/
export function px2mm(pixels) {
return pixels * 254 / 960;
}
export function getReferenceType(reference) {
if (typeof reference === "undefined") {
return "NON";
}
else if (isQRReference(reference)) {
return "QRR";
}
else {
return "SCOR";
}
}
function mod9710(iban) {

@@ -120,0 +214,0 @@ let remainder = iban;

@@ -86,7 +86,7 @@ import { validateData, cleanData } from "../shared/shared.js";

.x(0)
.dy("15pt")
.dy("18pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("6pt");
receiptTextContainer.addTSpan(utils.formatIBAN(this._data.reference))
receiptTextContainer.addTSpan(utils.formatReference(this._data.reference))
.x(0)

@@ -104,3 +104,3 @@ .dy("9pt")

.x(0)
.dy("15pt")
.dy("18pt")
.fontFamily("Arial")

@@ -127,8 +127,8 @@ .fontWeight("bold")

.x(0)
.dy("15pt")
.dy("18pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("6pt");
const referenceHeight = this._data.reference !== undefined ? "15pt" : "0";
this._addRectangle(5, calc(`12mm + 9pt + (${receiptLineCount} * 9pt) + ${referenceHeight} + 15pt + 1mm`, "mm"), 52, 20);
const referenceHeight = this._data.reference !== undefined ? "18pt" : "0";
this._addRectangle(5, calc(`12mm + 9pt + (${receiptLineCount} * 9pt) + ${referenceHeight} + 18pt + 1mm`, "mm"), 52, 20);
}

@@ -144,4 +144,5 @@ //-- Amount

.fontSize("6pt");
const amountXPosition = this._data.amount === undefined ? 13 : 22;
amountContainer.addTSpan(translations[this._language].amount)
.x("13mm")
.x(amountXPosition + "mm")
.fontFamily("Arial")

@@ -158,3 +159,3 @@ .fontWeight("bold")

amountContainer.addTSpan(utils.formatAmount(this._data.amount))
.x("13mm")
.x(amountXPosition + "mm")
.fontFamily("Arial")

@@ -198,3 +199,3 @@ .fontWeight("normal")

paymentPartMiddleTextContainer.addTSpan(translations[this._language].amount)
.x("20mm")
.x("22mm")
.fontFamily("Arial")

@@ -211,3 +212,3 @@ .fontWeight("bold")

paymentPartMiddleTextContainer.addTSpan(utils.formatAmount(this._data.amount))
.x("20mm")
.x("22mm")
.fontFamily("Arial")

@@ -260,3 +261,3 @@ .fontWeight("normal")

.y(0)
.dy("8pt")
.dy("11pt")
.fontFamily("Arial")

@@ -290,7 +291,7 @@ .fontWeight("bold")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("8pt");
paymentPartRightTextContainer.addTSpan(utils.formatIBAN(this._data.reference))
paymentPartRightTextContainer.addTSpan(utils.formatReference(this._data.reference))
.x(0)

@@ -307,3 +308,3 @@ .dy("11pt")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")

@@ -375,3 +376,3 @@ .fontWeight("bold")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")

@@ -397,9 +398,9 @@ .fontWeight("bold")

.x(0)
.dy("19pt")
.dy("22pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("8pt");
const referenceHeight = this._data.reference !== undefined ? "19pt" : "0";
const additionalInformationHeight = this._data.additionalInformation !== undefined || this._data.message !== undefined ? "19pt" : "0";
this._addRectangle(118, calc(`5mm + 8pt + (${paymentPartLineCount} * 11pt) + ${referenceHeight} + ${additionalInformationHeight} + 19pt + 1mm`, "mm"), 65, 25);
const referenceHeight = this._data.reference !== undefined ? "22pt" : "0";
const additionalInformationHeight = this._data.additionalInformation !== undefined || this._data.message !== undefined ? "22pt" : "0";
this._addRectangle(118, calc(`5mm + 11pt + (${paymentPartLineCount} * 11pt) + ${referenceHeight} + ${additionalInformationHeight} + 22pt + 1mm`, "mm"), 65, 25);
}

@@ -406,0 +407,0 @@ }

{
"name": "swissqrbill",
"version": "3.0.1",
"version": "3.1.0",
"description": "Swiss QR Bill generation in Node.js and browsers",

@@ -153,8 +153,8 @@ "main": "./lib/node/cjs/node/index.js",

"@types/blob-stream": "^0.1.30",
"@types/node": "^16.10.9",
"@types/node": "^16.11.7",
"@types/qrcode": "^1.4.1",
"@types/qrcode-svg": "^1.1.1",
"@types/svg-parser": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^5.3.1",
"@typescript-eslint/parser": "^5.3.1",
"assert": "^2.0.0",

@@ -164,3 +164,3 @@ "brfs": "^2.0.2",

"buffer": "^6.0.3",
"eslint": "^8.0.1",
"eslint": "^8.2.0",
"process": "^0.11.10",

@@ -172,13 +172,13 @@ "readable-stream": "^3.6.0",

"util": "^0.12.4",
"webpack": "^5.58.2",
"webpack-cli": "^4.9.0"
"webpack": "^5.64.0",
"webpack-cli": "^4.9.1"
},
"dependencies": {
"@schoero/qrcode": "^1.4.5",
"@types/pdfkit": "^0.11.2",
"@types/pdfkit": "^0.12.3",
"blob-stream": "^0.1.3",
"pdfkit": "^0.12.3",
"svg-engine": "^0.2.2",
"pdfkit": "^0.13.0",
"svg-engine": "^0.2.3",
"svgpath": "^2.3.1"
}
}

@@ -116,4 +116,4 @@ <div align="center">

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.
Unfortunately, The [current version of TypeScript](https://github.com/microsoft/TypeScript/issues/46452) 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.

@@ -133,3 +133,3 @@ ```js

```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/swissqrbill/lib/browser/bundle/index.min.js" />
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/swissqrbill/lib/browser/bundle/index.js" />
```

@@ -136,0 +136,0 @@

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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