Skip to content

collection()

Creates a CollectionFaker<T>. Generates an array from a faker or schema. Default length: [1, 5].

Mixins: Measurable, Nullable, Seedable

MethodDescriptionExample
.length(n)Exact lengthcollection(text().uuid()).length(3)
.minLength(n)Minimum lengthcollection(lorem().word()).minLength(2)
.maxLength(n)Maximum lengthcollection(lorem().word()).maxLength(5)
.unique()Deduplicate resultscollection(lorem().word()).unique().length(3)
.empty()Always []collection(text()).empty()

Schemas can be passed to collection():

typescript
collection(ItemSchema).length(3).create()
// [{ id: '...', name: '...', qty: 42 }, ...]

← Back to Faker API