From c05d4bc228ab7bb6cdbfc2f0256fe17830614550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Thu, 4 Apr 2019 09:55:08 +0200 Subject: [PATCH 1/8] :pencil2: Fix typo 'Anot' --- types/hummus-recipe/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index 3b3a47d5a2..f8d9526708 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -29,7 +29,7 @@ export interface CommentOptions { | "togglenoview"; } -export interface AnotOptions { +export interface AnnotOptions { title?: string; open?: boolean; richText?: boolean; @@ -192,7 +192,7 @@ export class Recipe { | "Ink" | "FileAttachment" | "Sound", - options?: AnotOptions + options?: AnnotOptions ): Recipe; appendPage(pdfSrc: string, pages: number | number[]): Recipe; From f4ceb7f0814de84a7930b1c58cddf87a4ab70a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Thu, 4 Apr 2019 09:57:32 +0200 Subject: [PATCH 2/8] :bug: Fix wrong type for prop coordinates of method line --- types/hummus-recipe/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index f8d9526708..247956428d 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -236,7 +236,7 @@ export class Recipe { lineTo(x: number, y: number, options?: LineToOptions): Recipe; - line(coordinates: number[], options?: LineOptions): Recipe; + line(coordinates: number[][], options?: LineOptions): Recipe; polygon(coordinates: number[][], options?: PolygonOptions): Recipe; From 70880592a041189ee6b5b92546ae2a7dea9ca45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Thu, 4 Apr 2019 10:07:38 +0200 Subject: [PATCH 3/8] :art: add namespace 'Recipe' for interfaces and types --- types/hummus-recipe/index.d.ts | 322 +++++++++++++++++---------------- 1 file changed, 167 insertions(+), 155 deletions(-) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index 247956428d..8d575e6f4b 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -4,172 +4,174 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 -export interface RecipeOptions { - version?: number; - author?: string; - title?: string; - subject?: string; - keywords?: string[]; -} +export namespace Recipe { + interface RecipeOptions { + version?: number; + author?: string; + title?: string; + subject?: string; + keywords?: string[]; + } -export interface CommentOptions { - title?: string; - date?: string; - open?: boolean; - richText?: boolean; - flag?: - | "invisible" - | "hidden" - | "print" - | "nozoom" - | "norotate" - | "noview" - | "readonly" - | "locked" - | "togglenoview"; -} + interface CommentOptions { + title?: string; + date?: string; + open?: boolean; + richText?: boolean; + flag?: + | "invisible" + | "hidden" + | "print" + | "nozoom" + | "norotate" + | "noview" + | "readonly" + | "locked" + | "togglenoview"; + } -export interface AnnotOptions { - 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 AnnotOptions { + 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 EncryptOptions { - password?: string; - ownerPassword?: string; - userProtectionFlag?: number; -} + interface EncryptOptions { + password?: string; + ownerPassword?: string; + userProtectionFlag?: number; + } -export interface ImageOptions { - width?: number; - height?: number; - scale?: number; - keepAspectRatio?: boolean; - opacity?: number; - align?: string; -} + interface ImageOptions { + width?: number; + height?: number; + scale?: number; + keepAspectRatio?: boolean; + opacity?: number; + align?: string; + } -export interface InfoOptions { - version?: string; - author?: string; - title?: string; - subject?: string; - keywords?: string[]; -} + interface InfoOptions { + version?: string; + author?: string; + title?: string; + subject?: string; + keywords?: string[]; + } -export interface OverlayOptions { - scale?: number; - keepAspectRatio?: boolean; - fitWidth?: boolean; - fitHeight?: boolean; -} + interface OverlayOptions { + scale?: number; + keepAspectRatio?: boolean; + fitWidth?: boolean; + fitHeight?: boolean; + } -export interface TextBoxStyle { - lineWidth?: number; - stroke?: string | number[]; - dash?: number[]; - fill?: string | number[]; - opacity?: number; -} + interface TextBoxStyle { + lineWidth?: number; + stroke?: string | number[]; + dash?: number[]; + fill?: string | number[]; + opacity?: number; + } -export interface TextBox { - width?: number; - height?: number; - minHeight?: number; - padding?: number | number[]; - lineHeight?: number; - textAlign?: string; - style?: TextBoxStyle; -} + interface TextBox { + width?: number; + height?: number; + minHeight?: number; + padding?: number | number[]; + lineHeight?: number; + textAlign?: string; + style?: TextBoxStyle; + } -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 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 LineToOptions { - color?: string | number[]; - stroke?: string | number[]; - fill?: string | number[]; - lineWidth?: number; - opacity?: number; - dash?: number[]; -} + interface LineToOptions { + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; + } -export interface LineOptions { - color?: string | number[]; - stroke?: string | number[]; - lineWidth?: number; - dash?: number[]; -} + interface LineOptions { + color?: string | number[]; + stroke?: string | number[]; + lineWidth?: number; + dash?: number[]; + } -export interface PolygonOptions { - color?: string | number[]; - stroke?: string | number[]; - fill?: string | number[]; - lineWidth?: number; - opacity?: number; - dash?: number[]; -} + interface PolygonOptions { + 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 CircleOptions { + color?: string | number[]; + stroke?: string | number[]; + fill?: string | number[]; + lineWidth?: number; + opacity?: number; + dash?: number[]; + } -export interface RectangleOptions { - color?: string | number[]; - stroke?: string | number[]; - fill?: string | number[]; - lineWidth?: number; - opacity?: number; - dash?: number[]; - rotation?: number; - rotationOrigin?: number[]; + 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?: RecipeOptions); + constructor(src: string, output: string, options?: Recipe.RecipeOptions); comment( text: string, x: number, y: number, - options?: CommentOptions + options?: Recipe.CommentOptions ): Recipe; annot( @@ -192,18 +194,23 @@ export class Recipe { | "Ink" | "FileAttachment" | "Sound", - options?: AnnotOptions + options?: Recipe.AnnotOptions ): Recipe; appendPage(pdfSrc: string, pages: number | number[]): Recipe; - encrypt(options: EncryptOptions): Recipe; + encrypt(options: Recipe.EncryptOptions): Recipe; registerFont(fontName: string, fontSrcPath: string): Recipe; - image(imgSrc: string, x: number, y: number, options?: ImageOptions): Recipe; + image( + imgSrc: string, + x: number, + y: number, + options?: Recipe.ImageOptions + ): Recipe; - info(options?: InfoOptions): Recipe; + info(options?: Recipe.InfoOptions): Recipe; custom(key?: string, value?: string): Recipe; @@ -217,7 +224,7 @@ export class Recipe { pdfSrc: string, x: number, y: number, - options?: OverlayOptions + options?: Recipe.OverlayOptions ): Recipe; createPage(pageWidth: number, pageHeight: number): Recipe; @@ -230,21 +237,26 @@ export class Recipe { split(outputDir: string, prefix: string): Recipe; - text(text: string, x: number, y: number, options?: TextOptions): Recipe; + text( + text: string, + x: number, + y: number, + options?: Recipe.TextOptions + ): Recipe; moveTo(x: number, y: number): Recipe; - lineTo(x: number, y: number, options?: LineToOptions): Recipe; + lineTo(x: number, y: number, options?: Recipe.LineToOptions): Recipe; - line(coordinates: number[][], options?: LineOptions): Recipe; + line(coordinates: number[][], options?: Recipe.LineOptions): Recipe; - polygon(coordinates: number[][], options?: PolygonOptions): Recipe; + polygon(coordinates: number[][], options?: Recipe.PolygonOptions): Recipe; circle( x: number, y: number, radius: number, - options?: CircleOptions + options?: Recipe.CircleOptions ): Recipe; rectangle( @@ -252,7 +264,7 @@ export class Recipe { y: number, width: number, height: number, - options?: RectangleOptions + options?: Recipe.RectangleOptions ): Recipe; endPDF(callback?: () => any): Recipe; From d3c5de3f6474650f92692832b2b8860af49e942f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Thu, 4 Apr 2019 10:17:20 +0200 Subject: [PATCH 4/8] :art: use double instead of single quote marks --- types/hummus-recipe/hummus-recipe-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/hummus-recipe/hummus-recipe-tests.ts b/types/hummus-recipe/hummus-recipe-tests.ts index 7635dbbce1..ce0b8097f9 100644 --- a/types/hummus-recipe/hummus-recipe-tests.ts +++ b/types/hummus-recipe/hummus-recipe-tests.ts @@ -1,4 +1,4 @@ -import { Recipe } from 'hummus-recipe'; +import { Recipe } from "hummus-recipe"; // $ExpectType Recipe const pdf = new Recipe("new", "test.pdf", { From 2a4d7ad0071304530323abfc15d862ae821ba0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Thu, 4 Apr 2019 10:18:51 +0200 Subject: [PATCH 5/8] :art: rename namespace 'Recipe' to 'HummusRecipe' --- types/hummus-recipe/index.d.ts | 35 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index 8d575e6f4b..3c785d6d43 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 -export namespace Recipe { +export namespace HummusRecipe { interface RecipeOptions { version?: number; author?: string; @@ -165,13 +165,17 @@ export namespace Recipe { } export class Recipe { - constructor(src: string, output: string, options?: Recipe.RecipeOptions); + constructor( + src: string, + output: string, + options?: HummusRecipe.RecipeOptions + ); comment( text: string, x: number, y: number, - options?: Recipe.CommentOptions + options?: HummusRecipe.CommentOptions ): Recipe; annot( @@ -194,12 +198,12 @@ export class Recipe { | "Ink" | "FileAttachment" | "Sound", - options?: Recipe.AnnotOptions + options?: HummusRecipe.AnnotOptions ): Recipe; appendPage(pdfSrc: string, pages: number | number[]): Recipe; - encrypt(options: Recipe.EncryptOptions): Recipe; + encrypt(options: HummusRecipe.EncryptOptions): Recipe; registerFont(fontName: string, fontSrcPath: string): Recipe; @@ -207,10 +211,10 @@ export class Recipe { imgSrc: string, x: number, y: number, - options?: Recipe.ImageOptions + options?: HummusRecipe.ImageOptions ): Recipe; - info(options?: Recipe.InfoOptions): Recipe; + info(options?: HummusRecipe.InfoOptions): Recipe; custom(key?: string, value?: string): Recipe; @@ -224,7 +228,7 @@ export class Recipe { pdfSrc: string, x: number, y: number, - options?: Recipe.OverlayOptions + options?: HummusRecipe.OverlayOptions ): Recipe; createPage(pageWidth: number, pageHeight: number): Recipe; @@ -241,22 +245,25 @@ export class Recipe { text: string, x: number, y: number, - options?: Recipe.TextOptions + options?: HummusRecipe.TextOptions ): Recipe; moveTo(x: number, y: number): Recipe; - lineTo(x: number, y: number, options?: Recipe.LineToOptions): Recipe; + lineTo(x: number, y: number, options?: HummusRecipe.LineToOptions): Recipe; - line(coordinates: number[][], options?: Recipe.LineOptions): Recipe; + line(coordinates: number[][], options?: HummusRecipe.LineOptions): Recipe; - polygon(coordinates: number[][], options?: Recipe.PolygonOptions): Recipe; + polygon( + coordinates: number[][], + options?: HummusRecipe.PolygonOptions + ): Recipe; circle( x: number, y: number, radius: number, - options?: Recipe.CircleOptions + options?: HummusRecipe.CircleOptions ): Recipe; rectangle( @@ -264,7 +271,7 @@ export class Recipe { y: number, width: number, height: number, - options?: Recipe.RectangleOptions + options?: HummusRecipe.RectangleOptions ): Recipe; endPDF(callback?: () => any): Recipe; From b73f45bdcb9d2eb8bd4e184b74654d4d0b508279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Thu, 4 Apr 2019 10:25:05 +0200 Subject: [PATCH 6/8] :art: add types --- types/hummus-recipe/index.d.ts | 98 ++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index 3c785d6d43..07285f5b48 100644 --- a/types/hummus-recipe/index.d.ts +++ b/types/hummus-recipe/index.d.ts @@ -5,6 +5,55 @@ // TypeScript Version: 2.1 export namespace HummusRecipe { + type CommentOptionsFlag = + | "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"; + + type AnnotOptionsFlag = + | "invisible" + | "hidden" + | "print" + | "nozoom" + | "norotate" + | "noview" + | "readonly" + | "locked" + | "togglenoview"; + + type AnnotOptionsIcon = + | "Comment" + | "Key" + | "Note" + | "Help" + | "NewParagraph" + | "Paragraph" + | "Insert"; + interface RecipeOptions { version?: number; author?: string; @@ -18,40 +67,15 @@ export namespace HummusRecipe { date?: string; open?: boolean; richText?: boolean; - flag?: - | "invisible" - | "hidden" - | "print" - | "nozoom" - | "norotate" - | "noview" - | "readonly" - | "locked" - | "togglenoview"; + flag?: CommentOptionsFlag; } interface AnnotOptions { title?: string; open?: boolean; richText?: boolean; - flag?: - | "invisible" - | "hidden" - | "print" - | "nozoom" - | "norotate" - | "noview" - | "readonly" - | "locked" - | "togglenoview"; - icon?: - | "Comment" - | "Key" - | "Note" - | "Help" - | "NewParagraph" - | "Paragraph" - | "Insert"; + flag?: AnnotOptionsFlag; + icon?: AnnotOptionsIcon; width?: number; height?: number; } @@ -181,23 +205,7 @@ export class Recipe { annot( x: number, y: number, - subtype: - | "Text" - | "FreeText" - | "Line" - | "Square" - | "Circle" - | "Polygon" - | "PolyLine" - | "Highlight" - | "Underline" - | "Squiggly" - | "StrikeOut" - | "Stamp" - | "Caret" - | "Ink" - | "FileAttachment" - | "Sound", + subtype: HummusRecipe.AnnotSubtype, options?: HummusRecipe.AnnotOptions ): Recipe; From 70c714301f54a8417e461a7276a94cc9e1379b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Thu, 4 Apr 2019 16:24:02 +0200 Subject: [PATCH 7/8] :bug: hummus-recipe directly exports its class --- types/hummus-recipe/hummus-recipe-tests.ts | 2 +- types/hummus-recipe/index.d.ts | 41 ++++++++++------------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/types/hummus-recipe/hummus-recipe-tests.ts b/types/hummus-recipe/hummus-recipe-tests.ts index ce0b8097f9..3d56e4d502 100644 --- a/types/hummus-recipe/hummus-recipe-tests.ts +++ b/types/hummus-recipe/hummus-recipe-tests.ts @@ -1,4 +1,4 @@ -import { Recipe } from "hummus-recipe"; +import * as Recipe from "hummus-recipe"; // $ExpectType Recipe const pdf = new Recipe("new", "test.pdf", { diff --git a/types/hummus-recipe/index.d.ts b/types/hummus-recipe/index.d.ts index 07285f5b48..7c6aa54fb7 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 -export namespace HummusRecipe { +declare namespace Recipe { type CommentOptionsFlag = | "invisible" | "hidden" @@ -188,30 +188,26 @@ export namespace HummusRecipe { } } -export class Recipe { - constructor( - src: string, - output: string, - options?: HummusRecipe.RecipeOptions - ); +declare class Recipe { + constructor(src: string, output: string, options?: Recipe.RecipeOptions); comment( text: string, x: number, y: number, - options?: HummusRecipe.CommentOptions + options?: Recipe.CommentOptions ): Recipe; annot( x: number, y: number, - subtype: HummusRecipe.AnnotSubtype, - options?: HummusRecipe.AnnotOptions + subtype: Recipe.AnnotSubtype, + options?: Recipe.AnnotOptions ): Recipe; appendPage(pdfSrc: string, pages: number | number[]): Recipe; - encrypt(options: HummusRecipe.EncryptOptions): Recipe; + encrypt(options: Recipe.EncryptOptions): Recipe; registerFont(fontName: string, fontSrcPath: string): Recipe; @@ -219,10 +215,10 @@ export class Recipe { imgSrc: string, x: number, y: number, - options?: HummusRecipe.ImageOptions + options?: Recipe.ImageOptions ): Recipe; - info(options?: HummusRecipe.InfoOptions): Recipe; + info(options?: Recipe.InfoOptions): Recipe; custom(key?: string, value?: string): Recipe; @@ -236,7 +232,7 @@ export class Recipe { pdfSrc: string, x: number, y: number, - options?: HummusRecipe.OverlayOptions + options?: Recipe.OverlayOptions ): Recipe; createPage(pageWidth: number, pageHeight: number): Recipe; @@ -253,25 +249,22 @@ export class Recipe { text: string, x: number, y: number, - options?: HummusRecipe.TextOptions + options?: Recipe.TextOptions ): Recipe; moveTo(x: number, y: number): Recipe; - lineTo(x: number, y: number, options?: HummusRecipe.LineToOptions): Recipe; + lineTo(x: number, y: number, options?: Recipe.LineToOptions): Recipe; - line(coordinates: number[][], options?: HummusRecipe.LineOptions): Recipe; + line(coordinates: number[][], options?: Recipe.LineOptions): Recipe; - polygon( - coordinates: number[][], - options?: HummusRecipe.PolygonOptions - ): Recipe; + polygon(coordinates: number[][], options?: Recipe.PolygonOptions): Recipe; circle( x: number, y: number, radius: number, - options?: HummusRecipe.CircleOptions + options?: Recipe.CircleOptions ): Recipe; rectangle( @@ -279,8 +272,10 @@ export class Recipe { y: number, width: number, height: number, - options?: HummusRecipe.RectangleOptions + options?: Recipe.RectangleOptions ): Recipe; endPDF(callback?: () => any): Recipe; } + +export = Recipe; From 82ffa9a86e89e40e79fa318878b869fea69ddd12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Berre=C3=9Fem?= Date: Thu, 4 Apr 2019 22:44:45 +0200 Subject: [PATCH 8/8] :ok_hand: update import to support pre-es6 syntax --- types/hummus-recipe/hummus-recipe-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/hummus-recipe/hummus-recipe-tests.ts b/types/hummus-recipe/hummus-recipe-tests.ts index 3d56e4d502..062700c8be 100644 --- a/types/hummus-recipe/hummus-recipe-tests.ts +++ b/types/hummus-recipe/hummus-recipe-tests.ts @@ -1,4 +1,4 @@ -import * as Recipe from "hummus-recipe"; +import Recipe = require("hummus-recipe"); // $ExpectType Recipe const pdf = new Recipe("new", "test.pdf", {