shelving
Version:
Toolkit for using data in JavaScript.
23 lines (22 loc) • 1.07 kB
TypeScript
import type { ImmutableDictionary } from "../util/dictionary.js";
import type { Validator } from "../util/validate.js";
import type { SchemaOptions } from "./Schema.js";
import { Schema } from "./Schema.js";
/** Allowed options for `DictionarySchema` */
export interface DictionarySchemaOptions<T> extends SchemaOptions {
readonly items: Validator<T>;
readonly value?: ImmutableDictionary | undefined;
readonly min?: number | undefined;
readonly max?: number | undefined;
}
/** Validate a dictionary object (whose props are all the same with string keys). */
export declare class DictionarySchema<T> extends Schema<ImmutableDictionary<T>> {
readonly value: ImmutableDictionary;
readonly items: Validator<T>;
readonly min: number;
readonly max: number;
constructor({ items, min, max, title, value, ...options }: DictionarySchemaOptions<T>);
validate(unsafeValue?: unknown): ImmutableDictionary<T>;
}
/** Valid dictionary object with specifed items. */
export declare const DICTIONARY: <T>(items: Validator<T>) => DictionarySchema<T>;