File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -179,6 +179,26 @@ export class Random {
179179 object : T ,
180180 field ?: unknown
181181 ) : T [ K ] ;
182+ /**
183+ * Returns a random key or value from given object.
184+ *
185+ * @template T The type of `Record` to pick from.
186+ * @template K The keys of `T`.
187+ * @param object The object to get the keys or values from.
188+ * @param field If this is set to `'key'`, this method will a return a random key of the given instance.
189+ * If this is set to `'value'`, this method will a return a random value of the given instance.
190+ * Defaults to `'value'`.
191+ *
192+ * @example
193+ * const object = { keyA: 'valueA', keyB: 42 };
194+ * faker.random.objectElement(object) // 42
195+ * faker.random.objectElement(object, 'key') // 'keyB'
196+ * faker.random.objectElement(object, 'value') // 'valueA'
197+ */
198+ objectElement < T extends Record < string , unknown > , K extends keyof T > (
199+ object : T ,
200+ field ?: 'key' | 'value'
201+ ) : K | T [ K ] ;
182202 objectElement < T extends Record < string , unknown > , K extends keyof T > (
183203 object = { foo : 'bar' , too : 'car' } as unknown as T ,
184204 field = 'value'
You can’t perform that action at this time.
0 commit comments