Unique
unique
Deprecated
This method is deprecated and will be removed in a future version.
Generates a unique result using the results of the given method. Used unique entries will be stored internally and filtered from subsequent calls.
Available since v5.0.0
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.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. | |
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. |
Returns: ReturnType<Method>
ts
faker.unique<Method>(method: Method, args?: Parameters<Method>, options: {
compare: (obj: Record<RecordKey, RecordKey>, key: RecordKey) => -1 | 0,
currentIterations: number,
exclude: RecordKey | RecordKey[],
maxRetries: number,
maxTime: number,
startTime: number,
store: Record<RecordKey, RecordKey>
} = {}): ReturnType<Method>
faker.unique(faker.name.firstName) // 'Corbin'