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
This commit is contained in:
Alex Seifert 2020-02-03 18:32:35 +01:00 committed by GitHub
parent 1b802a91a7
commit 7049fc4b4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

10
types/mjml/index.d.ts vendored
View File

@ -2,6 +2,7 @@
// Project: https://github.com/mjmlio/mjml, https://mjml.io
// Definitions by: aahoughton <https://github.com/aahoughton>
// marpstar <https://github.com/marpstar>
// eiskalteschatten <https://github.com/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;

View File

@ -1,4 +1,4 @@
import mjml2html = require('mjml');
import mjml2html = require("mjml");
const simple_test = mjml2html("<mjml>");
const html = simple_test.html;
@ -9,3 +9,6 @@ formattedMessage = "force string test";
const minimal_opts_test = mjml2html("<mjml>", {beautify: true});
const validation_level_test = mjml2html("<mjml>", {validationLevel: "strict"});
const filePath_test = mjml2html("<mjml>", {filePath: "."});
const jsonObject = {tagName: "mjml", attributes: {width: "100px"}, content: "test content"};
const jsonObject_test = mjml2html(jsonObject);