From 6921ab60c420524e3fd0a130e29062b02983318d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Wed, 3 Apr 2019 13:29:29 +0200 Subject: [PATCH 1/9] :label: Add typings for 'hummus-recipe' --- types/hummus-recipe/hummus-recipe-tests.ts | 21 + types/hummus-recipe/index.d.ts | 550 +++++++++++++++++++++ types/hummus-recipe/tsconfig.json | 22 + types/hummus-recipe/tslint.json | 1 + 4 files changed, 594 insertions(+) create mode 100644 types/hummus-recipe/hummus-recipe-tests.ts create mode 100644 types/hummus-recipe/index.d.ts create mode 100644 types/hummus-recipe/tsconfig.json create mode 100644 types/hummus-recipe/tslint.json diff --git a/types/hummus-recipe/hummus-recipe-tests.ts b/types/hummus-recipe/hummus-recipe-tests.ts new file mode 100644 index 0000000000..ce6139260f --- /dev/null +++ b/types/hummus-recipe/hummus-recipe-tests.ts @@ -0,0 +1,21 @@ +import * as HummusRecipe from 'hummus-recipe'; + +// $ExpectType HummusRecipe +const pdf = new HummusRecipe('new', 'test.pdf', { + version: 1.6, + author: 'John Doe', + title: 'Hummus Recipe', + subject: 'A brand new PDF', +}); + +// $ExpectType HummusRecipe +pdf.createPage(595, 842) + .text('Memento Mori', 100, 100) + .endPage() + .endPDF(); + +// $ExpectError +pdf.createPage('A4') + .text('Memento Mori', 100, 100) + .endPage() + .endPDF(); diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts new file mode 100644 index 0000000000..e1f1bee06f --- /dev/null +++ b/types/hummus-recipe/index.d.ts @@ -0,0 +1,550 @@ +// Type definitions for hummus-recipe 1.8 +// Project: https://github.com/chunyenHuang/hummusRecipe +// Definitions by: Erik Berreßem +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * @name HummusRecipe + * @namespace + */ +declare namespace HummusRecipe { + export interface IRecipeOptions { + version?: number + author?: string + title?: string + subject?: string + keywords?: string[] + } + + export interface ICommentOptions { + title?: string + date?: string + open?: boolean + richText?: boolean + flag?: + | 'invisible' + | 'hidden' + | 'print' + | 'nozoom' + | 'norotate' + | 'noview' + | 'readonly' + | 'locked' + | 'togglenoview' + } + + export interface IAnotOptions { + title?: string + open?: boolean + richText?: boolean + flag?: + | 'invisible' + | 'hidden' + | 'print' + | 'nozoom' + | 'norotate' + | 'noview' + | 'readonly' + | 'locked' + | 'togglenoview' + icon?: 'Comment' | 'Key' | 'Note' | 'Help' | 'NewParagraph' | 'Paragraph' | 'Insert' + width?: number + height?: number + } + + export interface IEncryptOptions { + password?: string + ownerPassword?: string + userProtectionFlag?: number + } + + export interface IImageOptions { + width?: number + height?: number + scale?: number + keepAspectRatio?: boolean + opacity?: number + align?: string + } + + export interface IInfoOptions { + version?: string + author?: string + title?: string + subject?: string + keywords?: string[] + } + + export interface IOverlayOptions { + scale?: number + keepAspectRatio?: boolean + fitWidth?: boolean + fitHeight?: boolean + } + + export interface ITextBoxStyle { + lineWidth?: number + stroke?: string | number[] + dash?: number[] + fill?: string | number[] + opacity?: number + } + + export interface ITextBox { + width?: number + height?: number + minHeight?: number + padding?: number | number[] + lineHeight?: number + textAlign?: string + style?: ITextBoxStyle + } + + export interface ITextOptions { + color?: string | number[] + opacity?: number + rotation?: number + rotationOrigin?: number[] + font?: string + size?: number + align?: string + highlight?: Object | Boolean + underline?: Object | Boolean + strikeOut?: Object | Boolean + textBox?: ITextBox + } + + export interface ILineToOptions { + color?: string | number[] + stroke?: string | number[] + fill?: string | number[] + lineWidth?: number + opacity?: number + dash?: number[] + } + + export interface ILineOptions { + color?: string | number[] + stroke?: string | number[] + lineWidth?: number + dash?: number[] + } + + export interface IPolygonOptions { + color?: string | number[] + stroke?: string | number[] + fill?: string | number[] + lineWidth?: number + opacity?: number + dash?: number[] + } + + export interface ICircleOptions { + color?: string | number[] + stroke?: string | number[] + fill?: string | number[] + lineWidth?: number + opacity?: number + dash?: number[] + } + + export interface IRactangleOptions { + color?: string | number[] + stroke?: string | number[] + fill?: string | number[] + lineWidth?: number + opacity?: number + dash?: number[] + rotation?: number + rotationOrigin?: number[] + } +} + +/** + * @name HummusRecipe + * @class + */ +declare class HummusRecipe { + /** + * @name HummusRecipe + * @desc Create a pdfDoc + * @constructor + * @memberof HummusRecipe + * @param {string} src - The file path or Buffer of the src file. + * @param {string} output - The path of the output file. + * @param {Object} [options] - The options for pdfDoc + * @param {number} [options.version] - The pdf version + * @param {string} [options.author] - The author + * @param {string} [options.title] - The title + * @param {string} [options.subject] - The subject + * @param {string[]} [options.keywords] - The array of keywords + */ + constructor(src: string, output: string, options?: HummusRecipe.IRecipeOptions) + + /** + * Create a comment annotation + * @name comment + * @function + * @memberof HummusRecipe + * @param {string} text - The text content + * @param {number} x - The coordinate x + * @param {number} y - The coordinate y + * @param {Object} [options] - The options + * @param {string} [options.title] - The title. + * @param {string} [options.date] - The date. + * @param {boolean} [options.open=false] - Open the annotation by default? + * @param {boolean} [options.richText] - Display with rich text format, text will be transformed automatically, or you may pass in your own rich text starts with " Date: Wed, 3 Apr 2019 13:37:20 +0200 Subject: [PATCH 2/9] Correct a strictFunctionTypes --- types/hummus-recipe/tsconfig.json | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/types/hummus-recipe/tsconfig.json b/types/hummus-recipe/tsconfig.json index 019227622f..a3a5f57e26 100644 --- a/types/hummus-recipe/tsconfig.json +++ b/types/hummus-recipe/tsconfig.json @@ -1,22 +1,16 @@ { "compilerOptions": { "module": "commonjs", - "lib": [ - "es6" - ], + "lib": ["es6"], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "baseUrl": "../", - "typeRoots": [ - "../" - ], + "typeRoots": ["../"], "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true }, - "files": [ - "index.d.ts", - "hummus-recipe-tests.ts" - ] + "files": ["index.d.ts", "hummus-recipe-tests.ts"] } From a562dc7568d2b631cc31576c29f3092f62a75f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Wed, 3 Apr 2019 13:44:58 +0200 Subject: [PATCH 3/9] :fire: Remove jsdoc and unneeded exports --- types/hummus-recipe/index.d.ts | 327 ++------------------------------- 1 file changed, 15 insertions(+), 312 deletions(-) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index e1f1bee06f..5f71b5a19d 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -3,12 +3,8 @@ // Definitions by: Erik Berreßem // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/** - * @name HummusRecipe - * @namespace - */ declare namespace HummusRecipe { - export interface IRecipeOptions { + interface IRecipeOptions { version?: number author?: string title?: string @@ -16,7 +12,7 @@ declare namespace HummusRecipe { keywords?: string[] } - export interface ICommentOptions { + interface ICommentOptions { title?: string date?: string open?: boolean @@ -33,7 +29,7 @@ declare namespace HummusRecipe { | 'togglenoview' } - export interface IAnotOptions { + interface IAnotOptions { title?: string open?: boolean richText?: boolean @@ -52,13 +48,13 @@ declare namespace HummusRecipe { height?: number } - export interface IEncryptOptions { + interface IEncryptOptions { password?: string ownerPassword?: string userProtectionFlag?: number } - export interface IImageOptions { + interface IImageOptions { width?: number height?: number scale?: number @@ -67,7 +63,7 @@ declare namespace HummusRecipe { align?: string } - export interface IInfoOptions { + interface IInfoOptions { version?: string author?: string title?: string @@ -75,14 +71,14 @@ declare namespace HummusRecipe { keywords?: string[] } - export interface IOverlayOptions { + interface IOverlayOptions { scale?: number keepAspectRatio?: boolean fitWidth?: boolean fitHeight?: boolean } - export interface ITextBoxStyle { + interface ITextBoxStyle { lineWidth?: number stroke?: string | number[] dash?: number[] @@ -90,7 +86,7 @@ declare namespace HummusRecipe { opacity?: number } - export interface ITextBox { + interface ITextBox { width?: number height?: number minHeight?: number @@ -100,7 +96,7 @@ declare namespace HummusRecipe { style?: ITextBoxStyle } - export interface ITextOptions { + interface ITextOptions { color?: string | number[] opacity?: number rotation?: number @@ -114,7 +110,7 @@ declare namespace HummusRecipe { textBox?: ITextBox } - export interface ILineToOptions { + interface ILineToOptions { color?: string | number[] stroke?: string | number[] fill?: string | number[] @@ -123,14 +119,14 @@ declare namespace HummusRecipe { dash?: number[] } - export interface ILineOptions { + interface ILineOptions { color?: string | number[] stroke?: string | number[] lineWidth?: number dash?: number[] } - export interface IPolygonOptions { + interface IPolygonOptions { color?: string | number[] stroke?: string | number[] fill?: string | number[] @@ -139,7 +135,7 @@ declare namespace HummusRecipe { dash?: number[] } - export interface ICircleOptions { + interface ICircleOptions { color?: string | number[] stroke?: string | number[] fill?: string | number[] @@ -148,7 +144,7 @@ declare namespace HummusRecipe { dash?: number[] } - export interface IRactangleOptions { + interface IRactangleOptions { color?: string | number[] stroke?: string | number[] fill?: string | number[] @@ -160,42 +156,9 @@ declare namespace HummusRecipe { } } -/** - * @name HummusRecipe - * @class - */ declare class HummusRecipe { - /** - * @name HummusRecipe - * @desc Create a pdfDoc - * @constructor - * @memberof HummusRecipe - * @param {string} src - The file path or Buffer of the src file. - * @param {string} output - The path of the output file. - * @param {Object} [options] - The options for pdfDoc - * @param {number} [options.version] - The pdf version - * @param {string} [options.author] - The author - * @param {string} [options.title] - The title - * @param {string} [options.subject] - The subject - * @param {string[]} [options.keywords] - The array of keywords - */ constructor(src: string, output: string, options?: HummusRecipe.IRecipeOptions) - /** - * Create a comment annotation - * @name comment - * @function - * @memberof HummusRecipe - * @param {string} text - The text content - * @param {number} x - The coordinate x - * @param {number} y - The coordinate y - * @param {Object} [options] - The options - * @param {string} [options.title] - The title. - * @param {string} [options.date] - The date. - * @param {boolean} [options.open=false] - Open the annotation by default? - * @param {boolean} [options.richText] - Display with rich text format, text will be transformed automatically, or you may pass in your own rich text starts with " Date: Wed, 3 Apr 2019 13:51:04 +0200 Subject: [PATCH 4/9] :rotating_light: Correct semicolons --- types/hummus-recipe/index.d.ts | 337 ++++++++++++++++++--------------- 1 file changed, 186 insertions(+), 151 deletions(-) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index 5f71b5a19d..ad2cfbba93 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -5,249 +5,284 @@ declare namespace HummusRecipe { interface IRecipeOptions { - version?: number - author?: string - title?: string - subject?: string - keywords?: string[] + version?: number; + author?: string; + title?: string; + subject?: string; + keywords?: string[]; } interface ICommentOptions { - title?: string - date?: string - open?: boolean - richText?: boolean + title?: string; + date?: string; + open?: boolean; + richText?: boolean; flag?: - | 'invisible' - | 'hidden' - | 'print' - | 'nozoom' - | 'norotate' - | 'noview' - | 'readonly' - | 'locked' - | 'togglenoview' + | "invisible" + | "hidden" + | "print" + | "nozoom" + | "norotate" + | "noview" + | "readonly" + | "locked" + | "togglenoview"; } interface IAnotOptions { - title?: string - open?: boolean - richText?: boolean + title?: string; + open?: boolean; + richText?: boolean; flag?: - | 'invisible' - | 'hidden' - | 'print' - | 'nozoom' - | 'norotate' - | 'noview' - | 'readonly' - | 'locked' - | 'togglenoview' - icon?: 'Comment' | 'Key' | 'Note' | 'Help' | 'NewParagraph' | 'Paragraph' | 'Insert' - width?: number - height?: number + | "invisible" + | "hidden" + | "print" + | "nozoom" + | "norotate" + | "noview" + | "readonly" + | "locked" + | "togglenoview"; + icon?: + | "Comment" + | "Key" + | "Note" + | "Help" + | "NewParagraph" + | "Paragraph" + | "Insert"; + width?: number; + height?: number; } interface IEncryptOptions { - password?: string - ownerPassword?: string - userProtectionFlag?: number + password?: string; + ownerPassword?: string; + userProtectionFlag?: number; } interface IImageOptions { - width?: number - height?: number - scale?: number - keepAspectRatio?: boolean - opacity?: number - align?: string + width?: number; + height?: number; + scale?: number; + keepAspectRatio?: boolean; + opacity?: number; + align?: string; } interface IInfoOptions { - version?: string - author?: string - title?: string - subject?: string - keywords?: string[] + version?: string; + author?: string; + title?: string; + subject?: string; + keywords?: string[]; } interface IOverlayOptions { - scale?: number - keepAspectRatio?: boolean - fitWidth?: boolean - fitHeight?: boolean + scale?: number; + keepAspectRatio?: boolean; + fitWidth?: boolean; + fitHeight?: boolean; } interface ITextBoxStyle { - lineWidth?: number - stroke?: string | number[] - dash?: number[] - fill?: string | number[] - opacity?: number + lineWidth?: number; + stroke?: string | number[]; + dash?: number[]; + fill?: string | number[]; + opacity?: number; } interface ITextBox { - width?: number - height?: number - minHeight?: number - padding?: number | number[] - lineHeight?: number - textAlign?: string - style?: ITextBoxStyle + width?: number; + height?: number; + minHeight?: number; + padding?: number | number[]; + lineHeight?: number; + textAlign?: string; + style?: ITextBoxStyle; } interface ITextOptions { - color?: string | number[] - opacity?: number - rotation?: number - rotationOrigin?: number[] - font?: string - size?: number - align?: string - highlight?: Object | Boolean - underline?: Object | Boolean - strikeOut?: Object | Boolean - textBox?: ITextBox + color?: string | number[]; + opacity?: number; + rotation?: number; + rotationOrigin?: number[]; + font?: string; + size?: number; + align?: string; + highlight?: Object | Boolean; + underline?: Object | Boolean; + strikeOut?: Object | Boolean; + textBox?: ITextBox; } interface ILineToOptions { - color?: string | number[] - stroke?: string | number[] - fill?: string | number[] - lineWidth?: number - opacity?: number - dash?: number[] + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; } interface ILineOptions { - color?: string | number[] - stroke?: string | number[] - lineWidth?: number - dash?: number[] + color?: string | number[]; + stroke?: string | number[]; + lineWidth?: number; + dash?: number[]; } interface IPolygonOptions { - color?: string | number[] - stroke?: string | number[] - fill?: string | number[] - lineWidth?: number - opacity?: number - dash?: number[] + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; } interface ICircleOptions { - color?: string | number[] - stroke?: string | number[] - fill?: string | number[] - lineWidth?: number - opacity?: number - dash?: number[] + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; } interface IRactangleOptions { - color?: string | number[] - stroke?: string | number[] - fill?: string | number[] - lineWidth?: number - opacity?: number - dash?: number[] - rotation?: number - rotationOrigin?: number[] + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; + rotation?: number; + rotationOrigin?: number[]; } } declare class HummusRecipe { - constructor(src: string, output: string, options?: HummusRecipe.IRecipeOptions) + constructor( + src: string, + output: string, + options?: HummusRecipe.IRecipeOptions + ); comment( text: string, x: number, y: number, - options?: HummusRecipe.ICommentOptions, - ): HummusRecipe + options?: HummusRecipe.ICommentOptions + ): HummusRecipe; annot( x: number, y: number, subtype: - | 'Text' - | 'FreeText' - | 'Line' - | 'Square' - | 'Circle' - | 'Polygon' - | 'PolyLine' - | 'Highlight' - | 'Underline' - | 'Squiggly' - | 'StrikeOut' - | 'Stamp' - | 'Caret' - | 'Ink' - | 'FileAttachment' - | 'Sound', - options?: HummusRecipe.IAnotOptions, - ): HummusRecipe + | "Text" + | "FreeText" + | "Line" + | "Square" + | "Circle" + | "Polygon" + | "PolyLine" + | "Highlight" + | "Underline" + | "Squiggly" + | "StrikeOut" + | "Stamp" + | "Caret" + | "Ink" + | "FileAttachment" + | "Sound", + options?: HummusRecipe.IAnotOptions + ): HummusRecipe; - appendPage(pdfSrc: string, pages: number | number[]): HummusRecipe + appendPage(pdfSrc: string, pages: number | number[]): HummusRecipe; - encrypt(options: HummusRecipe.IEncryptOptions): HummusRecipe + encrypt(options: HummusRecipe.IEncryptOptions): HummusRecipe; - registerFont(fontName: string, fontSrcPath: string): HummusRecipe + registerFont(fontName: string, fontSrcPath: string): HummusRecipe; - image(imgSrc: string, x: number, y: number, options?: HummusRecipe.IImageOptions): HummusRecipe + image( + imgSrc: string, + x: number, + y: number, + options?: HummusRecipe.IImageOptions + ): HummusRecipe; - info(options?: HummusRecipe.IInfoOptions): HummusRecipe + info(options?: HummusRecipe.IInfoOptions): HummusRecipe; - custom(key?: string, value?: string): HummusRecipe + custom(key?: string, value?: string): HummusRecipe; - insertPage(afterPageNumber: number, pdfSrc: string, srcPageNumber: number): HummusRecipe + insertPage( + afterPageNumber: number, + pdfSrc: string, + srcPageNumber: number + ): HummusRecipe; overlay( pdfSrc: string, x: number, y: number, - options?: HummusRecipe.IOverlayOptions, - ): HummusRecipe + options?: HummusRecipe.IOverlayOptions + ): HummusRecipe; - createPage(pageWidth: number, pageHeight: number): HummusRecipe + createPage(pageWidth: number, pageHeight: number): HummusRecipe; - endPage(): HummusRecipe + endPage(): HummusRecipe; - editPage(pageNumber: number): HummusRecipe + editPage(pageNumber: number): HummusRecipe; - pageInfo(pageNumber: number): HummusRecipe + pageInfo(pageNumber: number): HummusRecipe; - split(outputDir: string, prefix: string): HummusRecipe + split(outputDir: string, prefix: string): HummusRecipe; - text(text: string, x: number, y: number, options?: HummusRecipe.ITextOptions): HummusRecipe + text( + text: string, + x: number, + y: number, + options?: HummusRecipe.ITextOptions + ): HummusRecipe; - moveTo(x: number, y: number): HummusRecipe + moveTo(x: number, y: number): HummusRecipe; - lineTo(x: number, y: number, options?: HummusRecipe.ILineToOptions): HummusRecipe + lineTo( + x: number, + y: number, + options?: HummusRecipe.ILineToOptions + ): HummusRecipe; - line(coordinates: number[], options?: HummusRecipe.ILineOptions): HummusRecipe + line( + coordinates: number[], + options?: HummusRecipe.ILineOptions + ): HummusRecipe; - polygon(coordinates: number[][], options?: HummusRecipe.IPolygonOptions): HummusRecipe + polygon( + coordinates: number[][], + options?: HummusRecipe.IPolygonOptions + ): HummusRecipe; circle( x: number, y: number, radius: number, - options?: HummusRecipe.ICircleOptions, - ): HummusRecipe + options?: HummusRecipe.ICircleOptions + ): HummusRecipe; rectangle( x: number, y: number, width: number, height: number, - options?: HummusRecipe.IRactangleOptions, - ): HummusRecipe + options?: HummusRecipe.IRactangleOptions + ): HummusRecipe; - endPDF(callback?: Function): HummusRecipe + endPDF(callback?: Function): HummusRecipe; } -declare module 'hummus-recipe' { - export = HummusRecipe +declare module "hummus-recipe" { + export = HummusRecipe; } From 8f78483afd6bca62ab8b5b9a50855c45ae450c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Wed, 3 Apr 2019 13:58:49 +0200 Subject: [PATCH 5/9] :rotating_light: Rename interfaces --- types/hummus-recipe/index.d.ts | 60 +++++++++++++++++----------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index ad2cfbba93..2a02db53ac 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace HummusRecipe { - interface IRecipeOptions { + interface RecipeOptions { version?: number; author?: string; title?: string; @@ -12,7 +12,7 @@ declare namespace HummusRecipe { keywords?: string[]; } - interface ICommentOptions { + interface CommentOptions { title?: string; date?: string; open?: boolean; @@ -29,7 +29,7 @@ declare namespace HummusRecipe { | "togglenoview"; } - interface IAnotOptions { + interface AnotOptions { title?: string; open?: boolean; richText?: boolean; @@ -55,13 +55,13 @@ declare namespace HummusRecipe { height?: number; } - interface IEncryptOptions { + interface EncryptOptions { password?: string; ownerPassword?: string; userProtectionFlag?: number; } - interface IImageOptions { + interface ImageOptions { width?: number; height?: number; scale?: number; @@ -70,7 +70,7 @@ declare namespace HummusRecipe { align?: string; } - interface IInfoOptions { + interface InfoOptions { version?: string; author?: string; title?: string; @@ -78,14 +78,14 @@ declare namespace HummusRecipe { keywords?: string[]; } - interface IOverlayOptions { + interface OverlayOptions { scale?: number; keepAspectRatio?: boolean; fitWidth?: boolean; fitHeight?: boolean; } - interface ITextBoxStyle { + interface TextBoxStyle { lineWidth?: number; stroke?: string | number[]; dash?: number[]; @@ -93,17 +93,17 @@ declare namespace HummusRecipe { opacity?: number; } - interface ITextBox { + interface TextBox { width?: number; height?: number; minHeight?: number; padding?: number | number[]; lineHeight?: number; textAlign?: string; - style?: ITextBoxStyle; + style?: TextBoxStyle; } - interface ITextOptions { + interface TextOptions { color?: string | number[]; opacity?: number; rotation?: number; @@ -114,10 +114,10 @@ declare namespace HummusRecipe { highlight?: Object | Boolean; underline?: Object | Boolean; strikeOut?: Object | Boolean; - textBox?: ITextBox; + textBox?: TextBox; } - interface ILineToOptions { + interface LineToOptions { color?: string | number[]; stroke?: string | number[]; fill?: string | number[]; @@ -126,14 +126,14 @@ declare namespace HummusRecipe { dash?: number[]; } - interface ILineOptions { + interface LineOptions { color?: string | number[]; stroke?: string | number[]; lineWidth?: number; dash?: number[]; } - interface IPolygonOptions { + interface PolygonOptions { color?: string | number[]; stroke?: string | number[]; fill?: string | number[]; @@ -142,7 +142,7 @@ declare namespace HummusRecipe { dash?: number[]; } - interface ICircleOptions { + interface CircleOptions { color?: string | number[]; stroke?: string | number[]; fill?: string | number[]; @@ -151,7 +151,7 @@ declare namespace HummusRecipe { dash?: number[]; } - interface IRactangleOptions { + interface RectangleOptions { color?: string | number[]; stroke?: string | number[]; fill?: string | number[]; @@ -167,14 +167,14 @@ declare class HummusRecipe { constructor( src: string, output: string, - options?: HummusRecipe.IRecipeOptions + options?: HummusRecipe.RecipeOptions ); comment( text: string, x: number, y: number, - options?: HummusRecipe.ICommentOptions + options?: HummusRecipe.CommentOptions ): HummusRecipe; annot( @@ -197,12 +197,12 @@ declare class HummusRecipe { | "Ink" | "FileAttachment" | "Sound", - options?: HummusRecipe.IAnotOptions + options?: HummusRecipe.AnotOptions ): HummusRecipe; appendPage(pdfSrc: string, pages: number | number[]): HummusRecipe; - encrypt(options: HummusRecipe.IEncryptOptions): HummusRecipe; + encrypt(options: HummusRecipe.EncryptOptions): HummusRecipe; registerFont(fontName: string, fontSrcPath: string): HummusRecipe; @@ -210,10 +210,10 @@ declare class HummusRecipe { imgSrc: string, x: number, y: number, - options?: HummusRecipe.IImageOptions + options?: HummusRecipe.ImageOptions ): HummusRecipe; - info(options?: HummusRecipe.IInfoOptions): HummusRecipe; + info(options?: HummusRecipe.InfoOptions): HummusRecipe; custom(key?: string, value?: string): HummusRecipe; @@ -227,7 +227,7 @@ declare class HummusRecipe { pdfSrc: string, x: number, y: number, - options?: HummusRecipe.IOverlayOptions + options?: HummusRecipe.OverlayOptions ): HummusRecipe; createPage(pageWidth: number, pageHeight: number): HummusRecipe; @@ -244,7 +244,7 @@ declare class HummusRecipe { text: string, x: number, y: number, - options?: HummusRecipe.ITextOptions + options?: HummusRecipe.TextOptions ): HummusRecipe; moveTo(x: number, y: number): HummusRecipe; @@ -252,24 +252,24 @@ declare class HummusRecipe { lineTo( x: number, y: number, - options?: HummusRecipe.ILineToOptions + options?: HummusRecipe.LineToOptions ): HummusRecipe; line( coordinates: number[], - options?: HummusRecipe.ILineOptions + options?: HummusRecipe.LineOptions ): HummusRecipe; polygon( coordinates: number[][], - options?: HummusRecipe.IPolygonOptions + options?: HummusRecipe.PolygonOptions ): HummusRecipe; circle( x: number, y: number, radius: number, - options?: HummusRecipe.ICircleOptions + options?: HummusRecipe.CircleOptions ): HummusRecipe; rectangle( @@ -277,7 +277,7 @@ declare class HummusRecipe { y: number, width: number, height: number, - options?: HummusRecipe.IRactangleOptions + options?: HummusRecipe.RectangleOptions ): HummusRecipe; endPDF(callback?: Function): HummusRecipe; From 232addfa17f954003e56f8dc6b68e277b42e7283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Wed, 3 Apr 2019 14:00:15 +0200 Subject: [PATCH 6/9] :rotating_light: Add minimal typescript version number --- types/hummus-recipe/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index 2a02db53ac..be2c68b6b5 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/chunyenHuang/hummusRecipe // Definitions by: Erik Berreßem // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 declare namespace HummusRecipe { interface RecipeOptions { From 9fb3a7d07e97a1ed514bf1d9d1b772d79af2ee96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Wed, 3 Apr 2019 14:03:15 +0200 Subject: [PATCH 7/9] :rotating_light: Remove 'Object' --- types/hummus-recipe/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index be2c68b6b5..ceb135c6d1 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -112,9 +112,9 @@ declare namespace HummusRecipe { font?: string; size?: number; align?: string; - highlight?: Object | Boolean; - underline?: Object | Boolean; - strikeOut?: Object | Boolean; + highlight?: boolean; + underline?: boolean; + strikeOut?: boolean; textBox?: TextBox; } @@ -281,7 +281,7 @@ declare class HummusRecipe { options?: HummusRecipe.RectangleOptions ): HummusRecipe; - endPDF(callback?: Function): HummusRecipe; + endPDF(callback?: () => any): HummusRecipe; } declare module "hummus-recipe" { From 740513cda8cb0d1275234ff08d9328d89433285e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Wed, 3 Apr 2019 14:13:21 +0200 Subject: [PATCH 8/9] :rotating_light: remove module declaration --- types/hummus-recipe/hummus-recipe-tests.ts | 28 ++++---- types/hummus-recipe/index.d.ts | 84 +++++++++------------- 2 files changed, 47 insertions(+), 65 deletions(-) diff --git a/types/hummus-recipe/hummus-recipe-tests.ts b/types/hummus-recipe/hummus-recipe-tests.ts index ce6139260f..7503c86aa8 100644 --- a/types/hummus-recipe/hummus-recipe-tests.ts +++ b/types/hummus-recipe/hummus-recipe-tests.ts @@ -1,21 +1,21 @@ import * as HummusRecipe from 'hummus-recipe'; -// $ExpectType HummusRecipe -const pdf = new HummusRecipe('new', 'test.pdf', { - version: 1.6, - author: 'John Doe', - title: 'Hummus Recipe', - subject: 'A brand new PDF', +// $ExpectType Recipe +const pdf = new HummusRecipe.Recipe("new", "test.pdf", { + version: 1.6, + author: "John Doe", + title: "Hummus Recipe", + subject: "A brand new PDF" }); -// $ExpectType HummusRecipe +// $ExpectType Recipe pdf.createPage(595, 842) - .text('Memento Mori', 100, 100) - .endPage() - .endPDF(); + .text("Memento Mori", 100, 100) + .endPage() + .endPDF(); // $ExpectError -pdf.createPage('A4') - .text('Memento Mori', 100, 100) - .endPage() - .endPDF(); +pdf.createPage("A4") + .text("Memento Mori", 100, 100) + .endPage() + .endPDF(); diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index ceb135c6d1..c51427a16c 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 -declare namespace HummusRecipe { +export declare namespace Recipe { interface RecipeOptions { version?: number; author?: string; @@ -164,19 +164,15 @@ declare namespace HummusRecipe { } } -declare class HummusRecipe { - constructor( - src: string, - output: string, - options?: HummusRecipe.RecipeOptions - ); +export class Recipe { + constructor(src: string, output: string, options?: Recipe.RecipeOptions); comment( text: string, x: number, y: number, - options?: HummusRecipe.CommentOptions - ): HummusRecipe; + options?: Recipe.CommentOptions + ): Recipe; annot( x: number, @@ -198,92 +194,78 @@ declare class HummusRecipe { | "Ink" | "FileAttachment" | "Sound", - options?: HummusRecipe.AnotOptions - ): HummusRecipe; + options?: Recipe.AnotOptions + ): Recipe; - appendPage(pdfSrc: string, pages: number | number[]): HummusRecipe; + appendPage(pdfSrc: string, pages: number | number[]): Recipe; - encrypt(options: HummusRecipe.EncryptOptions): HummusRecipe; + encrypt(options: Recipe.EncryptOptions): Recipe; - registerFont(fontName: string, fontSrcPath: string): HummusRecipe; + registerFont(fontName: string, fontSrcPath: string): Recipe; image( imgSrc: string, x: number, y: number, - options?: HummusRecipe.ImageOptions - ): HummusRecipe; + options?: Recipe.ImageOptions + ): Recipe; - info(options?: HummusRecipe.InfoOptions): HummusRecipe; + info(options?: Recipe.InfoOptions): Recipe; - custom(key?: string, value?: string): HummusRecipe; + custom(key?: string, value?: string): Recipe; insertPage( afterPageNumber: number, pdfSrc: string, srcPageNumber: number - ): HummusRecipe; + ): Recipe; overlay( pdfSrc: string, x: number, y: number, - options?: HummusRecipe.OverlayOptions - ): HummusRecipe; + options?: Recipe.OverlayOptions + ): Recipe; - createPage(pageWidth: number, pageHeight: number): HummusRecipe; + createPage(pageWidth: number, pageHeight: number): Recipe; - endPage(): HummusRecipe; + endPage(): Recipe; - editPage(pageNumber: number): HummusRecipe; + editPage(pageNumber: number): Recipe; - pageInfo(pageNumber: number): HummusRecipe; + pageInfo(pageNumber: number): Recipe; - split(outputDir: string, prefix: string): HummusRecipe; + split(outputDir: string, prefix: string): Recipe; text( text: string, x: number, y: number, - options?: HummusRecipe.TextOptions - ): HummusRecipe; + options?: Recipe.TextOptions + ): Recipe; - moveTo(x: number, y: number): HummusRecipe; + moveTo(x: number, y: number): Recipe; - lineTo( - x: number, - y: number, - options?: HummusRecipe.LineToOptions - ): HummusRecipe; + lineTo(x: number, y: number, options?: Recipe.LineToOptions): Recipe; - line( - coordinates: number[], - options?: HummusRecipe.LineOptions - ): HummusRecipe; + line(coordinates: number[], options?: Recipe.LineOptions): Recipe; - polygon( - coordinates: number[][], - options?: HummusRecipe.PolygonOptions - ): HummusRecipe; + polygon(coordinates: number[][], options?: Recipe.PolygonOptions): Recipe; circle( x: number, y: number, radius: number, - options?: HummusRecipe.CircleOptions - ): HummusRecipe; + options?: Recipe.CircleOptions + ): Recipe; rectangle( x: number, y: number, width: number, height: number, - options?: HummusRecipe.RectangleOptions - ): HummusRecipe; + options?: Recipe.RectangleOptions + ): Recipe; - endPDF(callback?: () => any): HummusRecipe; -} - -declare module "hummus-recipe" { - export = HummusRecipe; + endPDF(callback?: () => any): Recipe; } From b475d4819691263353d64aa9ad7502354dceadd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Wed, 3 Apr 2019 14:16:20 +0200 Subject: [PATCH 9/9] :art: remove namespace --- types/hummus-recipe/hummus-recipe-tests.ts | 4 +- types/hummus-recipe/index.d.ts | 322 ++++++++++----------- 2 files changed, 157 insertions(+), 169 deletions(-) diff --git a/types/hummus-recipe/hummus-recipe-tests.ts b/types/hummus-recipe/hummus-recipe-tests.ts index 7503c86aa8..7635dbbce1 100644 --- a/types/hummus-recipe/hummus-recipe-tests.ts +++ b/types/hummus-recipe/hummus-recipe-tests.ts @@ -1,7 +1,7 @@ -import * as HummusRecipe from 'hummus-recipe'; +import { Recipe } from 'hummus-recipe'; // $ExpectType Recipe -const pdf = new HummusRecipe.Recipe("new", "test.pdf", { +const pdf = new Recipe("new", "test.pdf", { version: 1.6, author: "John Doe", title: "Hummus Recipe", diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index c51427a16c..3b3a47d5a2 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -4,174 +4,172 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 -export declare namespace Recipe { - interface RecipeOptions { - version?: number; - author?: string; - title?: string; - subject?: string; - keywords?: string[]; - } +export interface RecipeOptions { + version?: number; + author?: string; + title?: string; + subject?: string; + keywords?: string[]; +} - interface CommentOptions { - title?: string; - date?: string; - open?: boolean; - richText?: boolean; - flag?: - | "invisible" - | "hidden" - | "print" - | "nozoom" - | "norotate" - | "noview" - | "readonly" - | "locked" - | "togglenoview"; - } +export interface CommentOptions { + title?: string; + date?: string; + open?: boolean; + richText?: boolean; + flag?: + | "invisible" + | "hidden" + | "print" + | "nozoom" + | "norotate" + | "noview" + | "readonly" + | "locked" + | "togglenoview"; +} - interface AnotOptions { - title?: string; - open?: boolean; - richText?: boolean; - flag?: - | "invisible" - | "hidden" - | "print" - | "nozoom" - | "norotate" - | "noview" - | "readonly" - | "locked" - | "togglenoview"; - icon?: - | "Comment" - | "Key" - | "Note" - | "Help" - | "NewParagraph" - | "Paragraph" - | "Insert"; - width?: number; - height?: number; - } +export interface AnotOptions { + title?: string; + open?: boolean; + richText?: boolean; + flag?: + | "invisible" + | "hidden" + | "print" + | "nozoom" + | "norotate" + | "noview" + | "readonly" + | "locked" + | "togglenoview"; + icon?: + | "Comment" + | "Key" + | "Note" + | "Help" + | "NewParagraph" + | "Paragraph" + | "Insert"; + width?: number; + height?: number; +} - interface EncryptOptions { - password?: string; - ownerPassword?: string; - userProtectionFlag?: number; - } +export interface EncryptOptions { + password?: string; + ownerPassword?: string; + userProtectionFlag?: number; +} - interface ImageOptions { - width?: number; - height?: number; - scale?: number; - keepAspectRatio?: boolean; - opacity?: number; - align?: string; - } +export interface ImageOptions { + width?: number; + height?: number; + scale?: number; + keepAspectRatio?: boolean; + opacity?: number; + align?: string; +} - interface InfoOptions { - version?: string; - author?: string; - title?: string; - subject?: string; - keywords?: string[]; - } +export interface InfoOptions { + version?: string; + author?: string; + title?: string; + subject?: string; + keywords?: string[]; +} - interface OverlayOptions { - scale?: number; - keepAspectRatio?: boolean; - fitWidth?: boolean; - fitHeight?: boolean; - } +export interface OverlayOptions { + scale?: number; + keepAspectRatio?: boolean; + fitWidth?: boolean; + fitHeight?: boolean; +} - interface TextBoxStyle { - lineWidth?: number; - stroke?: string | number[]; - dash?: number[]; - fill?: string | number[]; - opacity?: number; - } +export interface TextBoxStyle { + lineWidth?: number; + stroke?: string | number[]; + dash?: number[]; + fill?: string | number[]; + opacity?: number; +} - interface TextBox { - width?: number; - height?: number; - minHeight?: number; - padding?: number | number[]; - lineHeight?: number; - textAlign?: string; - style?: TextBoxStyle; - } +export interface TextBox { + width?: number; + height?: number; + minHeight?: number; + padding?: number | number[]; + lineHeight?: number; + textAlign?: string; + style?: TextBoxStyle; +} - interface TextOptions { - color?: string | number[]; - opacity?: number; - rotation?: number; - rotationOrigin?: number[]; - font?: string; - size?: number; - align?: string; - highlight?: boolean; - underline?: boolean; - strikeOut?: boolean; - textBox?: TextBox; - } +export interface TextOptions { + color?: string | number[]; + opacity?: number; + rotation?: number; + rotationOrigin?: number[]; + font?: string; + size?: number; + align?: string; + highlight?: boolean; + underline?: boolean; + strikeOut?: boolean; + textBox?: TextBox; +} - interface LineToOptions { - color?: string | number[]; - stroke?: string | number[]; - fill?: string | number[]; - lineWidth?: number; - opacity?: number; - dash?: number[]; - } +export interface LineToOptions { + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; +} - interface LineOptions { - color?: string | number[]; - stroke?: string | number[]; - lineWidth?: number; - dash?: number[]; - } +export interface LineOptions { + color?: string | number[]; + stroke?: string | number[]; + lineWidth?: number; + dash?: number[]; +} - interface PolygonOptions { - color?: string | number[]; - stroke?: string | number[]; - fill?: string | number[]; - lineWidth?: number; - opacity?: number; - dash?: number[]; - } +export interface PolygonOptions { + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; +} - interface CircleOptions { - color?: string | number[]; - stroke?: string | number[]; - fill?: string | number[]; - lineWidth?: number; - opacity?: number; - dash?: number[]; - } +export interface CircleOptions { + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; +} - interface RectangleOptions { - color?: string | number[]; - stroke?: string | number[]; - fill?: string | number[]; - lineWidth?: number; - opacity?: number; - dash?: number[]; - rotation?: number; - rotationOrigin?: number[]; - } +export interface RectangleOptions { + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; + rotation?: number; + rotationOrigin?: number[]; } export class Recipe { - constructor(src: string, output: string, options?: Recipe.RecipeOptions); + constructor(src: string, output: string, options?: RecipeOptions); comment( text: string, x: number, y: number, - options?: Recipe.CommentOptions + options?: CommentOptions ): Recipe; annot( @@ -194,23 +192,18 @@ export class Recipe { | "Ink" | "FileAttachment" | "Sound", - options?: Recipe.AnotOptions + options?: AnotOptions ): Recipe; appendPage(pdfSrc: string, pages: number | number[]): Recipe; - encrypt(options: Recipe.EncryptOptions): Recipe; + encrypt(options: EncryptOptions): 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?: ImageOptions): Recipe; - info(options?: Recipe.InfoOptions): Recipe; + info(options?: InfoOptions): Recipe; custom(key?: string, value?: string): Recipe; @@ -224,7 +217,7 @@ export class Recipe { pdfSrc: string, x: number, y: number, - options?: Recipe.OverlayOptions + options?: OverlayOptions ): Recipe; createPage(pageWidth: number, pageHeight: number): Recipe; @@ -237,26 +230,21 @@ export 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?: TextOptions): Recipe; moveTo(x: number, y: number): Recipe; - lineTo(x: number, y: number, options?: Recipe.LineToOptions): Recipe; + lineTo(x: number, y: number, options?: LineToOptions): Recipe; - line(coordinates: number[], options?: Recipe.LineOptions): Recipe; + line(coordinates: number[], options?: LineOptions): Recipe; - polygon(coordinates: number[][], options?: Recipe.PolygonOptions): Recipe; + polygon(coordinates: number[][], options?: PolygonOptions): Recipe; circle( x: number, y: number, radius: number, - options?: Recipe.CircleOptions + options?: CircleOptions ): Recipe; rectangle( @@ -264,7 +252,7 @@ export class Recipe { y: number, width: number, height: number, - options?: Recipe.RectangleOptions + options?: RectangleOptions ): Recipe; endPDF(callback?: () => any): Recipe;