Unique
Generates a unique result using the results of the given method. Used unique entries will be stored internally and filtered from subsequent calls.
Parameters
Name | Type | Default | Description |
---|---|---|---|
<Method> | (parameters: any[]) => RecordKey | The type of the method to execute. | |
method | Method | The method used to generate the values. | |
args? | Parameters<Method> | The arguments used to call the method. | |
options | { ... } | {} | The optional options used to configure this method. |
options.currentIterations? | number | This parameter does nothing. | |
options.exclude? | RecordKey | RecordKey[] | [] | The value or values that should be excluded/skipped. |
options.maxRetries? | number | 50 | The total number of attempts to try before throwing an error. |
options.maxTime? | number | 50 | The time in milliseconds this method may take before throwing an error. |
options.startTime? | number | This parameter does nothing. | |
options.store? | Record<RecordKey, RecordKey> | The store of unique entries. Defaults to a global store. | |
options.compare? | (obj: Record<RecordKey, RecordKey>, key: RecordKey) => -1 | 0 | The function used to determine whether a value was already returned. Defaults to check the existence of the key. |
Returns: ReturnType<Method>
faker.unique<Method>(method: Method, args?: Parameters<Method>, options: {
currentIterations: number,
exclude: RecordKey | RecordKey[],
maxRetries: number,
maxTime: number,
startTime: number,
store: Record<RecordKey, RecordKey>,
compare: (obj: Record<RecordKey, RecordKey>, key: RecordKey) => -1 | 0
} = {}): ReturnType<Method>
faker.unique(faker.name.firstName) // 'Corbin'