npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zimatech/swiss-qr-bill

v2.0.2

Published

Create QR bills in browser as PDFs or SVGs according to Swiss Payment Standards

Downloads

43

Readme

This file was auto-generated with zdoccer.js 2.0.3

Index


original Markdown from src/_preamble.md

@zimatech/swiss-qr-bill

Provides functions to create QR bills according to Swiss Payment Standards in browsers.

Features:

  • generates bills as SVG (210 x 110mm)
  • generates bills as PDF (A4)
  • optional input values validation
  • four languages: DE, FR, IT, EN

Usage

Example:

const qrBill = new SwissQrBill({
  creditor: {
    IBAN: 'CH5204835012345671000',
    creditor: {
      type: 'S',
      name: 'Stiftung Bessere Welt',
      streetOrLine1: 'Postfach',
      postCode: '3011',
      town: 'Bern',
      country: 'CH'
    }
  },
  amount: {
    currency: 'CHF',
    amount: 420.69
  },
  additional: {
    data: 'Rechnung 200',
  },
}, SwissQrBillLang.DE)

console.log(qrBill.getErrors())

qrBill.render2PDF('dataurlstring', {
  title: 'Swiss QR Bill',
  subject: 'Rechnung 200',
  author: 'ZimaTech GmbH',
  creator: 'ZimaTech GmbH'
}).then((data) => {
  const a = document.createElement('a')
  a.setAttribute('download', 'bill.pdf')
  a.setAttribute('href', data)
  a.click()
})

transformed Javadoc from src/swiss-qr-bill-format.ts

enum SwissQrBillFormat

Available output formats for QR bill

PerforatedPaper,

Bill will be printed on perforated paper, so no cut lines are drawn.

LinesWithScissors,

Bill will be electronicly transmitted. Include cut lines with scissor symbol.

LinesWithText,

Bill will be electronicly transmitted. Include cut lines with 'seperate before paying' text.

DashedLinesWithScissors,

Bill will be electronicly transmitted. Include dashed cut lines with scissor symbol.

DashedLinesWithText

Bill will be electronicly transmitted. Include dashed cut lines with 'seperate before paying' text.


transformed Javadoc from src/swiss-qr-bill-lang.ts

enum SwissQrBillLang

Available QR bill languages

DE,

Deutsch

FR,

Français

IT,

Italiano

EN

English


transformed Javadoc from src/swiss-qr-bill-validator.ts

class SwissQrBillValidator

Validator for QR bill values

constructor(values: SQBValues, lang: SwissQrBillLang = SwissQrBillLang.DE)

Creates validator with given values

  • param values — @param lang

public setValues(values: SQBValues, lang: SwissQrBillLang = SwissQrBillLang.DE)

Set new QR bill values

public getErrors(format: 'array'): SwissQrBillValidationError[]|null

Get errors in array format

public getErrors(format?: 'object'): Record<SwissQrBillKeys, SwissQrBillValidationError[]>|null

Get errors in object format

  • param format'object' or undefined
  • returns — object SwissQrBillKeys: SwissQrBillValidationError[] or null if no errors occured

interface SwissQrBillValidationError

Object definition for raised validation errors

field: SwissQrBillKeys

Descriptor of the field containing the error, e.g. 'amount.currency'

errno: SwissQrBillValidationErrno

Error number

error: string

Initial error message text

enum SwissQrBillValidationErrno

Validation error numbers

MayNotBeEmpty = 1000,

Value may not be empty

MustBeEmpty = 1001,

Value must be empty

TooLong = 9000,

Value was too long. The code won't be exactly 9000 but 9000 + maxLength

CountryCodeNotCHOrLI = 2000,

Value must contain CH or LI country code (i.e. an IBAN)

InvalidIBAN = 2001,

IBAN not valid, i.e. checksum fail or wrong length

InvalidAddressType = 3000,

Invalid address type specified

InvalidCountryCode = 3001,

Invalid country code

InvalidAmount = 4000,

Invalid amount, i.e. not in range 0.01 ... 999999999.99

InvalidCurrency = 4001,

Invalid currency, i.e. not 'CHF' or 'EUR'

InvalidReferenceType = 5000,

Invalid reference type specified

InvalidReference = 5001,

Invalid reference, i.e. checksum fail or wrong length

NotAQRIBAN = 5002

QR refernce used without QR IBAN


transformed Javadoc from src/swiss-qr-bill.ts

class SwissQrBill

QR bill class

constructor(values: SwissQrBillOptions, lang: SwissQrBillLang = SwissQrBillLang.DE)

Create QR bill with given values

public setValues(values: SwissQrBillOptions, lang: SwissQrBillLang = SwissQrBillLang.DE)

Updates QR bill values

public getErrors(format: 'array'): SwissQrBillValidationError[]|null

Get errors in array format

public getErrors(format?: 'object'): Record<SwissQrBillKeys, SwissQrBillValidationError[]>|null

