aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-03-07 20:37:13 +0100
committerGitHub <[email protected]>2022-03-07 20:37:13 +0100
commitc115056e04d1e42f97c8d77daed3d9056c375953 (patch)
tree4d7e06fd659e8b218e9592cd1c938e13c56a95da /src
parent3c82057973146801336a81a710964d5816735732 (diff)
downloadfaker-c115056e04d1e42f97c8d77daed3d9056c375953.tar.xz
faker-c115056e04d1e42f97c8d77daed3d9056c375953.zip
docs: display correct signature (#596)
Diffstat (limited to 'src')
-rw-r--r--src/random.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/random.ts b/src/random.ts
index 47720de2..c2d8ecb2 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<T extends Record<string, unknown>, K extends keyof T>(
+ object: T,
+ field?: 'key' | 'value'
+ ): K | T[K];
objectElement<T extends Record<string, unknown>, K extends keyof T>(
object = { foo: 'bar', too: 'car' } as unknown as T,
field = 'value'