validateDictionary()function
validateDictionary(unsafeDictionary: PossibleDictionary<unknown>, validator: Validator<T>): ImmutableDictionary<T>
| Param | Type | |
|---|---|---|
unsafeDictionary | PossibleDictionary<unknown> | The dictionary (or iterable of entries) of potentially invalid values. required |
validator | Validator<T> | The validator to validate each value with. required |
| Return | |
|---|---|
ImmutableDictionary<T> | Dictionary with valid values. |
| Throws | |
|---|---|
unknown | string if one or more entry values did not validate (one "key: message" line per failure, joined by newlines). |
Validate the values of the entries in a dictionary object with a validator.
- Returns the original dictionary reference unchanged when every value was already valid (and the input was a plain dictionary, not an iterable).
Examples
validateDictionary({ a: "1", b: "2" }, STRING) // { a: "1", b: "2" }