Skip to content

Commit

Permalink
Separate data builder and QRcode generator
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-panteleev committed Jul 29, 2024
1 parent 628767e commit 857c62c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 108 deletions.
34 changes: 34 additions & 0 deletions src/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import QRCode from "qrcode";

import { DataUrl } from "../types/types";
import { TranslatableError } from "./error";


class QRCodeGenerator {

protected readonly inputString: string;

// TODO: make it configurable
protected readonly quality = {
margin: 1,
width: 500
}

public constructor(inputString: string) {
this.inputString = inputString;
}

public async generate(): Promise<DataUrl> {
try {
return QRCode.toDataURL(this.inputString, this.quality);
}
catch (e: unknown) {
throw new TranslatableError("generation.unknown_error")
}
}

}

export async function generateQR(inputString: string): Promise<DataUrl> {
return await (new QRCodeGenerator(inputString)).generate();
}
Empty file added src/models/data-builder.ts
Empty file.
108 changes: 0 additions & 108 deletions src/models/generator.ts

This file was deleted.

0 comments on commit 857c62c

Please sign in to comment.