UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

41 lines (40 loc) 2.1 kB
import { type Sanitizer, StringSchema, type StringSchemaOptions } from "./StringSchema.js"; /** `type=""` prop for HTML `<input />` tags that are relevant for strings. */ export type TextSchemaType = "text" | "password" | "color" | "date" | "email" | "number" | "tel" | "search" | "url"; /** Options for `TextSchema` */ export interface TextSchemaOptions extends StringSchemaOptions { readonly type?: TextSchemaType | undefined; readonly match?: RegExp | undefined; readonly multiline?: boolean | undefined; } /** * Schema that defines a valid text string. * * Ensures value is string and optionally enforces min/max length, whether to trim whitespace, and regex match format. * Doesn't allow `null` to mean no value — empty string is the equivalent for StringSchema (because it means we'll never accidentally get `"null"` by converting the `null` to string). * * Defaults to a single line text string (newlines are stripped). Use `multiline=true` to allow newlines. */ export declare class TextSchema extends StringSchema { readonly type: TextSchemaType; readonly match: RegExp | undefined; readonly sanitizer: Sanitizer | undefined; readonly multiline: boolean; constructor({ type, match, multiline, ...options }: TextSchemaOptions); validate(unsafeValue?: unknown): string; sanitize(str: string): string; } /** Valid text, e.g. `Hello there!` */ export declare const TEXT: TextSchema; /** Valid text, `Hello there!`, with more than one character. */ export declare const REQUIRED_TEXT: TextSchema; /** Title string, e.g. `Title of something` */ export declare const TITLE: TextSchema; /** Optional name string, e.g. `Title of something` or `null` */ export declare const OPTIONAL_TITLE: import("./OptionalSchema.js").OptionalSchema<string>; /** Name string, e.g. `Name of Something` */ export declare const NAME: TextSchema; /** Optional name string, e.g. `Name of Something` or `null` */ export declare const OPTIONAL_NAME: import("./OptionalSchema.js").OptionalSchema<string>; /** Password string. */ export declare const PASSWORD: TextSchema;