dmd-readme-api
Version:
A jsdoc2md template plugin generating elegant, compact one-page APIs in markdown, suitable for embedding in a README.md.
46 lines (39 loc) • 1.45 kB
JavaScript
const _handledKinds = [
{ kind : 'class', title : 'Classes' },
{ kind : 'mixin', title : 'Mixins' },
{ kind : 'member', title : 'Members' },
{ kind : 'namespace', title : 'Namespaces' },
{ kind : 'constant', title : 'Constants' },
{ kind : 'component', title : 'Components' },
{ kind : 'function', title : 'Functions' },
{ kind : 'event', title : 'Events' },
{ kind : 'typedef', title : 'Typedefs' },
{ kind : 'external', title : 'Externals' },
{ kind : 'interface', interface : 'Interfaces' }
]
function handledKinds() { return _handledKinds }
function sortAll(sortFields, options) {
options.data.root.sort((a, b) => {
sortFields = [...sortFields, 'kind']
const indexAKind = _handledKinds.findIndex((k) => k.kind === a.kind)
const indexBKind = _handledKinds.findIndex((k) => k.kind === b.kind)
const aSortFields = sortFields.map(function(sortField) {
return a[sortField]
})
const bSortFields = sortFields.map(function(sortField) {
return b[sortField]
})
for (let i = 0; i < sortFields.length; i += 1) {
const fieldA = aSortFields[i]
const fieldB = bSortFields[i]
if (fieldA !== fieldB) {
return fieldA.localeCompare(fieldB)
}
}
if (indexAKind < indexBKind) { return -1 }
else if (indexAKind > indexBKind) { return 1 }
return a.name.localeCompare(b.name)
})
}
exports.handledKinds = handledKinds
exports.sortAll = sortAll