MCPcopy
hub / github.com/josdejong/mathjs / iteratePath

Function iteratePath

tools/docgenerator.js:663–752  ·  view source on GitHub ↗
(functionNames, inputPath, outputPath, outputRoot)

Source from the content-addressed store, hash-verified

661 * @param {String} outputRoot Path to /docs/reference
662 */
663export function iteratePath (functionNames, inputPath, outputPath, outputRoot) {
664 if (!fs.existsSync(outputPath)) {
665 mkdirp.sync(outputPath)
666 }
667 const functions = collectDocs(functionNames, inputPath)
668 let issues = []
669 for (const fn of Object.values(functions)) {
670 issues = issues.concat(fn.issues)
671 const markdown = generateMarkdown(fn.doc, functions)
672 fs.writeFileSync(outputPath + '/' + fn.name + '.md', markdown)
673 }
674
675 /**
676 * Helper function to generate a markdown list entry for a function.
677 * Used to generate both alphabetical and categorical index pages.
678 * @param {string} name Function name
679 * @returns {string} Returns a markdown list entry
680 */
681 function functionEntry (name) {
682 const fn = functions[name]
683 let syntax = SYNTAX[name] || (fn.doc && fn.doc.syntax && fn.doc.syntax[0]) || name
684 syntax = syntax
685 // .replace(/^math\./, '')
686 .replace(/\s+\/\/.*$/, '')
687 .replace(/;$/, '')
688 if (syntax.length < 40) {
689 syntax = syntax.replace(/ /g, '&nbsp;')
690 }
691
692 let description = ''
693 if (fn.doc.description) {
694 description = fn.doc.description.replace(/\n/g, ' ').split('.')[0] + '.'
695 }
696
697 return '[' + syntax + '](functions/' + name + '.md) | ' + description
698 }
699
700 /**
701 * Change the first letter of the given string to upper case
702 * @param {string} text
703 */
704 function toCapital (text) {
705 return text[0].toUpperCase() + text.slice(1)
706 }
707
708 const order = ['core', 'construction', 'expression'] // and then the rest
709 function categoryIndex (entry) {
710 const index = order.indexOf(entry)
711 return index === -1 ? Infinity : index
712 }
713 function compareAsc (a, b) {
714 return a > b ? 1 : (a < b ? -1 : 0)
715 }
716 function compareCategory (a, b) {
717 const indexA = categoryIndex(a)
718 const indexB = categoryIndex(b)
719 return (indexA > indexB) ? 1 : (indexA < indexB ? -1 : compareAsc(a, b))
720 }

Callers 1

generateDocsFunction · 0.90

Calls 8

collectDocsFunction · 0.85
generateMarkdownFunction · 0.85
toCapitalFunction · 0.85
concatMethod · 0.65
forEachMethod · 0.65
keysMethod · 0.65
mapMethod · 0.65
sortMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…