Added typeing to the buffer and stream conversion

ref #3
This commit is contained in:
Nicolai Ort 2021-02-02 11:34:01 +01:00
parent 7d5b5750ad
commit 3fb8be22b7

View File

@ -1,6 +1,8 @@
import fs from "fs";
import pdf_converter from "html-pdf";
import path from 'path';
import { Stream } from 'stream';
/**
* This class is responsible for all things pdf creation.
* This uses the html templates from src/templates.
@ -17,6 +19,10 @@ export class PdfCreator {
}
/**
* This class is a wrapper for the pdf objects created by html-pdf.
* It offers typed conversion to Buffer and Stream.
*/
export class Pdf {
content: any;
@ -27,9 +33,9 @@ export class Pdf {
/**
* Promise wrapper function that resolves the toBuffer promise for pdf generation.
*/
public async toBuffer(): Promise<any> {
let promise = await new Promise((resolve, reject) => {
this.content.toBuffer(function (err, buffer) {
public async toBuffer(): Promise<Buffer> {
let promise = await new Promise<Buffer>((resolve, reject) => {
this.content.toBuffer(function (err, buffer: Buffer) {
resolve(buffer);
});
});
@ -39,9 +45,9 @@ export class Pdf {
/**
* Promise wrapper function that resolves the toStream promise for pdf generation.
*/
public async toStream(): Promise<any> {
let promise = await new Promise((resolve, reject) => {
this.content.toStream(function (err, stream) {
public async toStream(): Promise<Stream> {
let promise = await new Promise<Stream>((resolve, reject) => {
this.content.toStream(function (err, stream: Stream) {
resolve(stream);
});
});