Update to use named exports via / /async /promise /sync, simplify references via self-referencing, refine examples.

This commit is contained in:
David Anson 2024-12-03 19:58:28 -08:00
parent e41f034bef
commit 8da43dd246
96 changed files with 635 additions and 548 deletions

View file

@ -1,6 +1,9 @@
// @ts-check
import markdownlint from "markdownlint";
import { applyFixes } from "markdownlint";
import { lint as lintAsync } from "markdownlint/async";
import { lint as lintPromise } from "markdownlint/promise";
import { lint as lintSync } from "markdownlint/sync";
const options = {
"files": [ "good.md", "bad.md" ],
@ -10,27 +13,39 @@ const options = {
}
};
// Makes a synchronous call, using result.toString for pretty formatting
const result = markdownlint.sync(options);
console.log(result.toString());
if (true) {
// Makes an asynchronous call
markdownlint(options, function callback(err, result) {
if (!err) {
// @ts-ignore
console.log(result.toString());
}
});
// Makes a synchronous call, uses result.toString for pretty formatting
const results = lintSync(options);
console.log(results.toString());
// Displays the result object directly
markdownlint(options, function callback(err, result) {
if (!err) {
console.dir(result, { "colors": true, "depth": null });
}
});
}
// Fixes all supported violations in Markdown content
const original = "# Heading";
const fixResults = markdownlint.sync({ "strings": { "content": original } });
const fixed = markdownlint.applyFixes(original, fixResults.content);
console.log(fixed);
if (true) {
// Makes an asynchronous call, uses result.toString for pretty formatting
lintAsync(options, function callback(error, results) {
if (!error && results) {
console.log(results.toString());
}
});
}
if (true) {
// Makes a Promise-based asynchronous call, displays the result object directly
const results = await lintPromise(options);
console.dir(results, { "colors": true, "depth": null });
}
if (true) {
// Fixes all supported violations in Markdown content
const original = "# Heading";
const results = lintSync({ "strings": { "content": original } });
const fixed = applyFixes(original, results.content);
console.log(fixed);
}