diff --git a/types/hummus-recipe/hummus-recipe-tests.ts b/types/hummus-recipe/hummus-recipe-tests.ts index 2559b697f0..ad63542604 100644 --- a/types/hummus-recipe/hummus-recipe-tests.ts +++ b/types/hummus-recipe/hummus-recipe-tests.ts @@ -1,38 +1,44 @@ -import Recipe = require("hummus-recipe"); +import Recipe = require('hummus-recipe'); -import fs = require("fs"); +import fs = require('fs'); // $ExpectType Recipe -const newDoc = new Recipe("new", "test.pdf", { +const newDoc = new Recipe('new', 'test.pdf', { version: 1.6, - author: "John Doe", - title: "Hummus Recipe", - subject: "A brand new PDF" + author: 'John Doe', + title: 'Hummus Recipe', + subject: 'A brand new PDF', }); // $ExpectType Recipe newDoc .createPage(595, 842) - .text("Memento Mori", 100, 100) + .text('Memento Mori', 100, 100) .endPage() .endPDF(); // $ExpectError -newDoc.createPage("A5") - .text("Memento Mori", 100, 100) +newDoc.createPage('A5') + .text('Memento Mori', 100, 100) .endPage() .endPDF(); -const inBuffer: Buffer = fs.readFileSync("test.pdf"); +const inBuffer: Buffer = fs.readFileSync('test.pdf'); const bufferDoc = new Recipe(inBuffer); bufferDoc .createPage(595, 842) - .text("Memento Mori", 100, 100) + .text('Memento Mori', 100, 100) .endPage() .endPDF( (outBuffer: Buffer) => // $ExpectType Buffer - outBuffer + outBuffer, ); + +// $ExpectType Metadata +bufferDoc.metadata; + +// $ExpectType PageInfo +bufferDoc.metadata[1]; diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index 857dcb4187..42d31807d6 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for hummus-recipe 1.8 // Project: https://github.com/chunyenHuang/hummusRecipe // Definitions by: Erik Berreßem +// Sebastian Martinez // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 @@ -8,53 +9,46 @@ declare namespace Recipe { type CommentOptionsFlag = - | "invisible" - | "hidden" - | "print" - | "nozoom" - | "norotate" - | "noview" - | "readonly" - | "locked" - | "togglenoview"; + | 'invisible' + | 'hidden' + | 'print' + | 'nozoom' + | 'norotate' + | 'noview' + | 'readonly' + | 'locked' + | 'togglenoview'; type AnnotSubtype = - | "Text" - | "FreeText" - | "Line" - | "Square" - | "Circle" - | "Polygon" - | "PolyLine" - | "Highlight" - | "Underline" - | "Squiggly" - | "StrikeOut" - | "Stamp" - | "Caret" - | "Ink" - | "FileAttachment" - | "Sound"; + | 'Text' + | 'FreeText' + | 'Line' + | 'Square' + | 'Circle' + | 'Polygon' + | 'PolyLine' + | 'Highlight' + | 'Underline' + | 'Squiggly' + | 'StrikeOut' + | 'Stamp' + | 'Caret' + | 'Ink' + | 'FileAttachment' + | 'Sound'; type AnnotOptionsFlag = - | "invisible" - | "hidden" - | "print" - | "nozoom" - | "norotate" - | "noview" - | "readonly" - | "locked" - | "togglenoview"; + | 'invisible' + | 'hidden' + | 'print' + | 'nozoom' + | 'norotate' + | 'noview' + | 'readonly' + | 'locked' + | 'togglenoview'; - type AnnotOptionsIcon = - | "Comment" - | "Key" - | "Note" - | "Help" - | "NewParagraph" - | "Paragraph" - | "Insert"; + type AnnotOptionsIcon = 'Comment' | 'Key' | 'Note' | 'Help' | 'NewParagraph' | 'Paragraph' | 'Insert'; interface RecipeOptions { version?: number; @@ -189,6 +183,23 @@ declare namespace Recipe { rotationOrigin?: number[]; } + interface PageInfo { + pageNumber: number; + mediaBox: number[]; + layout: string; + rotate: number; + width: number; + height: number; + size: number[]; + offsetX: number; + offsetY: number; + } + + interface Metadata { + pages: number; + [PagesIndex: number]: PageInfo; + } + type EndPDFCallback1 = () => any; type EndPDFCallback2 = (buffer: Buffer) => any; type EndPDFCallback = EndPDFCallback1 | EndPDFCallback2; @@ -199,19 +210,11 @@ declare class Recipe { constructor(buffer: Buffer, options?: Recipe.RecipeOptions); - comment( - text: string, - x: number, - y: number, - options?: Recipe.CommentOptions - ): Recipe; + readonly metadata: Recipe.Metadata; - annot( - x: number, - y: number, - subtype: Recipe.AnnotSubtype, - options?: Recipe.AnnotOptions - ): Recipe; + comment(text: string, x: number, y: number, options?: Recipe.CommentOptions): Recipe; + + annot(x: number, y: number, subtype: Recipe.AnnotSubtype, options?: Recipe.AnnotOptions): Recipe; appendPage(pdfSrc: string, pages: number | number[]): Recipe; @@ -219,29 +222,15 @@ declare class Recipe { registerFont(fontName: string, fontSrcPath: string): Recipe; - image( - imgSrc: string, - x: number, - y: number, - options?: Recipe.ImageOptions - ): Recipe; + image(imgSrc: string, x: number, y: number, options?: Recipe.ImageOptions): Recipe; info(options?: Recipe.InfoOptions): Recipe; custom(key?: string, value?: string): Recipe; - insertPage( - afterPageNumber: number, - pdfSrc: string, - srcPageNumber: number - ): Recipe; + insertPage(afterPageNumber: number, pdfSrc: string, srcPageNumber: number): Recipe; - overlay( - pdfSrc: string, - x: number, - y: number, - options?: Recipe.OverlayOptions - ): Recipe; + overlay(pdfSrc: string, x: number, y: number, options?: Recipe.OverlayOptions): Recipe; createPage(pageWidth: number, pageHeight: number): Recipe; @@ -253,12 +242,7 @@ declare class Recipe { split(outputDir: string, prefix: string): Recipe; - text( - text: string, - x: number, - y: number, - options?: Recipe.TextOptions - ): Recipe; + text(text: string, x: number, y: number, options?: Recipe.TextOptions): Recipe; moveTo(x: number, y: number): Recipe; @@ -268,20 +252,9 @@ declare class Recipe { polygon(coordinates: number[][], options?: Recipe.PolygonOptions): Recipe; - circle( - x: number, - y: number, - radius: number, - options?: Recipe.CircleOptions - ): Recipe; + circle(x: number, y: number, radius: number, options?: Recipe.CircleOptions): Recipe; - rectangle( - x: number, - y: number, - width: number, - height: number, - options?: Recipe.RectangleOptions - ): Recipe; + rectangle(x: number, y: number, width: number, height: number, options?: Recipe.RectangleOptions): Recipe; endPDF(callback?: Recipe.EndPDFCallback): Recipe; }