Skip to content

Commit

Permalink
feat: adopt typescript declarations to new implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mojoaxel committed Dec 27, 2023
1 parent bcef7f4 commit 5623a60
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 21 deletions.
49 changes: 46 additions & 3 deletions browser.d.ts
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/mojoaxel/>
// Daniel Hammer <https://github.com/danmhammer/>
Expand All @@ -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<undefined>;
save(fileName: string): Promise<undefined>;
/**
* 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<void>}
*/
add(inputFile: PdfInput, pages?: string | string[] | number | number[] | undefined | null): Promise<undefined>;
/**
* Download the PDF as a file with the given name.
* The extension ".pdf" is appended automatically.
*
* @async
* @param {string} fileName
* @returns {Promise<void>}
*/
save(fileName: string): Promise<void>;
/**
* Return the merged PDF as a Uint8Array.
*
* @async
* @returns {Promise<Uint8Array>}
*/
saveAsBuffer(): Promise<Uint8Array>;
/**
* Return the merged PDF as a Blob.
*
* @async
* @returns {Promise<Blob>}
*/
saveAsBlob(): Promise<Blob>;
/**
* Set the metadata of the merged PDF.
*
* @async
* @param {Metadata} metadata
* @returns {Promise<void>}
*/
setMetadata(metadata: Metadata): Promise<void>;
}

export = PDFMerger;
}

declare type PdfInput = Uint8Array | ArrayBuffer | Blob | URL | File | String | string;

declare interface Metadata {
producer?: string
author?: string
Expand Down
42 changes: 39 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/mojoaxel/>

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<undefined>;
save(fileName: string): Promise<undefined>;
/**
* 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<void>}
*/
add(inputFile: PdfInput, pages?: string | string[] | number | number[] | undefined | null): Promise<void>;
/**
* Save the merged PDF to the given path.
*
* @async
* @param {string | PathLike} fileName
* @returns {Promise<void>}
*/
save(fileName: string): Promise<void>;
/**
* Return the merged PDF as a Buffer.
*
* @async
* @returns {Promise<Buffer>}
*/
saveAsBuffer(): Promise<Buffer>;
/**
* Set the metadata of the merged PDF.
*
* @async
* @param {Metadata} metadata
* @returns {Promise<void>}
*/
setMetadata(metadata: Metadata): Promise<void>;
}
export = PDFMerger;
}

declare type PdfInput = Uint8Array | ArrayBuffer | Blob | URL | Buffer | String | PathLike | string;

declare interface Metadata {
producer?: string
Expand Down
15 changes: 0 additions & 15 deletions types/index.d.ts

This file was deleted.

0 comments on commit 5623a60

Please sign in to comment.