markdownlint-rule-helpers
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -61,2 +61,13 @@ // @ts-check | ||
/** | ||
* Compare function for Array.prototype.sort for ascending order of numbers. | ||
* | ||
* @param {number} a First number. | ||
* @param {number} b Second number. | ||
* @returns {number} Positive value if a>b, negative value if b<a, 0 otherwise. | ||
*/ | ||
module.exports.numericSortAscending = function numericSortAscending(a, b) { | ||
return a - b; | ||
}; | ||
// Returns true iff the sorted array contains the specified element | ||
@@ -130,3 +141,24 @@ module.exports.includesSorted = function includesSorted(array, element) { | ||
// Returns the indent for a token | ||
/** | ||
* Return the string representation of a fence markup character. | ||
* | ||
* @param {string} markup Fence string. | ||
* @returns {string} String representation. | ||
*/ | ||
module.exports.fencedCodeBlockStyleFor = | ||
function fencedCodeBlockStyleFor(markup) { | ||
switch (markup[0]) { | ||
case "~": | ||
return "tilde"; | ||
default: | ||
return "backtick"; | ||
} | ||
}; | ||
/** | ||
* Return the number of characters of indent for a token. | ||
* | ||
* @param {Object} token MarkdownItToken instance. | ||
* @returns {number} Characters of indent. | ||
*/ | ||
function indentFor(token) { | ||
@@ -149,3 +181,28 @@ const line = token.line.replace(/^[\s>]*(> |>)/, ""); | ||
// Calls the provided function for each matching token | ||
/** | ||
* Return the string representation of an unordered list marker. | ||
* | ||
* @param {Object} token MarkdownItToken instance. | ||
* @returns {string} String representation. | ||
*/ | ||
module.exports.unorderedListStyleFor = function unorderedListStyleFor(token) { | ||
switch (token.markup) { | ||
case "-": | ||
return "dash"; | ||
case "+": | ||
return "plus"; | ||
// case "*": | ||
default: | ||
return "asterisk"; | ||
} | ||
}; | ||
/** | ||
* Calls the provided function for each matching token. | ||
* | ||
* @param {Object} params RuleParams instance. | ||
* @param {string} type Token type identifier. | ||
* @param {Function} handler Callback function. | ||
* @returns {void} | ||
*/ | ||
function filterTokens(params, type, handler) { | ||
@@ -344,3 +401,13 @@ params.tokens.forEach(function forToken(token) { | ||
// Adds a generic error object via the onError callback | ||
/** | ||
* Adds a generic error object via the onError callback. | ||
* | ||
* @param {Object} onError RuleOnError instance. | ||
* @param {number} lineNumber Line number. | ||
* @param {string} [detail] Error details. | ||
* @param {string} [context] Error context. | ||
* @param {number[]} [range] Column and length of error. | ||
* @param {Object} [fixInfo] RuleOnErrorFixInfo instance. | ||
* @returns {void} | ||
*/ | ||
function addError(onError, lineNumber, detail, context, range, fixInfo) { | ||
@@ -405,3 +472,3 @@ onError({ | ||
const frontMatterTitleRe = | ||
new RegExp(frontMatterTitlePattern || "^\\s*title\\s*[:=]", "i"); | ||
new RegExp(String(frontMatterTitlePattern || "^\\s*title\\s*[:=]"), "i"); | ||
return !ignoreFrontMatter && | ||
@@ -411,3 +478,8 @@ frontMatterLines.some((line) => frontMatterTitleRe.test(line)); | ||
// Gets the most common line ending, falling back to platform default | ||
/** | ||
* Gets the most common line ending, falling back to the platform default. | ||
* | ||
* @param {string} input Markdown content to analyze. | ||
* @returns {string} Preferred line ending. | ||
*/ | ||
function getPreferredLineEnding(input) { | ||
@@ -446,3 +518,9 @@ let cr = 0; | ||
// Normalizes the fields of a fixInfo object | ||
/** | ||
* Normalizes the fields of a RuleOnErrorFixInfo instance. | ||
* | ||
* @param {Object} fixInfo RuleOnErrorFixInfo instance. | ||
* @param {number} [lineNumber] Line number. | ||
* @returns {Object} Normalized RuleOnErrorFixInfo instance. | ||
*/ | ||
function normalizeFixInfo(fixInfo, lineNumber) { | ||
@@ -457,3 +535,10 @@ return { | ||
// Fixes the specifide error on a line | ||
/** | ||
* Fixes the specified error on a line of Markdown content. | ||
* | ||
* @param {string} line Line of Markdown content. | ||
* @param {Object} fixInfo RuleOnErrorFixInfo instance. | ||
* @param {string} lineEnding Line ending to use. | ||
* @returns {string} Fixed content. | ||
*/ | ||
function applyFix(line, fixInfo, lineEnding) { | ||
@@ -460,0 +545,0 @@ const { editColumn, deleteCount, insertText } = normalizeFixInfo(fixInfo); |
{ | ||
"name": "markdownlint-rule-helpers", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "A collection of markdownlint helper functions for custom rules", | ||
@@ -5,0 +5,0 @@ "main": "helpers.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23872
575