UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

28 lines (27 loc) 1.47 kB
import type { ImmutableArray } from "../util/array.js"; import { type AbsoluteLink } from "../util/link.js"; import type { StringSchemaOptions } from "./StringSchema.js"; import { TextSchema } from "./TextSchema.js"; /** Allowed options for `LinkSchema` */ export interface LinkSchemaOptions extends Omit<StringSchemaOptions, "type" | "min" | "max" | "multiline"> { readonly base?: AbsoluteLink | undefined; readonly schemes?: ImmutableArray<string> | undefined; readonly hosts?: ImmutableArray<string> | undefined; } /** * Type of `StringSchema` that defines a valid URL link. * - Checks URL scheme against a whitelist (always), and checks URL domain against a whitelist (optional). * - URLs are limited to 512 characters, but generally these won't be data: URIs so this is a reasonable limit. * - Falsy values are converted to `""` empty string. */ export declare class LinkSchema extends TextSchema { readonly base: AbsoluteLink | undefined; readonly schemes: ImmutableArray<string> | undefined; readonly hosts: ImmutableArray<string> | undefined; constructor({ base, schemes, hosts, title, ...options }: LinkSchemaOptions); validate(unsafeValue: unknown): AbsoluteLink; } /** Valid link, e.g. `https://www.google.com` */ export declare const LINK: LinkSchema; /** Valid link, e.g. `https://www.google.com`, or `null` */ export declare const OPTIONAL_LINK: import("./OptionalSchema.js").OptionalSchema<`${string}:${string}`>;