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

NameTypeDefaultDescription
<Method>(parameters: any[]) => RecordKey

The type of the method to execute.

methodMethod

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?number50

The total number of attempts to try before throwing an error.

options.maxTime?number50

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'