From 676f79a3c25ca549dd67e03140885252bdcc7b22 Mon Sep 17 00:00:00 2001 From: ocavue Date: Sat, 10 Oct 2020 22:02:03 +0800 Subject: [PATCH 1/5] Add types --- index.d.ts | 31 +++++++++++++++++++++++++++++++ mdast-util-from-markdown.test.ts | 25 +++++++++++++++++++++++++ package.json | 11 ++++++++--- tsconfig.json | 15 +++++++++++++++ tslint.json | 7 +++++++ 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 index.d.ts create mode 100644 mdast-util-from-markdown.test.ts create mode 100644 tsconfig.json create mode 100644 tslint.json diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..0d45aad --- /dev/null +++ b/index.d.ts @@ -0,0 +1,31 @@ +// Minimum TypeScript Version: 3.0 +import { + Buffer, + BufferEncoding, + SyntaxExtension, + Token +} from 'micromark/dist/shared-types' +import {Root} from 'mdast' +import {Type} from 'micromark/dist/constant/types' + +export = fromMarkdown + +declare namespace fromMarkdown {} + +interface MdastExtension { + enter: Record void> + exit: Record void> +} + +interface Options { + extensions?: SyntaxExtension[] + mdastExtensions?: MdastExtension[] +} + +declare function fromMarkdown(value: string | Buffer, options?: Options): Root + +declare function fromMarkdown( + value: string | Buffer, + encoding?: BufferEncoding, + options?: Options +): Root diff --git a/mdast-util-from-markdown.test.ts b/mdast-util-from-markdown.test.ts new file mode 100644 index 0000000..a50165c --- /dev/null +++ b/mdast-util-from-markdown.test.ts @@ -0,0 +1,25 @@ +// This file is for https://github.com/microsoft/dtslint . +// Tests are type-checked, but not run. + +import * as formMarkdown from 'mdast-util-from-markdown' + +function main() { + const raw = '# text **strong**' + + // $ExpectType Root + formMarkdown(raw) + + // $ExpectType Root + formMarkdown(Buffer.alloc(8)) + + // $ExpectType Root + formMarkdown(Buffer.alloc(8), {extensions: []}) + + // $ExpectType Root + formMarkdown(Buffer.alloc(8), 'utf-8', {mdastExtensions: []}) + + // $ExpectError + formMarkdown(Buffer.alloc(8), 'utf-8', {allowDangerousHtml: true}) +} + +main() diff --git a/package.json b/package.json index 6fce64c..ed848ab 100644 --- a/package.json +++ b/package.json @@ -27,16 +27,20 @@ "Titus Wormer (https://wooorm.com)" ], "files": [ - "index.js" + "index.js", + "index.d.ts" ], + "types": "index.d.ts", "dependencies": { + "@types/mdast": "^3.0.0", "mdast-util-to-string": "^1.0.0", - "micromark": "~2.9.0", + "micromark": "~2.10.0", "parse-entities": "^2.0.0" }, "devDependencies": { "browserify": "^16.0.0", "commonmark.json": "^0.29.0", + "dtslint": "^4.0.0", "gzip-size-cli": "^3.0.0", "hast-util-to-html": "^7.0.0", "mdast-util-to-hast": "^10.0.0", @@ -57,7 +61,8 @@ "generate": "npm run generate-size", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test/index.js", - "test": "npm run format && npm run generate && npm run test-coverage" + "test-types": "dtslint .", + "test": "npm run format && npm run generate && npm run test-coverage && npm run test-types" }, "nyc": { "check-coverage": true, diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..85c0535 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "lib": [ + "ES5" + ], + "strict": true, + "baseUrl": ".", + "paths": { + "mdast-util-from-markdown": [ + "index.d.ts" + ] + } + } +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..9001796 --- /dev/null +++ b/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false, + "whitespace": false + } +} From 11f64ec0d2bde7899119cf824e6942a6fc971c94 Mon Sep 17 00:00:00 2001 From: ocavue Date: Sun, 11 Oct 2020 21:05:10 +0800 Subject: [PATCH 2/5] move files into types/ --- package.json | 6 +++--- index.d.ts => types/index.d.ts | 0 .../mdast-util-from-markdown.test.ts | 0 tsconfig.json => types/tsconfig.json | 2 +- tslint.json => types/tslint.json | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename index.d.ts => types/index.d.ts (100%) rename mdast-util-from-markdown.test.ts => types/mdast-util-from-markdown.test.ts (100%) rename tsconfig.json => types/tsconfig.json (88%) rename tslint.json => types/tslint.json (100%) diff --git a/package.json b/package.json index ed848ab..4011dfc 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ ], "files": [ "index.js", - "index.d.ts" + "types/index.d.ts" ], - "types": "index.d.ts", + "types": "types", "dependencies": { "@types/mdast": "^3.0.0", "mdast-util-to-string": "^1.0.0", @@ -61,7 +61,7 @@ "generate": "npm run generate-size", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test/index.js", - "test-types": "dtslint .", + "test-types": "dtslint types", "test": "npm run format && npm run generate && npm run test-coverage && npm run test-types" }, "nyc": { diff --git a/index.d.ts b/types/index.d.ts similarity index 100% rename from index.d.ts rename to types/index.d.ts diff --git a/mdast-util-from-markdown.test.ts b/types/mdast-util-from-markdown.test.ts similarity index 100% rename from mdast-util-from-markdown.test.ts rename to types/mdast-util-from-markdown.test.ts diff --git a/tsconfig.json b/types/tsconfig.json similarity index 88% rename from tsconfig.json rename to types/tsconfig.json index 85c0535..9a36131 100644 --- a/tsconfig.json +++ b/types/tsconfig.json @@ -8,7 +8,7 @@ "baseUrl": ".", "paths": { "mdast-util-from-markdown": [ - "index.d.ts" + "./index.d.ts" ] } } diff --git a/tslint.json b/types/tslint.json similarity index 100% rename from tslint.json rename to types/tslint.json From 6851047c95312655db9ba0480956d3879d4f1f67 Mon Sep 17 00:00:00 2001 From: ocavue Date: Sun, 11 Oct 2020 21:45:29 +0800 Subject: [PATCH 3/5] Update types/mdast-util-from-markdown.test.ts Co-authored-by: Christian Murphy --- types/mdast-util-from-markdown.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/types/mdast-util-from-markdown.test.ts b/types/mdast-util-from-markdown.test.ts index a50165c..a574e5c 100644 --- a/types/mdast-util-from-markdown.test.ts +++ b/types/mdast-util-from-markdown.test.ts @@ -1,25 +1,25 @@ // This file is for https://github.com/microsoft/dtslint . // Tests are type-checked, but not run. -import * as formMarkdown from 'mdast-util-from-markdown' +import * as fromMarkdown from 'mdast-util-from-markdown' function main() { const raw = '# text **strong**' // $ExpectType Root - formMarkdown(raw) + fromMarkdown(raw) // $ExpectType Root - formMarkdown(Buffer.alloc(8)) + fromMarkdown(Buffer.alloc(8)) // $ExpectType Root - formMarkdown(Buffer.alloc(8), {extensions: []}) + fromMarkdown(Buffer.alloc(8), {extensions: []}) // $ExpectType Root - formMarkdown(Buffer.alloc(8), 'utf-8', {mdastExtensions: []}) + fromMarkdown(Buffer.alloc(8), 'utf-8', {mdastExtensions: []}) // $ExpectError - formMarkdown(Buffer.alloc(8), 'utf-8', {allowDangerousHtml: true}) + fromMarkdown(Buffer.alloc(8), 'utf-8', {allowDangerousHtml: true}) } main() From 17e853c86a3a3ae32471a7ab449a94a699af0d01 Mon Sep 17 00:00:00 2001 From: ocavue Date: Sun, 11 Oct 2020 21:46:01 +0800 Subject: [PATCH 4/5] Update types/index.d.ts Co-authored-by: Christian Murphy --- types/index.d.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 0d45aad..ab3038e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -10,22 +10,22 @@ import {Type} from 'micromark/dist/constant/types' export = fromMarkdown -declare namespace fromMarkdown {} +declare namespace fromMarkdown { + interface MdastExtension { + enter: Record void> + exit: Record void> + } -interface MdastExtension { - enter: Record void> - exit: Record void> + interface Options { + extensions?: SyntaxExtension[] + mdastExtensions?: MdastExtension[] + } } -interface Options { - extensions?: SyntaxExtension[] - mdastExtensions?: MdastExtension[] -} - -declare function fromMarkdown(value: string | Buffer, options?: Options): Root +declare function fromMarkdown(value: string | Buffer, options?: fromMarkdown.Options): Root declare function fromMarkdown( value: string | Buffer, encoding?: BufferEncoding, - options?: Options + options?: fromMarkdown.Options ): Root From f303f499c994e81ee190823dd7964b7176b74596 Mon Sep 17 00:00:00 2001 From: ocavue Date: Sun, 11 Oct 2020 21:59:52 +0800 Subject: [PATCH 5/5] format --- types/index.d.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index ab3038e..cb858ad 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -22,7 +22,10 @@ declare namespace fromMarkdown { } } -declare function fromMarkdown(value: string | Buffer, options?: fromMarkdown.Options): Root +declare function fromMarkdown( + value: string | Buffer, + options?: fromMarkdown.Options +): Root declare function fromMarkdown( value: string | Buffer,