aboutsummaryrefslogtreecommitdiff
path: root/scripts/apidoc/directMethods.ts
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-03-01 19:55:53 +0100
committerGitHub <[email protected]>2022-03-01 19:55:53 +0100
commit61fafe47547873fcde74e98bff2a70738df7d4f2 (patch)
tree379432fee1ba309ba1a004bd37af04bba4628a79 /scripts/apidoc/directMethods.ts
parent442812f66a5ad9a42e389ad1ae06dbbcddad4e99 (diff)
downloadfaker-61fafe47547873fcde74e98bff2a70738df7d4f2.tar.xz
faker-61fafe47547873fcde74e98bff2a70738df7d4f2.zip
docs: generate docs for fake() and unique() (#564)
Diffstat (limited to 'scripts/apidoc/directMethods.ts')
-rw-r--r--scripts/apidoc/directMethods.ts56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/apidoc/directMethods.ts b/scripts/apidoc/directMethods.ts
new file mode 100644
index 00000000..616226ee
--- /dev/null
+++ b/scripts/apidoc/directMethods.ts
@@ -0,0 +1,56 @@
+import * as TypeDoc from 'typedoc';
+import { writeApiDocsData, writeApiDocsDirectPage } from './apiDocsWriter';
+import { analyzeSignature } from './signature';
+import type { Page, PageIndex } from './utils';
+
+/**
+ * Analyzes and writes the documentation for direct methods such as `faker.fake()`.
+ *
+ * @param project The project used to extract the direct methods.
+ * @returns The generated pages.
+ */
+export function processDirectMethods(
+ project: TypeDoc.ProjectReflection
+): PageIndex {
+ const pages: PageIndex = [];
+
+ const directs = project
+ .getChildrenByKind(TypeDoc.ReflectionKind.Class)
+ .filter((ref) => ref.name === 'Faker')[0]
+ .getChildrenByKind(TypeDoc.ReflectionKind.Property)
+ .filter((ref) => ['fake', 'unique'].includes(ref.name));
+
+ for (const direct of directs) {
+ pages.push(processDirectMethod(direct));
+ }
+
+ return pages;
+}
+
+/**
+ * Analyzes and writes the documentation for a direct method such as `faker.fake()`.
+ *
+ * @param direct The direct method to process.
+ * @returns The generated pages.
+ */
+export function processDirectMethod(
+ direct: TypeDoc.DeclarationReflection
+): Page {
+ const methodName = direct.name;
+ const upperMethodName =
+ methodName.substring(0, 1).toUpperCase() + methodName.substring(1);
+ console.log(`Processing Direct: ${upperMethodName}`);
+
+ const signature = (direct.type as TypeDoc.ReflectionType).declaration
+ .signatures[0];
+
+ writeApiDocsDirectPage(methodName);
+ writeApiDocsData(methodName, [
+ analyzeSignature(signature, undefined, methodName),
+ ]);
+
+ return {
+ text: upperMethodName,
+ link: `/api/${methodName}.html`,
+ };
+}