mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Added types for react-native-pdf-lib (#37314)
* Added types for react-native-pdf-lib. * Making linter happy with default export.
This commit is contained in:
parent
57cfe86813
commit
388b2e06bd
57
types/react-native-pdf-lib/index.d.ts
vendored
Normal file
57
types/react-native-pdf-lib/index.d.ts
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
// Type definitions for react-native-pdf-lib 0.2
|
||||
// Project: https://github.com/Hopding/react-native-pdf-lib#readme
|
||||
// Definitions by: Kevin Brown <https://github.com/thekevinbrown>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare let PDFLib: {
|
||||
getDocumentsDirectory(): string;
|
||||
};
|
||||
|
||||
export default PDFLib;
|
||||
|
||||
export class PDFDocument {
|
||||
static create(path: string): PDFDocument;
|
||||
|
||||
addPages(pages: PDFPage[]): PDFDocument;
|
||||
|
||||
/* Saves the document and returns the path to the file it wrote */
|
||||
write(): Promise<string>;
|
||||
}
|
||||
|
||||
export interface SetMediaBoxOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
}
|
||||
|
||||
export interface TextDrawingOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
color?: string;
|
||||
fontName?: string;
|
||||
fontSize?: number;
|
||||
}
|
||||
|
||||
export interface RectangleDrawingOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
export interface ImageDrawingOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
}
|
||||
|
||||
export class PDFPage {
|
||||
static create(): PDFPage;
|
||||
|
||||
setMediaBox(width: number, height: number, options?: SetMediaBoxOptions): PDFPage;
|
||||
|
||||
drawText(text: string, options?: TextDrawingOptions): PDFPage;
|
||||
drawRectangle(options?: RectangleDrawingOptions): PDFPage;
|
||||
drawImage(imageUri: string, options?: ImageDrawingOptions): PDFPage;
|
||||
}
|
||||
29
types/react-native-pdf-lib/react-native-pdf-lib-tests.ts
Normal file
29
types/react-native-pdf-lib/react-native-pdf-lib-tests.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import PDFLib, { PDFDocument, PDFPage } from 'react-native-pdf-lib';
|
||||
|
||||
PDFLib.getDocumentsDirectory(); // $ExpectType string
|
||||
|
||||
// Document Tests
|
||||
PDFDocument.create('/some/path'); // $ExpectType PDFDocument
|
||||
|
||||
const document = PDFDocument.create('/some/path');
|
||||
document.addPages([PDFPage.create()]); // $ExpectType PDFDocument
|
||||
document.write(); // $ExpectType Promise<string>
|
||||
|
||||
// Page Tests
|
||||
PDFPage.create(); // $ExpectType PDFPage
|
||||
|
||||
const page = PDFPage.create();
|
||||
page.setMediaBox(10, 10); // $ExpectType PDFPage
|
||||
page.setMediaBox(10, 10, { x: 10, y: 10 }); // $ExpectType PDFPage
|
||||
|
||||
page.drawRectangle(); // $ExpectType PDFPage
|
||||
page.drawRectangle({}); // $ExpectType PDFPage
|
||||
page.drawRectangle({ x: 10, y: 10, width: 10, height: 10, color: '#fff' }); // $ExpectType PDFPage
|
||||
|
||||
page.drawImage('ph:/some/uri'); // $ExpectType PDFPage
|
||||
page.drawImage('ph:/some/uri', {}); // $ExpectType PDFPage
|
||||
page.drawImage('ph:/some/uri', { x: 10, y: 10, width: 10, height: 10 }); // $ExpectType PDFPage
|
||||
|
||||
page.drawText('Some string'); // $ExpectType PDFPage
|
||||
page.drawText('Some string', {}); // $ExpectType PDFPage
|
||||
page.drawText('Some string', { x: 10, y: 10, color: '#fff', fontName: 'TimesNewRoman', fontSize: 10 }); // $ExpectType PDFPage
|
||||
23
types/react-native-pdf-lib/tsconfig.json
Normal file
23
types/react-native-pdf-lib/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-native-pdf-lib-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/react-native-pdf-lib/tslint.json
Normal file
1
types/react-native-pdf-lib/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user