Get errors in object format

  • param format'object' or undefined
  • returns — object SwissQrBillKeys: SwissQrBillValidationError[] or null if no errors occured

public render2PDF(output: 'arraybuffer'|'blob'|'dataurlstring'|'pdfobjectnewwindow', properties?: DocumentProperties, format: SwissQrBillFormat = SwissQrBillFormat.DashedLinesWithScissors): Promise<unknown>

Renders the QR bill to an A4 pdf

  • param output — what to output, either 'arraybufer', 'blob, 'dataurlstring' or 'pdfobjectnewwindow'
  • param properties — jsPDF DocumentProperties
  • param format — the format of the bill itself. See SwissQrBillFormat
  • returns — a promise resolving once the object is ready

public render2SVG(format: SwissQrBillFormat = SwissQrBillFormat.DashedLinesWithScissors): SVGElement

Renders the QR bill to a 210 x 110 mm svg

  • param format — the format of the bill itself. See SwissQrBillFormat
  • returnsSVGElement containing the QR bill

public getQRCode(): QRCode

Create qr code for this bill

  • returns — QRCode object

public getQRData(): string

Create qr code data for this bill

  • returns — string (CR+LF delimited) containing all data

public static friendlyFormatIBAN(iban: string): string

Format IBAN in human friendly way

  • param iban — IBAN
  • returns — formatted IBAN

public static machineFormatIBAN(iban: string): string

Removes spaces from human friendly formatted IBAN

  • param iban — formatted IBAN
  • returns — IBAN

public static friendlyFormatQRR(qrr: string): string

Format a QR reference in human friendly way

  • param qrr — QR reference
  • returns — formatted QR reference

public static machineFormatQRR(qrr: string): string

Removes spaces from human friendly formatted QR reference

  • param qrr — formatted QR reference
  • returns — QR reference

public static friendlyFormatSCOR(scor: string): string

Format a creditor reference in human friendly way

  • param scor — creditor reference
  • returns — formatted creditor reference

public static machineFormatSCOR(scor: string): string

Removes spaces from human friendly formatted creditor reference

  • param scor — formatted creditor reference
  • returns — creditor reference

public static friendlyFormatAmount(amount: string): string

Format amount in human friendly way

  • param amount — amount
  • returns — formatted amount

public static machineFormatAmount(amount: string): string

Removes spaces from human friendly formatted amount

  • param amount — formatted amount
  • returns — amount

interface SwissQrBillOptions

Options for SwissQrBill

creditor: SQBCreditorInfo // CdtrInf

SQBCreditorInfo object describing the creditor

amount?: SQBAmount // CcyAmt

optional SQBAmount object

debitor?: SQBAddress // UltmtDbtr

optional SQBAddress object describing the debitor

reference?: SQBReferenceInfo // RmtInf

optional SQBReferenceInfo object describing the reference

additional?: SQBAdditionalInfo // AddInf

optional SQBAdditionalInfo object describing additional qr bill information

alternative?: SQBAlternativeInfo // AltPmtInf

optional SQBAlternativeInfo object describing alternative qr bill billing methods

adviceOnly?: boolean

optional parameter for 'advice only' bills. If set to true, amount will be set to 0.00 and additional information will say DO NOT USE FOR PAYMENT

interface SQBCreditorInfo

Creditor information with IBAN and address

IBAN: string // IBAN

IBAN as string without spaces

creditor: SQBAddress // Cdtr

SQBAddress object of creditor

interface SQBAddress

Addresses

type: 'S'|'K' // AdrTp

Address type, either 'S' for structured or 'K' for combined

Note: Several e-Bankings convert combined addresses to structured addresses on scanning. Thus, prefer providing a structured address!

name: string // Name

Name

streetOrLine1?: string // StrtNmOrAdrLine1

  • for structured addresses: street name
  • for combined addresses: line 1 of address

buildingOrLine2?: string // BldgNbOrAdrLine2

  • for structured addresses: building number
  • for combined addresses: line 2 of address

postCode?: string // PstCd

  • for structured addresses: postal code
  • for combined addresses: to be left empty

town?: string // TwnNm

  • for structured addresses: town name
  • for combined addresses: to be left empty

country: string // Ctry

Country code i.e. 'CH'

interface SQBAmount

Amount and currency

amount?: number

Amount from 0.01 to 999999999.99

currency: 'CHF'|'EUR'

Currency, either 'CHF' or 'EUR'

interface SQBReferenceInfo

Reference information

type: 'QRR'|'SCOR'|'NON'

Type, either 'QRR' (QR reference), 'SCOR' (creditor reference) or 'NON' (none)

reference?: string

Reference

interface SQBAdditionalInfo

Additional information

data?: string

Additional payment information, free text, i.e. payment message

bankingInfo?: string

Banking information. Not transmitted.

interface SQBAlternativeInfo

Alternative payment information

parameter1?: string

Value 1, free text

parameter2?: string

Value 2, free text

type SwissQrBillKeys =

All valuable keys in SwissQrBillOptions