From fd5742930d73d2889b2ab03da84ffe9b3be01298 Mon Sep 17 00:00:00 2001 From: Andrew Houghton Date: Tue, 24 Apr 2018 16:21:17 -0700 Subject: [PATCH] (new definition) add mjml (mjml.io) types (#25217) * add mjml (mjml.io) types * update mjml definition, actually verify linter runs, be more explicit in re: error types * mjml: int -> number. why does lint pass w/ 'int'? ah well. * per @plantain-00 CR --- types/mjml/index.d.ts | 29 +++++++++++++++++++++++++++++ types/mjml/mjml-tests.ts | 10 ++++++++++ types/mjml/tsconfig.json | 23 +++++++++++++++++++++++ types/mjml/tslint.json | 1 + 4 files changed, 63 insertions(+) create mode 100644 types/mjml/index.d.ts create mode 100644 types/mjml/mjml-tests.ts create mode 100644 types/mjml/tsconfig.json create mode 100644 types/mjml/tslint.json diff --git a/types/mjml/index.d.ts b/types/mjml/index.d.ts new file mode 100644 index 0000000000..bccb7d319d --- /dev/null +++ b/types/mjml/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for mjml 4.0 +// Project: https://github.com/mjmlio/mjml +// Definitions by: aahoughton +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface MJMLParsingOpts { + fonts?: { [key: string]: string; }; + keepComments?: boolean; + beautify?: boolean; + minify?: boolean; + validationLevel?: 'strict' | 'soft' | 'skip'; + filePath?: boolean; +} + +interface MJMLParseError { + line: number; + message: string; + tagName: string; + formattedMessage: string; +} + +interface MJMLParseResults { + html: string; + errors: MJMLParseError[]; +} + +declare function mjml2html(inp: string, opts?: MJMLParsingOpts): MJMLParseResults; + +export = mjml2html; diff --git a/types/mjml/mjml-tests.ts b/types/mjml/mjml-tests.ts new file mode 100644 index 0000000000..3a7711d08b --- /dev/null +++ b/types/mjml/mjml-tests.ts @@ -0,0 +1,10 @@ +import mjml2html = require('mjml'); + +const simple_test = mjml2html(""); +const html = simple_test.html; +const errors = simple_test.errors; +let formattedMessage = errors[0].formattedMessage; +formattedMessage = "force string test"; + +const minimal_opts_test = mjml2html("", {beautify: true}); +const validation_level_test = mjml2html("", {validationLevel: "strict"}); diff --git a/types/mjml/tsconfig.json b/types/mjml/tsconfig.json new file mode 100644 index 0000000000..5fb996bbe9 --- /dev/null +++ b/types/mjml/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mjml-tests.ts" + ] +} diff --git a/types/mjml/tslint.json b/types/mjml/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mjml/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }