mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 15:00:26 +00:00
Added pdf-fill-form's types (#43608)
This commit is contained in:
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
// Type definitions for pdf-fill-form 5.0
|
||||
// Project: https://github.com/tpisto/pdf-fill-form#readme
|
||||
// Definitions by: Grégoire Lodi <https://github.com/lodi-g>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
/// <reference types="node" />
|
||||
|
||||
export interface WritableFields {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export type ReadableFields = Array<{
|
||||
name: string;
|
||||
page: number;
|
||||
value: string;
|
||||
id: number;
|
||||
type: string;
|
||||
}>;
|
||||
|
||||
export interface PdfOptions {
|
||||
save?: string;
|
||||
cores?: number;
|
||||
scale?: number;
|
||||
antialias?: boolean;
|
||||
}
|
||||
|
||||
export interface ImgPdfOptions extends PdfOptions {
|
||||
startPage?: number;
|
||||
endPage?: number;
|
||||
}
|
||||
|
||||
export type Options = PdfOptions | ImgPdfOptions;
|
||||
|
||||
export type WriteAsyncCallback = (err: Error, result: Buffer) => void;
|
||||
|
||||
export function read(sourceFile: string): Promise<ReadableFields>;
|
||||
export function readSync(sourceFile: string): ReadableFields;
|
||||
export function readBuffer(sourceBuffer: Buffer): Promise<ReadableFields>;
|
||||
export function readBufferSync(sourceBuffer: Buffer): ReadableFields;
|
||||
|
||||
export function write(sourceFile: string, fields: WritableFields, options?: Options): Promise<Buffer>;
|
||||
export function writeBuffer(sourceBuffer: Buffer, fields: WritableFields, options?: Options): Promise<Buffer>;
|
||||
export function writeBufferSync(sourceBuffer: Buffer, fields: WritableFields, options?: Options): Buffer;
|
||||
|
||||
// Options are not optional here because the callback MUST be defined to avoid a crash
|
||||
export function writeAsync(
|
||||
sourceFile: string,
|
||||
fields: WritableFields,
|
||||
options: Options,
|
||||
callback: WriteAsyncCallback,
|
||||
): void;
|
||||
@@ -0,0 +1,24 @@
|
||||
import { write, writeBuffer, read, readBuffer, writeAsync, ReadableFields } from 'pdf-fill-form';
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
const buffer = readFileSync('test.pdf');
|
||||
|
||||
async function main() {
|
||||
// Workaround because TS 3.9 resolves to ReadableFields and TS 3.6 to the object
|
||||
// $ExpectType ReadableFields || { name: string; page: number; value: string; id: number; type: string; }[]
|
||||
await read('./test.pdf');
|
||||
|
||||
// $ExpectType ReadableFields || { name: string; page: number; value: string; id: number; type: string; }[]
|
||||
await readBuffer(buffer);
|
||||
|
||||
// $ExpectType Buffer
|
||||
await write('test.pdf', { field: 'test' }, { save: 'pdf' });
|
||||
|
||||
// $ExpectType Buffer
|
||||
await writeBuffer(buffer, { otherField: '123' }, { save: 'imgpdf', antialias: true });
|
||||
|
||||
// $ExpectError
|
||||
await writeBuffer(buffer, { field: 123 });
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts", "pdf-fill-form-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user