swissqrbill
Advanced tools
Comparing version 4.0.2 to 4.1.0
@@ -1,3 +0,3 @@ | ||
export * from "./swissqrbill.js"; | ||
export * from "./swissqrcode.js"; | ||
export * from "./table.js"; | ||
export * from './swissqrbill.js'; | ||
export * from './swissqrcode.js'; | ||
export * from './table.js'; |
@@ -1,6 +0,6 @@ | ||
/// <reference types="pdfkit" /> | ||
import type { Data, PDFOptions } from '../shared/types.js'; | ||
import { Data, PDFOptions } from '../shared/types.js'; | ||
/** | ||
* The SwissQRBill class creates the Payment Part with the QR Code. It can be attached to any PDFKit document instance | ||
* using the {@link SwissQRBill.attachTo} method. | ||
* | ||
* @example | ||
@@ -52,2 +52,3 @@ * ```ts | ||
* Creates a new SwissQRBill instance. | ||
* | ||
* @param data The data to be used for the QR Bill. | ||
@@ -61,3 +62,4 @@ * @param options Options to define how the QR Bill should be rendered. | ||
* enough space is left on the current page. | ||
* @param doc The PDFKit instance | ||
* | ||
* @param doc The PDFKit instance. | ||
* @param x The horizontal position in points where the QR Bill will be placed. | ||
@@ -69,3 +71,4 @@ * @param y The vertical position in points where the QR Bill will be placed. | ||
* Checks whether there is enough space on the current page to add the QR Bill. | ||
* @param doc The PDFKit document instance | ||
* | ||
* @param doc The PDFKit document instance. | ||
* @param xPosition The horizontal position where the QR Bill will be placed. | ||
@@ -72,0 +75,0 @@ * @param yPosition The vertical position where the QR Bill will be placed. |
@@ -1,3 +0,2 @@ | ||
/// <reference types="pdfkit" /> | ||
import type { Data } from '../shared/types.js'; | ||
import { Data } from '../shared/types.js'; | ||
export declare class SwissQRCode { | ||
@@ -8,2 +7,3 @@ private size; | ||
* Creates a Swiss QR Code. | ||
* | ||
* @param data The data to be encoded in the QR code. | ||
@@ -16,2 +16,3 @@ * @param size The size of the QR code in mm. | ||
* Attaches the Swiss QR Code to a PDF document. | ||
* | ||
* @param doc The PDF document to attach the Swiss QR Code to. | ||
@@ -18,0 +19,0 @@ * @param x The horizontal position in points where the Swiss QR Code will be placed. |
@@ -1,10 +0,9 @@ | ||
/// <reference types="pdfkit" /> | ||
export interface PDFTable { | ||
/** Table rows. */ | ||
rows: PDFRow[]; | ||
/** Horizontal alignment of texts inside the table */ | ||
/** Horizontal alignment of texts inside the table. */ | ||
align?: "center" | "left" | "right"; | ||
/** Background color of the table. */ | ||
backgroundColor?: string; | ||
/** The colors of the border */ | ||
/** The colors of the border. */ | ||
borderColor?: PDFBorderColor; | ||
@@ -23,3 +22,3 @@ /** Width of the borders of the row. */ | ||
textOptions?: PDFKit.Mixins.TextOptions; | ||
/** Vertical alignment of texts inside the table */ | ||
/** Vertical alignment of texts inside the table. */ | ||
verticalAlign?: "bottom" | "center" | "top"; | ||
@@ -32,7 +31,7 @@ /** Width of whole table. */ | ||
columns: PDFColumn[]; | ||
/** Horizontal alignment of texts inside the row */ | ||
/** Horizontal alignment of texts inside the row. */ | ||
align?: "center" | "left" | "right"; | ||
/** Background color of the row. */ | ||
backgroundColor?: string; | ||
/** The colors of the border */ | ||
/** The colors of the border. */ | ||
borderColor?: PDFBorderColor; | ||
@@ -47,7 +46,7 @@ /** Width of the borders of the row. */ | ||
header?: boolean; | ||
/** Height of the row. Overrides minHeight and maxHeight */ | ||
/** Height of the row. Overrides minHeight and maxHeight. */ | ||
height?: number; | ||
/** Maximum height of the row */ | ||
/** Maximum height of the row. */ | ||
maxHeight?: number; | ||
/** Minimum height of the row */ | ||
/** Minimum height of the row. */ | ||
minHeight?: number; | ||
@@ -60,3 +59,3 @@ /** Cell padding of the table cells inside the row. */ | ||
textOptions?: PDFKit.Mixins.TextOptions; | ||
/** Vertical alignment of texts inside the row */ | ||
/** Vertical alignment of texts inside the row. */ | ||
verticalAlign?: "bottom" | "center" | "top"; | ||
@@ -67,7 +66,7 @@ } | ||
text: boolean | number | string; | ||
/** Horizontal alignment of the text inside the cell */ | ||
/** Horizontal alignment of the text inside the cell. */ | ||
align?: "center" | "left" | "right"; | ||
/** Background color of the cell. */ | ||
backgroundColor?: string; | ||
/** The colors of the border */ | ||
/** The colors of the border. */ | ||
borderColor?: PDFBorderColor; | ||
@@ -86,3 +85,3 @@ /** Width of the borders of the row. */ | ||
textOptions?: PDFKit.Mixins.TextOptions; | ||
/** Vertical alignment of the text inside the cell */ | ||
/** Vertical alignment of the text inside the cell. */ | ||
verticalAlign?: "bottom" | "center" | "top"; | ||
@@ -101,2 +100,3 @@ /** Width of the cell. */ | ||
* using the {@link Table.attachTo} method. | ||
* | ||
* @example | ||
@@ -144,2 +144,3 @@ * ```ts | ||
* Creates a new Table instance. | ||
* | ||
* @param data The rows and columns for the table. | ||
@@ -153,3 +154,4 @@ * @returns The Table instance. | ||
* every row that no longer fits on a page. | ||
* @param doc The PDFKit document instance | ||
* | ||
* @param doc The PDFKit document instance. | ||
* @param x The horizontal position in points where the table be placed. | ||
@@ -156,0 +158,0 @@ * @param y The vertical position in points where the table will be placed. |
@@ -1,4 +0,4 @@ | ||
import type { Data } from './types.js'; | ||
import { Data } from './types.js'; | ||
export declare function cleanData(data: Data): Data; | ||
export declare function removeSpaces(text: string): string; | ||
export declare function removeLineBreaks(text: string): string; |
@@ -0,9 +1,6 @@ | ||
/** A {@link ValidationError} is thrown when the data provided to swissqrbill is invalid. */ | ||
export declare class ValidationError extends Error { | ||
constructor(message: string, params?: { | ||
[name: string]: string; | ||
}); | ||
/** A stable error code that can be used to identify the error programmatically. */ | ||
code: keyof typeof ValidationErrors; | ||
} | ||
export declare function resolveMessageParams(message: string, params: { | ||
[name: string]: string; | ||
}): string; | ||
export declare enum ValidationErrors { | ||
@@ -10,0 +7,0 @@ ACCOUNT_IS_QR_IBAN_BUT_REFERENCE_IS_MISSING = "If there is no reference, a conventional IBAN must be used.", |
@@ -1,4 +0,4 @@ | ||
import type { Data } from "swissqrbill:shared:types.js"; | ||
import { Data } from './types.js'; | ||
export declare function generateQRData(data: Data): string; | ||
export declare function renderQRCode(data: Data, size: number, renderBlockFunction: (x: number, y: number, blockSize: number) => void): void; | ||
export declare function renderSwissCross(size: number, renderRectFunction: (x: number, y: number, width: number, height: number, fillColor: string) => void): void; |
@@ -7,7 +7,7 @@ export interface Data { | ||
/** | ||
* The currency to be used. **3 characters.** | ||
* The currency to be used. **3 characters.**. | ||
*/ | ||
currency: "CHF" | "EUR"; | ||
/** | ||
* Additional information. **Max 140 characters.** | ||
* Additional information. **Max 140 characters.**. | ||
* | ||
@@ -18,15 +18,15 @@ * Bill information contain coded information for automated booking of the payment. The data is not forwarded with the payment. | ||
/** | ||
* The amount. **Max. 12 digits.** | ||
* The amount. **Max. 12 digits.**. | ||
*/ | ||
amount?: number; | ||
/** | ||
* Alternative scheme. **Max. 100 characters.** | ||
* 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) | ||
* 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.** | ||
* 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) | ||
* 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). | ||
*/ | ||
@@ -39,9 +39,9 @@ av2?: string; | ||
/** | ||
* A message. **Max. 140 characters.** | ||
* 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 can be used to indicate the payment purpose or for additional textual information about payments with a structured reference. | ||
*/ | ||
message?: string; | ||
/** | ||
* A reference number. **Max 27 characters.** | ||
* A reference number. **Max 27 characters.**. | ||
* | ||
@@ -55,23 +55,23 @@ * QR-IBAN: Maximum 27 characters. Must be filled if a QR-IBAN is used. | ||
/** | ||
* Address. **Max 70 characters.** | ||
* Address. **Max 70 characters.**. | ||
*/ | ||
address: string; | ||
/** | ||
* City. **Max 35 characters.** | ||
* City. **Max 35 characters.**. | ||
*/ | ||
city: string; | ||
/** | ||
* Country code. **2 characters.** | ||
* Country code. **2 characters.**. | ||
*/ | ||
country: string; | ||
/** | ||
* Name. **Max. 70 characters.** | ||
* Name. **Max. 70 characters.**. | ||
*/ | ||
name: string; | ||
/** | ||
* Postal code. **Max 16 characters.** | ||
* Postal code. **Max 16 characters.**. | ||
*/ | ||
zip: number | string; | ||
/** | ||
* Building number. **Max 16 characters.** | ||
* Building number. **Max 16 characters.**. | ||
*/ | ||
@@ -82,3 +82,3 @@ buildingNumber?: number | string; | ||
/** | ||
* The IBAN. **21 characters.** | ||
* The IBAN. **21 characters.**. | ||
*/ | ||
@@ -90,4 +90,5 @@ account: string; | ||
* Font used for the QR-Bill. | ||
* Fonts other than Helvetica must be registered in the PDFKit document. {@link http://pdfkit.org/docs/text.html#fonts} | ||
* @defaultValue 'Helvetica' | ||
* Fonts other than Helvetica must be registered in the PDFKit document. {@link http://pdfkit.org/docs/text.html#fonts}. | ||
* | ||
* @default 'Helvetica' | ||
* @example | ||
@@ -105,3 +106,4 @@ * ```ts | ||
* The language with which the bill is rendered. | ||
* @defaultValue `DE` | ||
* | ||
* @default `DE` | ||
*/ | ||
@@ -111,3 +113,4 @@ language?: "DE" | "EN" | "FR" | "IT"; | ||
* Whether you want render the outlines. This option may be disabled if you use perforated paper. | ||
* @defaultValue `true` | ||
* | ||
* @default `true` | ||
*/ | ||
@@ -119,3 +122,4 @@ outlines?: boolean; | ||
* **Warning:** Setting **scissors** to false sets **separate** to true. To disable scissors and separate, you have to set both options to false. | ||
* @defaultValue `true` | ||
* | ||
* @default `true` | ||
*/ | ||
@@ -129,3 +133,4 @@ scissors?: boolean; | ||
* **Warning:** Setting **separate** to true sets **scissors** to false. To disable scissors and separate, you have to set both options to false. | ||
* @defaultValue `false` | ||
* | ||
* @default `false` | ||
*/ | ||
@@ -132,0 +137,0 @@ separate?: boolean; |
/** | ||
* Checks whether the given iban is a QR-IBAN or not. | ||
* | ||
* @param iban The IBAN to be checked. | ||
@@ -9,2 +10,3 @@ * @returns `true` if the given IBAN is a QR-IBAN and `false` otherwise. | ||
* Validates the given IBAN. | ||
* | ||
* @param iban The IBAN to be checked. | ||
@@ -16,2 +18,3 @@ * @returns `true` if the checksum of the given IBAN is valid and `false` otherwise. | ||
* Formats the given IBAN according the specifications to be easily readable. | ||
* | ||
* @param iban The IBAN to be formatted. | ||
@@ -23,2 +26,3 @@ * @returns The formatted IBAN. | ||
* Checks whether the given reference is a QR-Reference or not. | ||
* | ||
* @param reference The Reference to be checked. | ||
@@ -31,2 +35,3 @@ * @returns `true` if the given reference is a QR-Reference and `false` otherwise. | ||
* Validates the given QR-Reference. | ||
* | ||
* @param reference The reference to be checked. | ||
@@ -38,2 +43,3 @@ * @returns `true` if the given reference is valid and `false` otherwise. | ||
* Checks whether the given reference is a SCOR-Reference or not. | ||
* | ||
* @param reference The Reference to be checked. | ||
@@ -46,2 +52,3 @@ * @returns `true` if the given reference is a SCOR-Reference and `false` otherwise. | ||
* Validates the given SCOR-Reference. | ||
* | ||
* @param reference The reference to be checked. | ||
@@ -53,2 +60,3 @@ * @returns `true` if the given reference is valid and `false` otherwise. | ||
* Calculates the checksum according to the ISO 11649 standard. | ||
* | ||
* @param reference The max 21 digits long reference (without the "RF" and the 2 digit checksum) whose checksum should be calculated. | ||
@@ -60,2 +68,3 @@ * @returns The calculated checksum as 2 digit string. | ||
* Calculates the checksum according the specifications. | ||
* | ||
* @param reference The 26 digits long reference (without the checksum) whose checksum should be calculated. | ||
@@ -67,2 +76,3 @@ * @returns The calculated checksum. | ||
* Formats the given QR-Reference according the specifications to be easily readable. | ||
* | ||
* @param reference The QR-Reference to be formatted. | ||
@@ -74,2 +84,3 @@ * @returns The formatted QR-Reference. | ||
* Formats the given SCOR-Reference according the specifications to be easily readable. | ||
* | ||
* @param reference The SCOR-Reference to be formatted. | ||
@@ -81,2 +92,3 @@ * @returns The formatted SCOR-Reference. | ||
* Detects the type of the given reference and formats it according the specifications to be easily readable. | ||
* | ||
* @param reference The reference to be formatted. | ||
@@ -88,3 +100,4 @@ * @returns The formatted reference. | ||
* Formats the given amount according the specifications to be easily readable. | ||
* @param amount containing the amount to be formatted. | ||
* | ||
* @param amount Containing the amount to be formatted. | ||
* @returns The formatted amount. | ||
@@ -95,2 +108,3 @@ */ | ||
* Converts millimeters to points. | ||
* | ||
* @param millimeters The millimeters you want to convert to points. | ||
@@ -102,2 +116,3 @@ * @returns The converted millimeters in points. | ||
* Converts points to millimeters. | ||
* | ||
* @param points The points you want to convert to millimeters. | ||
@@ -109,2 +124,3 @@ * @returns The converted points in millimeters. | ||
* Converts millimeters to pixels. | ||
* | ||
* @param millimeters The millimeters you want to convert to pixels. | ||
@@ -116,3 +132,4 @@ * @returns The converted millimeters in pixels. | ||
* Converts pixels to millimeters. | ||
* @param pixels containing the pixels you want to convert to millimeters. | ||
* | ||
* @param pixels Containing the pixels you want to convert to millimeters. | ||
* @returns The converted pixels in millimeters. | ||
@@ -123,2 +140,3 @@ */ | ||
* Detects the type of the given reference. | ||
* | ||
* @param reference The reference to get the type of. | ||
@@ -125,0 +143,0 @@ * @returns The type of the given reference. |
@@ -1,4 +0,5 @@ | ||
import type { Data } from './types.js'; | ||
import { Data } from './types.js'; | ||
/** | ||
* Validate the provided data. | ||
* | ||
* @param data The data to validate. | ||
@@ -5,0 +6,0 @@ * @throws { ValidationError } If the data is invalid. |
@@ -385,2 +385,2 @@ export declare const arial8pt: { | ||
}; | ||
export declare function calculateTextWidth(text: string, size: "8pt" | "10pt"): number; | ||
export declare function calculateTextWidth(text: string, size: "10pt" | "8pt"): number; |
@@ -1,2 +0,2 @@ | ||
export * from "./swissqrbill.js"; | ||
export * from "./swissqrcode.js"; | ||
export * from './swissqrbill.js'; | ||
export * from './swissqrcode.js'; |
@@ -1,5 +0,6 @@ | ||
import { SVG } from "svg-engine"; | ||
import type { Data, SVGOptions } from '../shared/types.js'; | ||
import { SVG } from 'svg-engine'; | ||
import { Data, SVGOptions } from '../shared/types.js'; | ||
/** | ||
* The SwissQRBill class creates the Payment Part with the QR Code as an SVG. | ||
* | ||
* @example | ||
@@ -44,2 +45,3 @@ * ```ts | ||
* Outputs the SVG as a string. | ||
* | ||
* @returns The outerHTML of the SVG. | ||
@@ -50,2 +52,3 @@ */ | ||
* Returns the SVG element. | ||
* | ||
* @returns The SVG element. | ||
@@ -52,0 +55,0 @@ */ |
@@ -1,3 +0,3 @@ | ||
import { SVG } from "svg-engine"; | ||
import type { Data } from '../shared/types.js'; | ||
import { SVG } from 'svg-engine'; | ||
import { Data } from '../shared/types.js'; | ||
export declare class SwissQRCode { | ||
@@ -7,2 +7,3 @@ instance: SVG; | ||
* Creates a Swiss QR Code. | ||
* | ||
* @param data The data to be encoded in the QR code. | ||
@@ -15,2 +16,3 @@ * @param size The size of the QR code in mm. | ||
* Outputs the SVG as a string. | ||
* | ||
* @returns The outerHTML of the SVG element. | ||
@@ -21,2 +23,3 @@ */ | ||
* Returns the SVG element. | ||
* | ||
* @returns The SVG element. | ||
@@ -23,0 +26,0 @@ */ |
@@ -1,3 +0,3 @@ | ||
export * from "./swissqrbill.js"; | ||
export * from "./swissqrcode.js"; | ||
export * from "./table.js"; | ||
export * from './swissqrbill.js'; | ||
export * from './swissqrcode.js'; | ||
export * from './table.js'; |
@@ -1,6 +0,6 @@ | ||
/// <reference types="pdfkit" /> | ||
import type { Data, PDFOptions } from '../shared/types.js'; | ||
import { Data, PDFOptions } from '../shared/types.js'; | ||
/** | ||
* The SwissQRBill class creates the Payment Part with the QR Code. It can be attached to any PDFKit document instance | ||
* using the {@link SwissQRBill.attachTo} method. | ||
* | ||
* @example | ||
@@ -52,2 +52,3 @@ * ```ts | ||
* Creates a new SwissQRBill instance. | ||
* | ||
* @param data The data to be used for the QR Bill. | ||
@@ -61,3 +62,4 @@ * @param options Options to define how the QR Bill should be rendered. | ||
* enough space is left on the current page. | ||
* @param doc The PDFKit instance | ||
* | ||
* @param doc The PDFKit instance. | ||
* @param x The horizontal position in points where the QR Bill will be placed. | ||
@@ -69,3 +71,4 @@ * @param y The vertical position in points where the QR Bill will be placed. | ||
* Checks whether there is enough space on the current page to add the QR Bill. | ||
* @param doc The PDFKit document instance | ||
* | ||
* @param doc The PDFKit document instance. | ||
* @param xPosition The horizontal position where the QR Bill will be placed. | ||
@@ -72,0 +75,0 @@ * @param yPosition The vertical position where the QR Bill will be placed. |
@@ -28,2 +28,3 @@ var __defProp = Object.defineProperty; | ||
* Creates a new SwissQRBill instance. | ||
* | ||
* @param data The data to be used for the QR Bill. | ||
@@ -62,3 +63,4 @@ * @param options Options to define how the QR Bill should be rendered. | ||
* enough space is left on the current page. | ||
* @param doc The PDFKit instance | ||
* | ||
* @param doc The PDFKit instance. | ||
* @param x The horizontal position in points where the QR Bill will be placed. | ||
@@ -82,3 +84,4 @@ * @param y The vertical position in points where the QR Bill will be placed. | ||
* Checks whether there is enough space on the current page to add the QR Bill. | ||
* @param doc The PDFKit document instance | ||
* | ||
* @param doc The PDFKit document instance. | ||
* @param xPosition The horizontal position where the QR Bill will be placed. | ||
@@ -85,0 +88,0 @@ * @param yPosition The vertical position where the QR Bill will be placed. |
@@ -1,3 +0,2 @@ | ||
/// <reference types="pdfkit" /> | ||
import type { Data } from '../shared/types.js'; | ||
import { Data } from '../shared/types.js'; | ||
export declare class SwissQRCode { | ||
@@ -8,2 +7,3 @@ private size; | ||
* Creates a Swiss QR Code. | ||
* | ||
* @param data The data to be encoded in the QR code. | ||
@@ -16,2 +16,3 @@ * @param size The size of the QR code in mm. | ||
* Attaches the Swiss QR Code to a PDF document. | ||
* | ||
* @param doc The PDF document to attach the Swiss QR Code to. | ||
@@ -18,0 +19,0 @@ * @param x The horizontal position in points where the Swiss QR Code will be placed. |
@@ -8,2 +8,3 @@ import { cleanData } from "../shared/cleaner.js"; | ||
* Creates a Swiss QR Code. | ||
* | ||
* @param data The data to be encoded in the QR code. | ||
@@ -20,2 +21,3 @@ * @param size The size of the QR code in mm. | ||
* Attaches the Swiss QR Code to a PDF document. | ||
* | ||
* @param doc The PDF document to attach the Swiss QR Code to. | ||
@@ -22,0 +24,0 @@ * @param x The horizontal position in points where the Swiss QR Code will be placed. |
@@ -1,10 +0,9 @@ | ||
/// <reference types="pdfkit" /> | ||
export interface PDFTable { | ||
/** Table rows. */ | ||
rows: PDFRow[]; | ||
/** Horizontal alignment of texts inside the table */ | ||
/** Horizontal alignment of texts inside the table. */ | ||
align?: "center" | "left" | "right"; | ||
/** Background color of the table. */ | ||
backgroundColor?: string; | ||
/** The colors of the border */ | ||
/** The colors of the border. */ | ||
borderColor?: PDFBorderColor; | ||
@@ -23,3 +22,3 @@ /** Width of the borders of the row. */ | ||
textOptions?: PDFKit.Mixins.TextOptions; | ||
/** Vertical alignment of texts inside the table */ | ||
/** Vertical alignment of texts inside the table. */ | ||
verticalAlign?: "bottom" | "center" | "top"; | ||
@@ -32,7 +31,7 @@ /** Width of whole table. */ | ||
columns: PDFColumn[]; | ||
/** Horizontal alignment of texts inside the row */ | ||
/** Horizontal alignment of texts inside the row. */ | ||
align?: "center" | "left" | "right"; | ||
/** Background color of the row. */ | ||
backgroundColor?: string; | ||
/** The colors of the border */ | ||
/** The colors of the border. */ | ||
borderColor?: PDFBorderColor; | ||
@@ -47,7 +46,7 @@ /** Width of the borders of the row. */ | ||
header?: boolean; | ||
/** Height of the row. Overrides minHeight and maxHeight */ | ||
/** Height of the row. Overrides minHeight and maxHeight. */ | ||
height?: number; | ||
/** Maximum height of the row */ | ||
/** Maximum height of the row. */ | ||
maxHeight?: number; | ||
/** Minimum height of the row */ | ||
/** Minimum height of the row. */ | ||
minHeight?: number; | ||
@@ -60,3 +59,3 @@ /** Cell padding of the table cells inside the row. */ | ||
textOptions?: PDFKit.Mixins.TextOptions; | ||
/** Vertical alignment of texts inside the row */ | ||
/** Vertical alignment of texts inside the row. */ | ||
verticalAlign?: "bottom" | "center" | "top"; | ||
@@ -67,7 +66,7 @@ } | ||
text: boolean | number | string; | ||
/** Horizontal alignment of the text inside the cell */ | ||
/** Horizontal alignment of the text inside the cell. */ | ||
align?: "center" | "left" | "right"; | ||
/** Background color of the cell. */ | ||
backgroundColor?: string; | ||
/** The colors of the border */ | ||
/** The colors of the border. */ | ||
borderColor?: PDFBorderColor; | ||
@@ -86,3 +85,3 @@ /** Width of the borders of the row. */ | ||
textOptions?: PDFKit.Mixins.TextOptions; | ||
/** Vertical alignment of the text inside the cell */ | ||
/** Vertical alignment of the text inside the cell. */ | ||
verticalAlign?: "bottom" | "center" | "top"; | ||
@@ -101,2 +100,3 @@ /** Width of the cell. */ | ||
* using the {@link Table.attachTo} method. | ||
* | ||
* @example | ||
@@ -144,2 +144,3 @@ * ```ts | ||
* Creates a new Table instance. | ||
* | ||
* @param data The rows and columns for the table. | ||
@@ -153,3 +154,4 @@ * @returns The Table instance. | ||
* every row that no longer fits on a page. | ||
* @param doc The PDFKit document instance | ||
* | ||
* @param doc The PDFKit document instance. | ||
* @param x The horizontal position in points where the table be placed. | ||
@@ -156,0 +158,0 @@ * @param y The vertical position in points where the table will be placed. |
@@ -31,2 +31,3 @@ var __defProp = Object.defineProperty; | ||
* Creates a new Table instance. | ||
* | ||
* @param data The rows and columns for the table. | ||
@@ -52,3 +53,4 @@ * @returns The Table instance. | ||
* every row that no longer fits on a page. | ||
* @param doc The PDFKit document instance | ||
* | ||
* @param doc The PDFKit document instance. | ||
* @param x The horizontal position in points where the table be placed. | ||
@@ -85,151 +87,149 @@ * @param y The vertical position in points where the table will be placed. | ||
let rowY = tableY; | ||
rowLoop: | ||
for (let rowIndex = 0; rowIndex < this.data.rows.length; rowIndex++) { | ||
const row = this.data.rows[rowIndex]; | ||
const rowHeight = autoRowHeights[rowIndex]; | ||
const minRowHeight = row.minHeight; | ||
const maxRowHeight = row.maxHeight; | ||
const rowPadding = row.padding ? row.padding : tablePadding; | ||
const rowBackgroundColor = row.backgroundColor ? row.backgroundColor : tableBackgroundColor; | ||
const rowBorder = row.borderWidth ? row.borderWidth : tableBorder; | ||
const rowBorderColors = row.borderColor ? row.borderColor : tableBorderColors; | ||
const rowFontSize = row.fontSize ? row.fontSize : tableFontSize; | ||
const rowFont = row.fontName ? row.fontName : tableFont; | ||
const rowTextColor = row.textColor ? row.textColor : tableTextColor; | ||
const rowAlign = row.align ? row.align : tableAlign; | ||
const rowVerticalAlign = row.verticalAlign ? row.verticalAlign : tableVerticalAlign; | ||
doc.moveTo(tableX, tableY); | ||
let columnX = tableX; | ||
columnLoop: | ||
for (let columnIndex = 0; columnIndex < row.columns.length; columnIndex++) { | ||
const column = row.columns[columnIndex]; | ||
const { remainingColumns, widthUsed } = row.columns.reduce((acc, column2) => { | ||
if (column2.width !== void 0) { | ||
acc.widthUsed += column2.width; | ||
acc.remainingColumns--; | ||
} | ||
return acc; | ||
}, { remainingColumns: row.columns.length, widthUsed: 0 }); | ||
const columnWidth = column.width ? column.width : (tableWidth - widthUsed) / remainingColumns; | ||
const columnPadding = column.padding ? column.padding : rowPadding; | ||
const columnBackgroundColor = column.backgroundColor ? column.backgroundColor : rowBackgroundColor; | ||
const columnBorder = column.borderWidth ? column.borderWidth : rowBorder; | ||
const columnBorderColors = column.borderColor ? column.borderColor : rowBorderColors; | ||
const columnFontSize = column.fontSize ? column.fontSize : rowFontSize; | ||
const columnFont = column.fontName ? column.fontName : rowFont; | ||
const columnTextColor = column.textColor ? column.textColor : rowTextColor; | ||
const columnAlign = column.align ? column.align : rowAlign; | ||
const columnVerticalAlign = column.verticalAlign ? column.verticalAlign : rowVerticalAlign; | ||
const fillOpacity = columnBackgroundColor === void 0 ? 0 : 1; | ||
const borderOpacity = columnBorderColors === void 0 ? 0 : 1; | ||
const paddings = this._positionsToObject(columnPadding); | ||
doc.moveTo(columnX + columnWidth, rowY); | ||
const textOptions = __spreadProps(__spreadValues({}, (_a2 = column.textOptions) != null ? _a2 : {}), { | ||
align: columnAlign, | ||
baseline: "middle", | ||
height: rowHeight !== void 0 ? rowHeight - ((_b2 = paddings.top) != null ? _b2 : 0) - ((_c = paddings.bottom) != null ? _c : 0) : void 0, | ||
lineBreak: true, | ||
width: columnWidth - ((_d = paddings.left) != null ? _d : 0) - ((_e = paddings.right) != null ? _e : 0) | ||
}); | ||
doc.font(columnFont); | ||
doc.fontSize(columnFontSize); | ||
const textHeight = doc.heightOfString(`${column.text}`, textOptions); | ||
const singleLineHeight = doc.heightOfString("A", textOptions); | ||
if (layer === 0) { | ||
if (autoRowHeights[rowIndex] === void 0 || autoRowHeights[rowIndex] < textHeight + ((_f = paddings.top) != null ? _f : 0) + ((_g = paddings.bottom) != null ? _g : 0)) { | ||
autoRowHeights[rowIndex] = textHeight + ((_h = paddings.top) != null ? _h : 0) + ((_i = paddings.bottom) != null ? _i : 0); | ||
if (minRowHeight !== void 0 && autoRowHeights[rowIndex] < minRowHeight) { | ||
autoRowHeights[rowIndex] = minRowHeight; | ||
} | ||
if (maxRowHeight !== void 0 && autoRowHeights[rowIndex] > maxRowHeight) { | ||
autoRowHeights[rowIndex] = maxRowHeight; | ||
} | ||
} | ||
if (row.height !== void 0) { | ||
autoRowHeights[rowIndex] = row.height; | ||
} | ||
if (columnIndex < row.columns.length - 1) { | ||
continue columnLoop; | ||
} else { | ||
continue rowLoop; | ||
} | ||
rowLoop: for (let rowIndex = 0; rowIndex < this.data.rows.length; rowIndex++) { | ||
const row = this.data.rows[rowIndex]; | ||
const rowHeight = autoRowHeights[rowIndex]; | ||
const minRowHeight = row.minHeight; | ||
const maxRowHeight = row.maxHeight; | ||
const rowPadding = row.padding ? row.padding : tablePadding; | ||
const rowBackgroundColor = row.backgroundColor ? row.backgroundColor : tableBackgroundColor; | ||
const rowBorder = row.borderWidth ? row.borderWidth : tableBorder; | ||
const rowBorderColors = row.borderColor ? row.borderColor : tableBorderColors; | ||
const rowFontSize = row.fontSize ? row.fontSize : tableFontSize; | ||
const rowFont = row.fontName ? row.fontName : tableFont; | ||
const rowTextColor = row.textColor ? row.textColor : tableTextColor; | ||
const rowAlign = row.align ? row.align : tableAlign; | ||
const rowVerticalAlign = row.verticalAlign ? row.verticalAlign : tableVerticalAlign; | ||
doc.moveTo(tableX, tableY); | ||
let columnX = tableX; | ||
columnLoop: for (let columnIndex = 0; columnIndex < row.columns.length; columnIndex++) { | ||
const column = row.columns[columnIndex]; | ||
const { remainingColumns, widthUsed } = row.columns.reduce((acc, column2) => { | ||
if (column2.width !== void 0) { | ||
acc.widthUsed += column2.width; | ||
acc.remainingColumns--; | ||
} | ||
return acc; | ||
}, { remainingColumns: row.columns.length, widthUsed: 0 }); | ||
const columnWidth = column.width ? column.width : (tableWidth - widthUsed) / remainingColumns; | ||
const columnPadding = column.padding ? column.padding : rowPadding; | ||
const columnBackgroundColor = column.backgroundColor ? column.backgroundColor : rowBackgroundColor; | ||
const columnBorder = column.borderWidth ? column.borderWidth : rowBorder; | ||
const columnBorderColors = column.borderColor ? column.borderColor : rowBorderColors; | ||
const columnFontSize = column.fontSize ? column.fontSize : rowFontSize; | ||
const columnFont = column.fontName ? column.fontName : rowFont; | ||
const columnTextColor = column.textColor ? column.textColor : rowTextColor; | ||
const columnAlign = column.align ? column.align : rowAlign; | ||
const columnVerticalAlign = column.verticalAlign ? column.verticalAlign : rowVerticalAlign; | ||
const fillOpacity = columnBackgroundColor === void 0 ? 0 : 1; | ||
const borderOpacity = columnBorderColors === void 0 ? 0 : 1; | ||
const paddings = this._positionsToObject(columnPadding); | ||
doc.moveTo(columnX + columnWidth, rowY); | ||
const textOptions = __spreadProps(__spreadValues({}, (_a2 = column.textOptions) != null ? _a2 : {}), { | ||
align: columnAlign, | ||
baseline: "middle", | ||
height: rowHeight !== void 0 ? rowHeight - ((_b2 = paddings.top) != null ? _b2 : 0) - ((_c = paddings.bottom) != null ? _c : 0) : void 0, | ||
lineBreak: true, | ||
width: columnWidth - ((_d = paddings.left) != null ? _d : 0) - ((_e = paddings.right) != null ? _e : 0) | ||
}); | ||
doc.font(columnFont); | ||
doc.fontSize(columnFontSize); | ||
const textHeight = doc.heightOfString(`${column.text}`, textOptions); | ||
const singleLineHeight = doc.heightOfString("A", textOptions); | ||
if (layer === 0) { | ||
if (autoRowHeights[rowIndex] === void 0 || autoRowHeights[rowIndex] < textHeight + ((_f = paddings.top) != null ? _f : 0) + ((_g = paddings.bottom) != null ? _g : 0)) { | ||
autoRowHeights[rowIndex] = textHeight + ((_h = paddings.top) != null ? _h : 0) + ((_i = paddings.bottom) != null ? _i : 0); | ||
if (minRowHeight !== void 0 && autoRowHeights[rowIndex] < minRowHeight) { | ||
autoRowHeights[rowIndex] = minRowHeight; | ||
} | ||
if (layer === 1) { | ||
if (rowY + rowHeight >= doc.page.height - doc.page.margins.bottom) { | ||
doc.addPage(); | ||
rowY = doc.y; | ||
const headerRow = this.data.rows[headerRowIndex]; | ||
if (headerRow !== void 0) { | ||
this.data.rows.splice(rowIndex, 0, headerRow); | ||
autoRowHeights.splice(rowIndex, 0, autoRowHeights[headerRowIndex]); | ||
rowIndex--; | ||
continue rowLoop; | ||
} | ||
} | ||
if (maxRowHeight !== void 0 && autoRowHeights[rowIndex] > maxRowHeight) { | ||
autoRowHeights[rowIndex] = maxRowHeight; | ||
} | ||
if (layer > 1) { | ||
if (!!row.header && rowY !== ((_j = doc.page.margins.top) != null ? _j : 0) && rowIndex !== headerRowIndex || rowY + rowHeight >= doc.page.height - doc.page.margins.bottom) { | ||
doc.switchToPage(this.getCurrentPage(doc) + 1); | ||
doc.x = tableX; | ||
doc.y = (_k = doc.page.margins.top) != null ? _k : 0; | ||
rowY = doc.y; | ||
} | ||
} | ||
if (row.height !== void 0) { | ||
autoRowHeights[rowIndex] = row.height; | ||
} | ||
if (columnIndex < row.columns.length - 1) { | ||
continue columnLoop; | ||
} else { | ||
continue rowLoop; | ||
} | ||
} | ||
if (layer === 1) { | ||
if (rowY + rowHeight >= doc.page.height - doc.page.margins.bottom) { | ||
doc.addPage(); | ||
rowY = doc.y; | ||
const headerRow = this.data.rows[headerRowIndex]; | ||
if (headerRow !== void 0) { | ||
this.data.rows.splice(rowIndex, 0, headerRow); | ||
autoRowHeights.splice(rowIndex, 0, autoRowHeights[headerRowIndex]); | ||
rowIndex--; | ||
continue rowLoop; | ||
} | ||
if (layer === 2) { | ||
if (columnBackgroundColor !== void 0) { | ||
doc.rect(columnX, rowY, columnWidth, rowHeight).fillColor(columnBackgroundColor).fillOpacity(fillOpacity).fill(); | ||
} | ||
} | ||
} | ||
if (layer > 1) { | ||
if (!!row.header && rowY !== ((_j = doc.page.margins.top) != null ? _j : 0) && rowIndex !== headerRowIndex || rowY + rowHeight >= doc.page.height - doc.page.margins.bottom) { | ||
doc.switchToPage(this.getCurrentPage(doc) + 1); | ||
doc.x = tableX; | ||
doc.y = (_k = doc.page.margins.top) != null ? _k : 0; | ||
rowY = doc.y; | ||
} | ||
} | ||
if (layer === 2) { | ||
if (columnBackgroundColor !== void 0) { | ||
doc.rect(columnX, rowY, columnWidth, rowHeight).fillColor(columnBackgroundColor).fillOpacity(fillOpacity).fill(); | ||
} | ||
} | ||
if (layer === 4) { | ||
let textPosY = rowY; | ||
if (columnVerticalAlign === "top") { | ||
textPosY = rowY + ((_l = paddings.top) != null ? _l : 0) + singleLineHeight / 2; | ||
} else if (columnVerticalAlign === "center") { | ||
textPosY = rowY + rowHeight / 2 - textHeight / 2 + singleLineHeight / 2; | ||
} else if (columnVerticalAlign === "bottom") { | ||
textPosY = rowY + rowHeight - ((_m = paddings.bottom) != null ? _m : 0) - textHeight + singleLineHeight / 2; | ||
} | ||
if (textPosY < rowY + ((_n = paddings.top) != null ? _n : 0) + singleLineHeight / 2) { | ||
textPosY = rowY + ((_o = paddings.top) != null ? _o : 0) + singleLineHeight / 2; | ||
} | ||
doc.fillColor(columnTextColor).fillOpacity(1); | ||
doc.text(`${column.text}`, columnX + ((_p = paddings.left) != null ? _p : 0), textPosY, textOptions); | ||
} | ||
if (layer === 3) { | ||
if (columnBorder !== void 0 && columnBorderColors !== void 0) { | ||
const border = this._positionsToObject(columnBorder); | ||
const borderColor = this._positionsToObject(columnBorderColors); | ||
doc.undash().lineJoin("miter").lineCap("butt").strokeOpacity(borderOpacity); | ||
if (border.left && borderColor.left) { | ||
const borderBottomMargin = border.bottom ? border.bottom / 2 : 0; | ||
const borderTopMargin = border.top ? border.top / 2 : 0; | ||
doc.moveTo(columnX, rowY + rowHeight + borderBottomMargin); | ||
doc.lineTo(columnX, rowY - borderTopMargin).strokeColor(borderColor.left).lineWidth(border.left).stroke(); | ||
} | ||
if (layer === 4) { | ||
let textPosY = rowY; | ||
if (columnVerticalAlign === "top") { | ||
textPosY = rowY + ((_l = paddings.top) != null ? _l : 0) + singleLineHeight / 2; | ||
} else if (columnVerticalAlign === "center") { | ||
textPosY = rowY + rowHeight / 2 - textHeight / 2 + singleLineHeight / 2; | ||
} else if (columnVerticalAlign === "bottom") { | ||
textPosY = rowY + rowHeight - ((_m = paddings.bottom) != null ? _m : 0) - textHeight + singleLineHeight / 2; | ||
} | ||
if (textPosY < rowY + ((_n = paddings.top) != null ? _n : 0) + singleLineHeight / 2) { | ||
textPosY = rowY + ((_o = paddings.top) != null ? _o : 0) + singleLineHeight / 2; | ||
} | ||
doc.fillColor(columnTextColor).fillOpacity(1); | ||
doc.text(`${column.text}`, columnX + ((_p = paddings.left) != null ? _p : 0), textPosY, textOptions); | ||
if (border.right && borderColor.right) { | ||
const borderTopMargin = border.top ? border.top / 2 : 0; | ||
const borderBottomMargin = border.bottom ? border.bottom / 2 : 0; | ||
doc.moveTo(columnX + columnWidth, rowY - borderTopMargin); | ||
doc.lineTo(columnX + columnWidth, rowY + rowHeight + borderBottomMargin).strokeColor(borderColor.right).lineWidth(border.right).stroke(); | ||
} | ||
if (layer === 3) { | ||
if (columnBorder !== void 0 && columnBorderColors !== void 0) { | ||
const border = this._positionsToObject(columnBorder); | ||
const borderColor = this._positionsToObject(columnBorderColors); | ||
doc.undash().lineJoin("miter").lineCap("butt").strokeOpacity(borderOpacity); | ||
if (border.left && borderColor.left) { | ||
const borderBottomMargin = border.bottom ? border.bottom / 2 : 0; | ||
const borderTopMargin = border.top ? border.top / 2 : 0; | ||
doc.moveTo(columnX, rowY + rowHeight + borderBottomMargin); | ||
doc.lineTo(columnX, rowY - borderTopMargin).strokeColor(borderColor.left).lineWidth(border.left).stroke(); | ||
} | ||
if (border.right && borderColor.right) { | ||
const borderTopMargin = border.top ? border.top / 2 : 0; | ||
const borderBottomMargin = border.bottom ? border.bottom / 2 : 0; | ||
doc.moveTo(columnX + columnWidth, rowY - borderTopMargin); | ||
doc.lineTo(columnX + columnWidth, rowY + rowHeight + borderBottomMargin).strokeColor(borderColor.right).lineWidth(border.right).stroke(); | ||
} | ||
if (border.top && borderColor.top) { | ||
const borderLeftMargin = border.left ? border.left / 2 : 0; | ||
const borderRightMargin = border.right ? border.right / 2 : 0; | ||
doc.moveTo(columnX - borderLeftMargin, rowY); | ||
doc.lineTo(columnX + columnWidth + borderRightMargin, rowY).strokeColor(borderColor.top).lineWidth(border.top).stroke(); | ||
} | ||
if (border.bottom && borderColor.bottom) { | ||
const borderRightMargin = border.right ? border.right / 2 : 0; | ||
const borderLeftMargin = border.left ? border.left / 2 : 0; | ||
doc.moveTo(columnX + columnWidth + borderRightMargin, rowY + rowHeight); | ||
doc.lineTo(columnX - borderLeftMargin, rowY + rowHeight).strokeColor(borderColor.bottom).lineWidth(border.bottom).stroke(); | ||
} | ||
} | ||
if (border.top && borderColor.top) { | ||
const borderLeftMargin = border.left ? border.left / 2 : 0; | ||
const borderRightMargin = border.right ? border.right / 2 : 0; | ||
doc.moveTo(columnX - borderLeftMargin, rowY); | ||
doc.lineTo(columnX + columnWidth + borderRightMargin, rowY).strokeColor(borderColor.top).lineWidth(border.top).stroke(); | ||
} | ||
columnX += columnWidth; | ||
if (border.bottom && borderColor.bottom) { | ||
const borderRightMargin = border.right ? border.right / 2 : 0; | ||
const borderLeftMargin = border.left ? border.left / 2 : 0; | ||
doc.moveTo(columnX + columnWidth + borderRightMargin, rowY + rowHeight); | ||
doc.lineTo(columnX - borderLeftMargin, rowY + rowHeight).strokeColor(borderColor.bottom).lineWidth(border.bottom).stroke(); | ||
} | ||
} | ||
rowY += rowHeight; | ||
doc.x = columnX; | ||
doc.y = rowY; | ||
} | ||
columnX += columnWidth; | ||
} | ||
rowY += rowHeight; | ||
doc.x = columnX; | ||
doc.y = rowY; | ||
} | ||
} | ||
@@ -236,0 +236,0 @@ doc.x = tableX; |
@@ -1,4 +0,4 @@ | ||
import type { Data } from './types.js'; | ||
import { Data } from './types.js'; | ||
export declare function cleanData(data: Data): Data; | ||
export declare function removeSpaces(text: string): string; | ||
export declare function removeLineBreaks(text: string): string; |
@@ -0,9 +1,6 @@ | ||
/** A {@link ValidationError} is thrown when the data provided to swissqrbill is invalid. */ | ||
export declare class ValidationError extends Error { | ||
constructor(message: string, params?: { | ||
[name: string]: string; | ||
}); | ||
/** A stable error code that can be used to identify the error programmatically. */ | ||
code: keyof typeof ValidationErrors; | ||
} | ||
export declare function resolveMessageParams(message: string, params: { | ||
[name: string]: string; | ||
}): string; | ||
export declare enum ValidationErrors { | ||
@@ -10,0 +7,0 @@ ACCOUNT_IS_QR_IBAN_BUT_REFERENCE_IS_MISSING = "If there is no reference, a conventional IBAN must be used.", |
class ValidationError extends Error { | ||
/** @internal */ | ||
constructor(message, params) { | ||
@@ -6,4 +7,10 @@ const messageWithParams = params ? resolveMessageParams(message, params) : message; | ||
this.name = "ValidationError"; | ||
this.code = getErrorCodeByMessage(message); | ||
} | ||
} | ||
function getErrorCodeByMessage(message) { | ||
const errorCodes = Object.keys(ValidationErrors); | ||
const errorCode = errorCodes.find((key) => ValidationErrors[key] === message); | ||
return errorCode; | ||
} | ||
function resolveMessageParams(message, params) { | ||
@@ -80,3 +87,4 @@ return Object.entries(params).reduce((message2, [key, value]) => { | ||
ValidationErrors, | ||
getErrorCodeByMessage, | ||
resolveMessageParams | ||
}; |
@@ -1,4 +0,4 @@ | ||
import type { Data } from "swissqrbill:shared:types.js"; | ||
import { Data } from './types.js'; | ||
export declare function generateQRData(data: Data): string; | ||
export declare function renderQRCode(data: Data, size: number, renderBlockFunction: (x: number, y: number, blockSize: number) => void): void; | ||
export declare function renderSwissCross(size: number, renderRectFunction: (x: number, y: number, width: number, height: number, fillColor: string) => void): void; |
@@ -7,7 +7,7 @@ export interface Data { | ||
/** | ||
* The currency to be used. **3 characters.** | ||
* The currency to be used. **3 characters.**. | ||
*/ | ||
currency: "CHF" | "EUR"; | ||
/** | ||
* Additional information. **Max 140 characters.** | ||
* Additional information. **Max 140 characters.**. | ||
* | ||
@@ -18,15 +18,15 @@ * Bill information contain coded information for automated booking of the payment. The data is not forwarded with the payment. | ||
/** | ||
* The amount. **Max. 12 digits.** | ||
* The amount. **Max. 12 digits.**. | ||
*/ | ||
amount?: number; | ||
/** | ||
* Alternative scheme. **Max. 100 characters.** | ||
* 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) | ||
* 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.** | ||
* 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) | ||
* 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). | ||
*/ | ||
@@ -39,9 +39,9 @@ av2?: string; | ||
/** | ||
* A message. **Max. 140 characters.** | ||
* 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 can be used to indicate the payment purpose or for additional textual information about payments with a structured reference. | ||
*/ | ||
message?: string; | ||
/** | ||
* A reference number. **Max 27 characters.** | ||
* A reference number. **Max 27 characters.**. | ||
* | ||
@@ -55,23 +55,23 @@ * QR-IBAN: Maximum 27 characters. Must be filled if a QR-IBAN is used. | ||
/** | ||
* Address. **Max 70 characters.** | ||
* Address. **Max 70 characters.**. | ||
*/ | ||
address: string; | ||
/** | ||
* City. **Max 35 characters.** | ||
* City. **Max 35 characters.**. | ||
*/ | ||
city: string; | ||
/** | ||
* Country code. **2 characters.** | ||
* Country code. **2 characters.**. | ||
*/ | ||
country: string; | ||
/** | ||
* Name. **Max. 70 characters.** | ||
* Name. **Max. 70 characters.**. | ||
*/ | ||
name: string; | ||
/** | ||
* Postal code. **Max 16 characters.** | ||
* Postal code. **Max 16 characters.**. | ||
*/ | ||
zip: number | string; | ||
/** | ||
* Building number. **Max 16 characters.** | ||
* Building number. **Max 16 characters.**. | ||
*/ | ||
@@ -82,3 +82,3 @@ buildingNumber?: number | string; | ||
/** | ||
* The IBAN. **21 characters.** | ||
* The IBAN. **21 characters.**. | ||
*/ | ||
@@ -90,4 +90,5 @@ account: string; | ||
* Font used for the QR-Bill. | ||
* Fonts other than Helvetica must be registered in the PDFKit document. {@link http://pdfkit.org/docs/text.html#fonts} | ||
* @defaultValue 'Helvetica' | ||
* Fonts other than Helvetica must be registered in the PDFKit document. {@link http://pdfkit.org/docs/text.html#fonts}. | ||
* | ||
* @default 'Helvetica' | ||
* @example | ||
@@ -105,3 +106,4 @@ * ```ts | ||
* The language with which the bill is rendered. | ||
* @defaultValue `DE` | ||
* | ||
* @default `DE` | ||
*/ | ||
@@ -111,3 +113,4 @@ language?: "DE" | "EN" | "FR" | "IT"; | ||
* Whether you want render the outlines. This option may be disabled if you use perforated paper. | ||
* @defaultValue `true` | ||
* | ||
* @default `true` | ||
*/ | ||
@@ -119,3 +122,4 @@ outlines?: boolean; | ||
* **Warning:** Setting **scissors** to false sets **separate** to true. To disable scissors and separate, you have to set both options to false. | ||
* @defaultValue `true` | ||
* | ||
* @default `true` | ||
*/ | ||
@@ -129,3 +133,4 @@ scissors?: boolean; | ||
* **Warning:** Setting **separate** to true sets **scissors** to false. To disable scissors and separate, you have to set both options to false. | ||
* @defaultValue `false` | ||
* | ||
* @default `false` | ||
*/ | ||
@@ -132,0 +137,0 @@ separate?: boolean; |
/** | ||
* Checks whether the given iban is a QR-IBAN or not. | ||
* | ||
* @param iban The IBAN to be checked. | ||
@@ -9,2 +10,3 @@ * @returns `true` if the given IBAN is a QR-IBAN and `false` otherwise. | ||
* Validates the given IBAN. | ||
* | ||
* @param iban The IBAN to be checked. | ||
@@ -16,2 +18,3 @@ * @returns `true` if the checksum of the given IBAN is valid and `false` otherwise. | ||
* Formats the given IBAN according the specifications to be easily readable. | ||
* | ||
* @param iban The IBAN to be formatted. | ||
@@ -23,2 +26,3 @@ * @returns The formatted IBAN. | ||
* Checks whether the given reference is a QR-Reference or not. | ||
* | ||
* @param reference The Reference to be checked. | ||
@@ -31,2 +35,3 @@ * @returns `true` if the given reference is a QR-Reference and `false` otherwise. | ||
* Validates the given QR-Reference. | ||
* | ||
* @param reference The reference to be checked. | ||
@@ -38,2 +43,3 @@ * @returns `true` if the given reference is valid and `false` otherwise. | ||
* Checks whether the given reference is a SCOR-Reference or not. | ||
* | ||
* @param reference The Reference to be checked. | ||
@@ -46,2 +52,3 @@ * @returns `true` if the given reference is a SCOR-Reference and `false` otherwise. | ||
* Validates the given SCOR-Reference. | ||
* | ||
* @param reference The reference to be checked. | ||
@@ -53,2 +60,3 @@ * @returns `true` if the given reference is valid and `false` otherwise. | ||
* Calculates the checksum according to the ISO 11649 standard. | ||
* | ||
* @param reference The max 21 digits long reference (without the "RF" and the 2 digit checksum) whose checksum should be calculated. | ||
@@ -60,2 +68,3 @@ * @returns The calculated checksum as 2 digit string. | ||
* Calculates the checksum according the specifications. | ||
* | ||
* @param reference The 26 digits long reference (without the checksum) whose checksum should be calculated. | ||
@@ -67,2 +76,3 @@ * @returns The calculated checksum. | ||
* Formats the given QR-Reference according the specifications to be easily readable. | ||
* | ||
* @param reference The QR-Reference to be formatted. | ||
@@ -74,2 +84,3 @@ * @returns The formatted QR-Reference. | ||
* Formats the given SCOR-Reference according the specifications to be easily readable. | ||
* | ||
* @param reference The SCOR-Reference to be formatted. | ||
@@ -81,2 +92,3 @@ * @returns The formatted SCOR-Reference. | ||
* Detects the type of the given reference and formats it according the specifications to be easily readable. | ||
* | ||
* @param reference The reference to be formatted. | ||
@@ -88,3 +100,4 @@ * @returns The formatted reference. | ||
* Formats the given amount according the specifications to be easily readable. | ||
* @param amount containing the amount to be formatted. | ||
* | ||
* @param amount Containing the amount to be formatted. | ||
* @returns The formatted amount. | ||
@@ -95,2 +108,3 @@ */ | ||
* Converts millimeters to points. | ||
* | ||
* @param millimeters The millimeters you want to convert to points. | ||
@@ -102,2 +116,3 @@ * @returns The converted millimeters in points. | ||
* Converts points to millimeters. | ||
* | ||
* @param points The points you want to convert to millimeters. | ||
@@ -109,2 +124,3 @@ * @returns The converted points in millimeters. | ||
* Converts millimeters to pixels. | ||
* | ||
* @param millimeters The millimeters you want to convert to pixels. | ||
@@ -116,3 +132,4 @@ * @returns The converted millimeters in pixels. | ||
* Converts pixels to millimeters. | ||
* @param pixels containing the pixels you want to convert to millimeters. | ||
* | ||
* @param pixels Containing the pixels you want to convert to millimeters. | ||
* @returns The converted pixels in millimeters. | ||
@@ -123,2 +140,3 @@ */ | ||
* Detects the type of the given reference. | ||
* | ||
* @param reference The reference to get the type of. | ||
@@ -125,0 +143,0 @@ * @returns The type of the given reference. |
@@ -1,4 +0,5 @@ | ||
import type { Data } from './types.js'; | ||
import { Data } from './types.js'; | ||
/** | ||
* Validate the provided data. | ||
* | ||
* @param data The data to validate. | ||
@@ -5,0 +6,0 @@ * @throws { ValidationError } If the data is invalid. |
@@ -385,2 +385,2 @@ export declare const arial8pt: { | ||
}; | ||
export declare function calculateTextWidth(text: string, size: "8pt" | "10pt"): number; | ||
export declare function calculateTextWidth(text: string, size: "10pt" | "8pt"): number; |
@@ -1,2 +0,2 @@ | ||
export * from "./swissqrbill.js"; | ||
export * from "./swissqrcode.js"; | ||
export * from './swissqrbill.js'; | ||
export * from './swissqrcode.js'; |
@@ -1,5 +0,6 @@ | ||
import { SVG } from "svg-engine"; | ||
import type { Data, SVGOptions } from '../shared/types.js'; | ||
import { SVG } from 'svg-engine'; | ||
import { Data, SVGOptions } from '../shared/types.js'; | ||
/** | ||
* The SwissQRBill class creates the Payment Part with the QR Code as an SVG. | ||
* | ||
* @example | ||
@@ -44,2 +45,3 @@ * ```ts | ||
* Outputs the SVG as a string. | ||
* | ||
* @returns The outerHTML of the SVG. | ||
@@ -50,2 +52,3 @@ */ | ||
* Returns the SVG element. | ||
* | ||
* @returns The SVG element. | ||
@@ -52,0 +55,0 @@ */ |
@@ -28,2 +28,3 @@ import { SVG, calc } from "svg-engine"; | ||
* Outputs the SVG as a string. | ||
* | ||
* @returns The outerHTML of the SVG. | ||
@@ -36,2 +37,3 @@ */ | ||
* Returns the SVG element. | ||
* | ||
* @returns The SVG element. | ||
@@ -38,0 +40,0 @@ */ |
@@ -1,3 +0,3 @@ | ||
import { SVG } from "svg-engine"; | ||
import type { Data } from '../shared/types.js'; | ||
import { SVG } from 'svg-engine'; | ||
import { Data } from '../shared/types.js'; | ||
export declare class SwissQRCode { | ||
@@ -7,2 +7,3 @@ instance: SVG; | ||
* Creates a Swiss QR Code. | ||
* | ||
* @param data The data to be encoded in the QR code. | ||
@@ -15,2 +16,3 @@ * @param size The size of the QR code in mm. | ||
* Outputs the SVG as a string. | ||
* | ||
* @returns The outerHTML of the SVG element. | ||
@@ -21,2 +23,3 @@ */ | ||
* Returns the SVG element. | ||
* | ||
* @returns The SVG element. | ||
@@ -23,0 +26,0 @@ */ |
@@ -6,2 +6,3 @@ import { SVG } from "svg-engine"; | ||
* Creates a Swiss QR Code. | ||
* | ||
* @param data The data to be encoded in the QR code. | ||
@@ -34,2 +35,3 @@ * @param size The size of the QR code in mm. | ||
* Outputs the SVG as a string. | ||
* | ||
* @returns The outerHTML of the SVG element. | ||
@@ -42,2 +44,3 @@ */ | ||
* Returns the SVG element. | ||
* | ||
* @returns The SVG element. | ||
@@ -44,0 +47,0 @@ */ |
{ | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"type": "module", | ||
@@ -66,8 +66,9 @@ "name": "swissqrbill", | ||
"build:esm": "vite build --config vite.config.ts && echo '{ \"type\": \"module\" }' > lib/esm/package.json", | ||
"docs": "npm run docs:pdf && npm run docs:svg && npm run docs:shared && npm run docs:bundle", | ||
"docs": "npm run docs:pdf && npm run docs:svg && npm run docs:utils && npm run docs:errors && npm run docs:bundle", | ||
"docs:bundle": "unwritten src/bundle/index.ts -t tsconfig.docs.json -o docs/bundle/ ", | ||
"docs:errors": "unwritten src/shared/errors.ts -t tsconfig.docs.json -o docs/errors/", | ||
"docs:pdf": "unwritten src/pdf/index.ts src/shared/types.ts -t tsconfig.docs.json -o docs/pdf/", | ||
"docs:shared": "unwritten src/shared/utils.ts -t tsconfig.docs.json -o docs/utils/", | ||
"docs:svg": "unwritten src/svg/index.ts src/shared/types.ts -t tsconfig.docs.json -o docs/svg/", | ||
"eslint": "eslint --ext .ts,.tsx,.js,.jsx,.json,.jsonc,.yml,.md ./", | ||
"docs:utils": "unwritten src/shared/utils.ts -t tsconfig.docs.json -o docs/utils/", | ||
"eslint": "eslint .", | ||
"eslint:ci": "npm run eslint -- --max-warnings 0", | ||
@@ -80,6 +81,6 @@ "eslint:fix": "npm run eslint -- --fix", | ||
"markdownlint:ci": "npm run markdownlint", | ||
"markdownlint:fix": "markdownlint-cli2-fix '**/*.md' '#node_modules'", | ||
"markdownlint:fix": "npm run markdownlint -- --fix", | ||
"postrelease:alpha": "npm run postrelease", | ||
"postrelease:beta": "npm run postrelease", | ||
"postrelease:latest": "eslint --fix package.json && markdownlint-cli2-fix 'CHANGELOG.md'", | ||
"postrelease:latest": "eslint --fix package.json && markdownlint-cli2 --fix 'CHANGELOG.md'", | ||
"prebuild": "npm run typecheck && npm run lint && npm run spellcheck", | ||
@@ -97,3 +98,3 @@ "prerelease:alpha": "npm run test -- --run && npm run build", | ||
"spellcheck:ci": "npm run spellcheck -- --no-progress", | ||
"test": "vitest --config ./vite.config.ts --threads=false", | ||
"test": "vitest --config ./vite.config.ts", | ||
"test:update": "npm run test -- --update --run", | ||
@@ -122,3 +123,3 @@ "test:visual": "cross-env VISUAL=true npm run test -- --run", | ||
"dependencies": { | ||
"svg-engine": "^0.2.3" | ||
"svg-engine": "^0.2.4" | ||
}, | ||
@@ -128,23 +129,19 @@ "devDependencies": { | ||
"@cspell/dict-it-it": "^3.1.0", | ||
"@schoero/changelog-config": "^0.0.3", | ||
"@schoero/cspell-config": "^1.9.0", | ||
"@schoero/eslint-config": "^1.42.0", | ||
"@schoero/markdownlint-config": "^1.1.7", | ||
"@schoero/ts-config": "^0.3.7", | ||
"@schoero/unwritten-config": "^0.0.3", | ||
"@schoero/vite-config": "^0.0.28", | ||
"@types/node": "^20.9.1", | ||
"@types/pdfkit": "^0.13.2", | ||
"@schoero/configs": "^1.1.1", | ||
"@types/node": "^22.5.2", | ||
"@types/pdfkit": "^0.13.4", | ||
"@types/svg-parser": "^2.0.6", | ||
"@typescript-eslint/eslint-plugin": "^6.11.0", | ||
"@typescript-eslint/parser": "^6.11.0", | ||
"changelogen": "^0.5.5", | ||
"cross-env": "^7.0.3", | ||
"glob": "^10.3.10", | ||
"pdfkit": "^0.14.0", | ||
"typescript": "^5.2.2", | ||
"unwritten": "^0.2.7", | ||
"vite": "^5.0.0", | ||
"vite-plugin-dts": "^3.6.3", | ||
"vite-plugin-no-bundle": "^3.0.0", | ||
"vitest": "^0.34.6" | ||
"cspell": "^8.14.2", | ||
"eslint": "^9.9.1", | ||
"glob": "^11.0.0", | ||
"markdownlint": "^0.34.0", | ||
"pdfkit": "^0.15.0", | ||
"typescript": "^5.5.4", | ||
"unwritten": "^0.2.13", | ||
"vite": "^5.4.2", | ||
"vite-plugin-dts": "^4.1.0", | ||
"vite-plugin-no-bundle": "^4.0.0", | ||
"vitest": "^2.0.5" | ||
}, | ||
@@ -171,4 +168,4 @@ "keywords": [ | ||
"volta": { | ||
"node": "20.8.1" | ||
"node": "22.1.0" | ||
} | ||
} |
@@ -32,5 +32,22 @@ <div align="center"> | ||
<div align="center"> | ||
<a href="https://github.com/sponsors/schoero"> | ||
<picture> | ||
<source media="(prefers-color-scheme: dark)" srcset="./assets/sponsor-dark.svg"> | ||
<source media="(prefers-color-scheme: light)" srcset="./assets/sponsor-light.svg"> | ||
<img alt="eslint-plugin-readable-tailwind logo" src="./assets/sponsor-dark.svg"> | ||
</picture> | ||
</a> | ||
Invoices are a critical part of every business. Keeping this library up-to-date with the extensive specifications takes time and effort. | ||
If this library has been valuable to you, please consider becoming a sponsor, or make a one time donation to support its ongoing development. | ||
</div> | ||
<br/> | ||
<br/> | ||
## Links | ||
* [Migration from v3 to v4](#migration-from-v3-to-v4) | ||
* [Features](#features) | ||
@@ -42,2 +59,3 @@ * [Installation](#installation) | ||
* [PDFKit documentation][pdfkit-documentation] | ||
* [Migration from v3 to v4](./docs/migration-v3-to-v4.md) | ||
* [How to create a complete qr bill][how-to-create-a-complete-qr-bill] | ||
@@ -50,10 +68,2 @@ * [QR bill validator](https://swiss-qr-invoice.org/validator/?lang=de) | ||
## Migration from v3 to v4 | ||
In SwissQRBill v4, large parts of the application have been rewritten to make the API more flexible. This means that you have to make some changes to your code when upgrading from v3 to v4. | ||
Please read the [migration guide](./docs/migration-v3-to-v4.md) to learn more about the changes and how to migrate your code. | ||
<br/> | ||
## Features | ||
@@ -60,0 +70,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19
8697
176
413009
5
+ Addedobject-inspect@1.13.2(transitive)
- Removedobject-inspect@1.13.3(transitive)
Updatedsvg-engine@^0.2.4