forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added pdf-fill-form's types (DefinitelyTyped#43608)
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "dtslint/dt.json" } |