chore: add sorting to api tables (#2476)

This commit is contained in:
gerjanvangeest 2025-02-13 14:10:02 +01:00 committed by GitHub
parent e0e1738d05
commit 933a0ea089
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,6 +28,25 @@ const moduleGraph = await createModuleGraph(globs, {
], ],
}); });
/**
* @param {{name: string}} a
* @param {{name: string}} b
* @returns
*/
function sortName(a, b) {
const nameA = a.name?.toUpperCase(); // ignore upper and lowercase
const nameB = b.name?.toUpperCase(); // ignore upper and lowercase
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
// names must be equal
return 0;
}
/** /**
* Create ts.sourceFiles from the modules in the module graph * Create ts.sourceFiles from the modules in the module graph
* to pass to the CEM analyzer * to pass to the CEM analyzer
@ -58,20 +77,22 @@ const cem = create({
/** /**
* Filter out unwanted information from the docs * Filter out unwanted information from the docs
*/ */
declaration.members = declaration.members.filter( declaration.members = declaration.members
member => !inheritanceDenyList.includes(member.inheritedFrom?.name), .filter(
); /** @param {{inheritedFrom: {name: string}}} member */ member =>
!inheritanceDenyList.includes(member.inheritedFrom?.name),
)
.sort(sortName);
/** /**
* Set privacy for members based on naming conventions * Set privacy for members based on naming conventions
*/ */
for (const m of declaration.members) { for (const m of declaration.members) {
if (!m.privacy && !m.name?.startsWith('_') && !m.name?.startsWith('#')) { if (!m.privacy && !m.name?.startsWith('_') && !m.name?.startsWith('#')) {
m.privacy = 'public'; m.privacy = 'public';
} else if (!m.privacy && m.name?.startsWith('_')) {
m.privacy = 'protected';
} else if (m.name?.startsWith('#') || m.name?.startsWith('__')) { } else if (m.name?.startsWith('#') || m.name?.startsWith('__')) {
m.privacy = 'private'; m.privacy = 'private';
} else if (!m.privacy && m.name?.startsWith('_')) {
m.privacy = 'protected';
} }
} }
} }