DictionarySchemaclass
new DictionarySchema<T>({
items,
one = items.one,
many = items.many,
placeholder = `No ${many}`,
min = 0,
max = Number.POSITIVE_INFINITY,
title = "Items",
value = {},
...options
}: DictionarySchemaOptions<T>)| Param | Type | |
|---|---|---|
options | DictionarySchemaOptions<T> | Options for DictionarySchema. required |
.items | Schema<T> | Schema every entry value in the dictionary must conform to. required readonly |
.value | ImmutableDictionary | Default dictionary used when the input is undefined. readonly |
.min | number | Minimum number of entries. Defaults to 0 readonly |
.max | number | Maximum number of entries. Defaults to Number.POSITIVE_INFINITY readonly |
| Return | |
|---|---|
DictionarySchema<T> | Schema that validates a dictionary object whose entries all share the same value schema and have string keys. |
| Property | Type | |
|---|---|---|
.items | Schema<T> | Schema is an object instance with a validate() method that converts unknown input into a known, valid type T. required readonly |
.min | number | required readonly |
.max | number | required readonly |
Schema that validates a dictionary object whose entries all share the same value schema and have string keys.
- Every entry value is validated by the
itemsschema. - Entry count is checked against
minandmax.
Examples
const schema = new DictionarySchema({ items: NUMBER });
schema.validate({ a: 1, b: 2 }); // { a: 1, b: 2 }