Search


Search something to see results

size

Works on anything with a size or length property of type number.
Commonly known: array, set, map and strings

It could also be your own types.

Type Parameters

  • T extends {} | {}

Parameters

  • options: Object

Returns Object

import * as x from 'unhoax'

// With a Set
const mySet = x.size({ min: 1, max: 10, reason: 'My sets are small' })
// or, using pipe:
const mySet = pipe(x.string, x.Set, x.size({ min: 1, max: 10, reason: 'My sets are small' }))

// With a string
const firstName = x.size({ min: 1, max: 80, reason: 'FirstNameConstraints' })

// With a custom type:
class Vector<T> {
x: number
y: number

get length(): number {}
static fromPosition = ({ x: number, y: number }): Vector =>
}

const vectorSchema = pipe(
x.object({ x: x.number, y: x.number }),
x.map(Vector.fromPosition),
x.size({ min: 1, max: 10, reason: 'My vectors are small' }),
) // Schema<LinkedList<T>>