From 5ce04b82664a747bc6a504c01ef138bc32d03814 Mon Sep 17 00:00:00 2001 From: Kevin Van Lierde Date: Fri, 4 Nov 2022 21:52:49 +0100 Subject: [PATCH] Adds Typescript support --- .gitignore | 2 +- lib/index.d.ts | 20 ++++++++++++++++++++ package.json | 3 ++- test/index.cjs | 3 ++- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 lib/index.d.ts diff --git a/.gitignore b/.gitignore index 08cddfa..839ff94 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ npm-debug.log* .nyc_output coverage.info test/fixtures/*/build -lib +lib/*.*js node_modules \ No newline at end of file diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..9821312 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,20 @@ +import { marked } from 'marked'; +import Metalsmith from 'metalsmith'; + +export default initMarkdown; +export interface Options extends marked.MarkedOptions { + /** + * - Key names of file metadata to render to HTML - can be nested + */ + keys?: string[]; + /** + * - Expand `*` wildcards in keypaths + */ + wildcard?: boolean; +}; +/** + * A Metalsmith plugin to render markdown files to HTML + * @param {Options} [options] + * @return {import('metalsmith').Plugin} + */ +declare function initMarkdown(options?: Options): Metalsmith.Plugin; diff --git a/package.json b/package.json index a71225d..65923f2 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "require": "./lib/index.cjs" }, "type": "module", + "types": "lib/index.d.ts", "files": [ "lib/*.js" ], @@ -44,7 +45,7 @@ "lint": "eslint --fix .", "lint:check": "eslint --fix-dry-run .", "release": "npm run build && release-it .", - "build": "microbundle --target node --no-sourcemap -f cjs,esm", + "build": "microbundle --target node --no-sourcemap -f cjs,esm --generateTypes=false", "test": "nyc mocha", "pretest": "npm run build" }, diff --git a/test/index.cjs b/test/index.cjs index 2552636..c4dfa77 100644 --- a/test/index.cjs +++ b/test/index.cjs @@ -4,6 +4,7 @@ const assert = require('assert') const equal = require('assert-dir-equal') const Metalsmith = require('metalsmith') const { name } = require('../package.json') +/* eslint-disable-next-line n/no-missing-require */ const markdown = require('..') let expandWildcardKeypath const path = require('path') @@ -15,7 +16,7 @@ function msCommon(dir) { describe('@metalsmith/markdown', function () { before(function (done) { import('../src/expand-wildcard-keypath.js').then(imported => { - expandWildcardKeypath = imported + expandWildcardKeypath = imported.default done() }) })