Skip to content

Commit

Permalink
refactor: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
schoero committed Dec 14, 2022
1 parent 9b54515 commit dae6563
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 117 deletions.
12 changes: 7 additions & 5 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"@schoero/cspell-config"
],
"words": [
"swissqrbill",
"SCOR",
"iban",
"qriban",
"QRIBAN",
"QRIID",
"QRR",
"QRIBAN",
"qriban",
"iban"
"SCOR",
"swiss",
"swissqrbill",
"undash"
]
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
lib
src/shared/qr-code-generator.ts
!/.vscode
!/.github
18 changes: 8 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
"markdownlint:ci": "npm run markdownlint",
"markdownlint:fix": "node_modules/.bin/markdownlint-cli2-fix '**/*.md' '#node_modules'",
"postbuild": "sh fix-exports.sh",
"spellcheck": "node_modules/.bin/cspell lint",
"spellcheck:ci": "npm run spellcheck -- --no-progress",
"test": "node_modules/.bin/vitest -c ./vite.config.ts",
"test:legacy": "npm run build && cd tests && sh run.sh",
"test:update": "npm run test -- --update --run",
Expand All @@ -150,9 +152,9 @@
},
"devDependencies": {
"@schoero/cspell-config": "^1.5.0",
"@schoero/eslint-config": "^1.28.14",
"@schoero/eslint-config": "^1.28.15",
"@schoero/markdownlint-config": "^1.1.2",
"@schoero/ts-config": "^0.3.0",
"@schoero/ts-config": "^0.3.1",
"@types/blob-stream": "^0.1.30",
"@types/node": "^18.11.15",
"@types/svg-parser": "^2.0.3",
Expand Down
5 changes: 2 additions & 3 deletions src/browser/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import fs from "fs";

import BlobStream_ from "blob-stream";

//-- Register fonts for the bundled version
// @ts-expect-error
// @ts-expect-error - Import resolution does not work here
import Helvetica from "../../node_modules/pdfkit/js/data/Helvetica.afm";
// @ts-expect-error
// @ts-expect-error - Import resolution does not work here
import HelveticaBold from "../../node_modules/pdfkit/js/data/Helvetica-Bold.afm";
import * as types from "../shared/types.js";
import * as utils from "../shared/utils.js";
Expand Down
5 changes: 2 additions & 3 deletions src/browser/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ export import BlobStream = BlobStream_;

export class PDF extends PDF_ {

constructor(data: Data, writableStream: IBlobStream, options?: PDFOptions);
constructor(data: Data, writeableStream: IBlobStream, options?: PDFOptions, callback?: Function);
constructor(data: Data, writeableStream: IBlobStream, callback?: Function);
constructor(data: Data, writeableStream: IBlobStream, optionsOrCallback?: PDFOptions | Function, callbackOrUndefined?: Function | undefined) {
constructor(data: Data, writeableStream: IBlobStream, options?: PDFOptions, callback?: Function);
constructor(data: Data, writeableStream: IBlobStream, optionsOrCallback?: Function | PDFOptions, callbackOrUndefined?: Function | undefined) {

let callback: Function | undefined = undefined;
let options: PDFOptions | undefined = undefined;
Expand Down
8 changes: 2 additions & 6 deletions src/browser/svg.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { Data, SVGOptions } from "../shared/types.js";
import { SVG_ } from "../svg/svg.js";


export class SVG extends SVG_ {

constructor(data: Data, options?: SVGOptions) {
super(data, options);
}


/**
* Outputs the SVG as a string.
Expand All @@ -21,7 +16,8 @@ export class SVG extends SVG_ {

/**
* Returns the SVG element.
* > **Note:** This function is only available in the browser.
*
* **Note:** This function is only available in the browser.
*
* @readonly
*/
Expand Down
8 changes: 3 additions & 5 deletions src/node/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import { Data, PDFOptions } from "../shared/types.js";

export class PDF extends PDF_ {

constructor(data: Data, outputPath: string, options?: PDFOptions);
constructor(data: Data, writableStream: Writable, options?: PDFOptions);
constructor(data: Data, outputPath: string, options?: PDFOptions, callback?: Function);
constructor(data: Data, writableStream: Writable, options?: PDFOptions, callback?: Function);
constructor(data: Data, outputPath: string, callback?: Function);
constructor(data: Data, writableStream: Writable, callback?: Function);
constructor(data: Data, outputPathOrWritableStream: string | Writable, optionsOrCallback?: PDFOptions | Function, callbackOrUndefined?: Function | undefined) {
constructor(data: Data, outputPath: string, options?: PDFOptions, callback?: Function);
constructor(data: Data, writableStream: Writable, options?: PDFOptions, callback?: Function);
constructor(data: Data, outputPathOrWritableStream: Writable | string, optionsOrCallback?: Function | PDFOptions, callbackOrUndefined?: Function | undefined) {

let callback: Function | undefined = undefined;
let options: PDFOptions | undefined = undefined;
Expand Down
7 changes: 1 addition & 6 deletions src/node/svg.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { Data, SVGOptions } from "../shared/types.js";
import { SVG_ } from "../svg/svg.js";


export class SVG extends SVG_ {

constructor(data: Data, options?: SVGOptions) {
super(data, options);
}

public toString(): string {
public override toString(): string {
return this.outerHTML;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pdf/extended-pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class ExtendedPDF extends PDFDocument {
}


public switchToPage(n: number): PDFKit.PDFPage {
public override switchToPage(n: number): PDFKit.PDFPage {
const page = super.switchToPage(n);
this._currentPage = n;
return page;
Expand Down
6 changes: 3 additions & 3 deletions src/pdf/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class PDF_ extends ExtendedPDF {
this._data = data;


//-- Clean data (remove line breaks and unnecessary whitespaces)
//-- Clean data (remove line breaks and unnecessary white spaces)

this._data = cleanData(this._data);

Expand Down Expand Up @@ -82,7 +82,7 @@ export class PDF_ extends ExtendedPDF {
* @param options - An object containing [PDFKit document options.](https://pdfkit.org/docs/getting_started.html#adding_pages)
* @returns `this`
*/
public addPage(options?: PDFKit.PDFDocumentOptions): PDFKit.PDFDocument {
public override addPage(options?: PDFKit.PDFDocumentOptions): PDFKit.PDFDocument {

if(options === undefined){
options = {
Expand All @@ -97,7 +97,7 @@ export class PDF_ extends ExtendedPDF {
}


public end(): void {
public override end(): void {
this.emit("beforeEnd", this);
return super.end();
}
Expand Down
16 changes: 8 additions & 8 deletions src/shared/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ export function cleanData(data: Data): Data {
const keys = Object.keys(object);

for(let k = 0; k < keys.length; k++){
if(typeof object[keys[k]] === "string"){
if(typeof object[keys[k]!] === "string"){

object[keys[k]] = removeLinebreaks(object[keys[k]]);
object[keys[k]!] = removeLineBreaks(object[keys[k]!]);

if(keys[k] === "account"){
object[keys[k]] = object[keys[k]].replace(/ /g, "");
object[keys[k]!] = object[keys[k]!].replace(/ /g, "");
}
if(keys[k] === "reference"){
object[keys[k]] = object[keys[k]].replace(/ /g, "");
object[keys[k]!] = object[keys[k]!].replace(/ /g, "");
}
if(keys[k] === "country"){
object[keys[k]] = object[keys[k]].toUpperCase();
object[keys[k]!] = object[keys[k]!].toUpperCase();
}

} else {
if(typeof object[keys[k]] === "object"){
_cleanObject(object[keys[k]]);
if(typeof object[keys[k]!] === "object"){
_cleanObject(object[keys[k]!]);
}
}
}
Expand All @@ -38,7 +38,7 @@ export function cleanData(data: Data): Data {
}


export function removeLinebreaks(text: string): string {
export function removeLineBreaks(text: string): string {
return text.replace(/\n/g, "").replace(/\r/g, "");
}

Expand Down
27 changes: 17 additions & 10 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export interface Data {

/**
* Additional information. **Max 140 characters.**
* > Bill information contain coded information for automated booking of the payment. The data is not forwarded with the payment.
*
* Bill information contain coded information for automated booking of the payment. The data is not forwarded with the payment.
*/
additionalInformation?: string;

Expand All @@ -34,13 +35,15 @@ export interface Data {

/**
* 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.**
* > 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)
*/
av2?: string;

Expand All @@ -51,13 +54,15 @@ export interface Data {

/**
* 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.**
* > QR-IBAN: Maximum 27 characters. Must be filled if a QR-IBAN is used.
*
* QR-IBAN: Maximum 27 characters. Must be filled if a QR-IBAN is used.
* Creditor Reference (ISO 11649): Maximum 25 characters.
*/
reference?: string;
Expand Down Expand Up @@ -119,21 +124,23 @@ export interface PDFOptions {
language?: Languages;

/**
* Whether you want render the outlines. This option may be disabled if you use perforated paper.
* Whether you want render the outlines. This option may be disabled if you use perforated paper.
* @defaultValue `true`
*/
outlines?: boolean;

/**
* 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.
* 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.
* 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;
Expand Down
Loading

0 comments on commit dae6563

Please sign in to comment.