From 5623a60d3e81f6992095cfaff2687a8b297b5772 Mon Sep 17 00:00:00 2001 From: Alexander Wunschik Date: Wed, 27 Dec 2023 15:19:17 +0100 Subject: [PATCH] feat: adopt typescript declarations to new implementation --- browser.d.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++--- index.d.ts | 42 ++++++++++++++++++++++++++++++++++++++--- types/index.d.ts | 15 --------------- 3 files changed, 85 insertions(+), 21 deletions(-) delete mode 100644 types/index.d.ts diff --git a/browser.d.ts b/browser.d.ts index 81b982e..d6495a4 100644 --- a/browser.d.ts +++ b/browser.d.ts @@ -1,4 +1,4 @@ -// Type definitions for pdf-merger-js v4.2.0 +// Type definitions for pdf-merger-js v5.0.0 // Project: https://github.com/nbesli/pdf-merger-js // Definitions by: Alexander Wunschik // Daniel Hammer @@ -7,16 +7,59 @@ declare module "pdf-merger-js/browser" { class PDFMerger { constructor(); - add(inputFile: string | Uint8Array | ArrayBuffer | Blob | File, pages?: string | string[] | undefined | null): Promise; - save(fileName: string): Promise; + /** + * Resets the internal state of the document, to start again. + * + * @returns {void} + */ + reset(): void; + /** + * Add pages from a PDF document to the end of the merged document. + * + * @async + * @param {PdfInput} input - a pdf source + * @param {string | string[] | number | number[] | undefined | null} [pages] + * @returns {Promise} + */ + add(inputFile: PdfInput, pages?: string | string[] | number | number[] | undefined | null): Promise; + /** + * Download the PDF as a file with the given name. + * The extension ".pdf" is appended automatically. + * + * @async + * @param {string} fileName + * @returns {Promise} + */ + save(fileName: string): Promise; + /** + * Return the merged PDF as a Uint8Array. + * + * @async + * @returns {Promise} + */ saveAsBuffer(): Promise; + /** + * Return the merged PDF as a Blob. + * + * @async + * @returns {Promise} + */ saveAsBlob(): Promise; + /** + * Set the metadata of the merged PDF. + * + * @async + * @param {Metadata} metadata + * @returns {Promise} + */ setMetadata(metadata: Metadata): Promise; } export = PDFMerger; } +declare type PdfInput = Uint8Array | ArrayBuffer | Blob | URL | File | String | string; + declare interface Metadata { producer?: string author?: string diff --git a/index.d.ts b/index.d.ts index 7b87b7c..da708e3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,19 +1,55 @@ -// Type definitions for pdf-merger-js v4.2.1+ +// Type definitions for pdf-merger-js v5.0.0 // Project: https://github.com/nbesli/pdf-merger-js // Definitions by: Alexander Wunschik +import { PathLike } from "fs-extra"; + declare module "pdf-merger-js" { class PDFMerger { constructor(); + /** + * Resets the internal state of the document, to start again. + * + * @returns {void} + */ reset(): void; - add(inputFile: string | Buffer | ArrayBuffer, pages?: string | string[] | undefined | null): Promise; - save(fileName: string): Promise; + /** + * Add pages from a PDF document to the end of the merged document. + * + * @async + * @param {PdfInput} input - a pdf source + * @param {string | string[] | number | number[] | undefined | null} [pages] + * @returns {Promise} + */ + add(inputFile: PdfInput, pages?: string | string[] | number | number[] | undefined | null): Promise; + /** + * Save the merged PDF to the given path. + * + * @async + * @param {string | PathLike} fileName + * @returns {Promise} + */ + save(fileName: string): Promise; + /** + * Return the merged PDF as a Buffer. + * + * @async + * @returns {Promise} + */ saveAsBuffer(): Promise; + /** + * Set the metadata of the merged PDF. + * + * @async + * @param {Metadata} metadata + * @returns {Promise} + */ setMetadata(metadata: Metadata): Promise; } export = PDFMerger; } +declare type PdfInput = Uint8Array | ArrayBuffer | Blob | URL | Buffer | String | PathLike | string; declare interface Metadata { producer?: string diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100644 index 56bec63..0000000 --- a/types/index.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -export = PDFMerger; -declare class PDFMerger { - /** - * Resets the internal PDFDocument. - * Call this method if you want to start merging a new document. - * - * @returns {void} - */ - reset(): void; - add(inputFile: any, pages: any): Promise; - setMetadata(metadata: any): Promise; - save(fileName: any): Promise; - saveAsBuffer(): Promise; - #private; -}