Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 📘 Added option to add functions to multiple categories #176

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions docs-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,29 @@ jsdoc2md.getTemplateData({
configure: 'jsdoc.json'
}).then(res => {
const categories = res.reduce((acc, current) => {
const c = current.category.toLowerCase();

if(!acc[c]) {
acc[c] = [];
const category = current.category.toLowerCase();

// Handle multiple categories
if( category.includes(',') ) {
const categories = category.split(', ');
categories.forEach((c) => {
if(!acc[c]) {
acc[c] = [];
}

acc[c].push({
...current,
category: c,
});
});
}
else {
if(!acc[category]) {
acc[category] = [];
}

acc[c].push(current);
acc[category].push(current);
}

return acc;
}, {});
Expand All @@ -37,10 +53,10 @@ jsdoc2md.getTemplateData({
fs.mkdirSync(docsOutputPath);
}

for(const [category, items] of Object.entries(categories)) {
for(let [category, items] of Object.entries(categories)) {
let md = `---\nslug: /${category.toLowerCase()}\n---\n\n# ${capitalize(category)}\n\n`;

md += items.map(getDocsSection).join('');
md += items.sort((funcA, funcB) => sortFunctions(funcA, funcB)).map(getDocsSection).join('');

fs.writeFileSync(path.join(docsOutputPath, `${category.toLowerCase()}.mdx`), md, { encoding: 'utf8' });
}
Expand All @@ -51,6 +67,17 @@ jsdoc2md.getTemplateData({
});
});

function sortFunctions(funcA, funcB) {
if(funcA.name < funcB.name) {
return -1;
}

if(funcA.name > funcB.name) {
return 1;
}

return 0;
}

function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
Expand Down
2 changes: 1 addition & 1 deletion packages/falso/src/lib/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { randCountry } from './country';
/**
* Generate a random address.
*
* @category Entities
* @category entities, address
*
* @example
*
Expand Down
2 changes: 1 addition & 1 deletion packages/falso/src/lib/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function randFormattedName<Options extends EmailOptions = never>(
/**
* Generate a random email.
*
* @category Person
* @category Person, User
*
* @example
*
Expand Down
2 changes: 1 addition & 1 deletion packages/falso/src/lib/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Post {
/**
* Generate a random post.
*
* @category entities
* @category entities, internet
*
* @example
*
Expand Down
2 changes: 1 addition & 1 deletion packages/falso/src/lib/superhero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface SuperheroEntity extends Superhero {
/**
* Generate a random superhero.
*
* @category entities
* @category entities, comic book
*
* @example
*
Expand Down
2 changes: 1 addition & 1 deletion packages/falso/src/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface User {
/**
* Generate a random user.
*
* @category entities
* @category entities, user
*
* @example
*
Expand Down