From 75759e1af8a8694cff330ef4690e85e8d62f2e5f Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 4 Mar 2022 12:38:22 +0100 Subject: [PATCH 1/2] docs: use last signature for api doc generation --- scripts/apidoc/directMethods.ts | 5 +++-- scripts/apidoc/moduleMethods.ts | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/apidoc/directMethods.ts b/scripts/apidoc/directMethods.ts index 616226ee522..159ad84833d 100644 --- a/scripts/apidoc/directMethods.ts +++ b/scripts/apidoc/directMethods.ts @@ -41,8 +41,9 @@ export function processDirectMethod( methodName.substring(0, 1).toUpperCase() + methodName.substring(1); console.log(`Processing Direct: ${upperMethodName}`); - const signature = (direct.type as TypeDoc.ReflectionType).declaration - .signatures[0]; + const signatures = (direct.type as TypeDoc.ReflectionType).declaration + .signatures; + const signature = signatures[signatures.length - 1]; writeApiDocsDirectPage(methodName); writeApiDocsData(methodName, [ diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts index 89c42a33a56..7b090d13e9c 100644 --- a/scripts/apidoc/moduleMethods.ts +++ b/scripts/apidoc/moduleMethods.ts @@ -50,7 +50,8 @@ function processModuleMethod(module: TypeDoc.DeclarationReflection): PageIndex { )) { const methodName = method.name; console.debug(`- ${methodName}`); - const signature = method.signatures[0]; + const signatures = method.signatures; + const signature = signatures[signatures.length - 1]; methods.push(analyzeSignature(signature, lowerModuleName, methodName)); } From ab3d8c3d6c5e9148756dd0e72ff76d4a66249cc1 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 7 Mar 2022 19:34:31 +0100 Subject: [PATCH 2/2] docs: add signature especially for the api docs --- src/random.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/random.ts b/src/random.ts index 47720de2b6b..c2d8ecb2bb4 100644 --- a/src/random.ts +++ b/src/random.ts @@ -179,6 +179,26 @@ export class Random { object: T, field?: unknown ): T[K]; + /** + * Returns a random key or value from given object. + * + * @template T The type of `Record` to pick from. + * @template K The keys of `T`. + * @param object The object to get the keys or values from. + * @param field If this is set to `'key'`, this method will a return a random key of the given instance. + * If this is set to `'value'`, this method will a return a random value of the given instance. + * Defaults to `'value'`. + * + * @example + * const object = { keyA: 'valueA', keyB: 42 }; + * faker.random.objectElement(object) // 42 + * faker.random.objectElement(object, 'key') // 'keyB' + * faker.random.objectElement(object, 'value') // 'valueA' + */ + objectElement, K extends keyof T>( + object: T, + field?: 'key' | 'value' + ): K | T[K]; objectElement, K extends keyof T>( object = { foo: 'bar', too: 'car' } as unknown as T, field = 'value'