From 7049fc4b4c732ca53e1bb1f778e813fcf4d50bde Mon Sep 17 00:00:00 2001 From: Alex Seifert Date: Mon, 3 Feb 2020 18:32:35 +0100 Subject: [PATCH] Add object type to the MJML package (#42066) * Add object type to the MJML package * Add more a more specific interface * Add missing types to MJML and make optional ones optional * Add usage examples to the MJML test file --- types/mjml/index.d.ts | 10 +++++++++- types/mjml/mjml-tests.ts | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/types/mjml/index.d.ts b/types/mjml/index.d.ts index 867dfb7145..c8bd78667a 100644 --- a/types/mjml/index.d.ts +++ b/types/mjml/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/mjmlio/mjml, https://mjml.io // Definitions by: aahoughton // marpstar +// eiskalteschatten // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped interface MJMLParsingOpts { @@ -25,6 +26,13 @@ interface MJMLParseResults { errors: MJMLParseError[]; } -declare function mjml2html(inp: string, opts?: MJMLParsingOpts): MJMLParseResults; +interface MJMLJsonObject { + tagName: string; + attributes: object; + children?: MJMLJsonObject[]; + content?: string; +} + +declare function mjml2html(inp: string | MJMLJsonObject, opts?: MJMLParsingOpts): MJMLParseResults; export = mjml2html; diff --git a/types/mjml/mjml-tests.ts b/types/mjml/mjml-tests.ts index 1acee04e49..9c7d47e421 100644 --- a/types/mjml/mjml-tests.ts +++ b/types/mjml/mjml-tests.ts @@ -1,4 +1,4 @@ -import mjml2html = require('mjml'); +import mjml2html = require("mjml"); const simple_test = mjml2html(""); const html = simple_test.html; @@ -9,3 +9,6 @@ formattedMessage = "force string test"; const minimal_opts_test = mjml2html("", {beautify: true}); const validation_level_test = mjml2html("", {validationLevel: "strict"}); const filePath_test = mjml2html("", {filePath: "."}); + +const jsonObject = {tagName: "mjml", attributes: {width: "100px"}, content: "test content"}; +const jsonObject_test = mjml2html(jsonObject);