array<T>(itemSchema: Schema<T>): ArraySchema<T>
itemSchema: Schema<T>
const schema = x.array(x.string) Copy
const schema = x.array(x.string)
const schema = x.array(x.string)schema.item // -> x.string Copy
const schema = x.array(x.string)schema.item // -> x.string
const schema = pipe(x.array(…), x.nonEmpty())const schema = pipe(x.array(…), x.nonEmpty('requires 1+ elements'))const schema = pipe(x.array(…), x.size({ min: 3 }))const schema = pipe(x.array(…), x.size({ min: 3, reason: '…' }))const schema = pipe(x.array(…), x.size({ max: 10 }))const schema = pipe(x.array(…), x.size({ max: 10, reason: '…' }))const schema = pipe(x.array(…), x.size({ min: 3, max: 10 }))const schema = pipe(x.array(…), x.size({ min: 3, max: 10, reason: '…' })) Copy
const schema = pipe(x.array(…), x.nonEmpty())const schema = pipe(x.array(…), x.nonEmpty('requires 1+ elements'))const schema = pipe(x.array(…), x.size({ min: 3 }))const schema = pipe(x.array(…), x.size({ min: 3, reason: '…' }))const schema = pipe(x.array(…), x.size({ max: 10 }))const schema = pipe(x.array(…), x.size({ max: 10, reason: '…' }))const schema = pipe(x.array(…), x.size({ min: 3, max: 10 }))const schema = pipe(x.array(…), x.size({ min: 3, max: 10, reason: '…' }))
const arrayOfMinimumFiveUpperCaseStrings = pipe( x.string, x.nonEmpty('this string must have some content'), x.map((str) => str.toUpperCase()), x.array, x.size({ min: 5, reason: 'requires 5+ elements' }),) Copy
const arrayOfMinimumFiveUpperCaseStrings = pipe( x.string, x.nonEmpty('this string must have some content'), x.map((str) => str.toUpperCase()), x.array, x.size({ min: 5, reason: 'requires 5+ elements' }),)
See
Example
Example: Access the array content schema with `.item`
Example: Constrain the length using `x.size` or `x.nonEmpty`
Example: Thanks to the `pipe` notation, you can construct complex schemas easily