URLSchemaclass
new URLSchema({ one = "URL", title = "URL", base, schemes = HTTP_SCHEMES, input = "url", max = 512, ...options }: URLSchemaOptions)| Param | Type | |
|---|---|---|
options | URLSchemaOptions | Options for URLSchema. required |
.value | string | Default string value used when the input is undefined. readonly |
.max | number | Maximum allowed character length. Defaults to 512 readonly |
.match | RegExp | Regular expression the sanitized string must match. readonly |
.case | "upper""lower" | Force the result to "upper" or "lower" case. readonly |
.input | StringInputType | HTML <input /> type="" hint for downstream UIs. Defaults to "url" readonly |
.base | URLURLString | Base URL that relative URLs are resolved against. readonly |
.schemes | URISchemes | Whitelist of allowed URL schemes. Defaults to HTTP_SCHEMES readonly |
| Return | |
|---|---|
URLSchema | Schema that defines a valid absolute or relative URL string. |
| Property | Type | |
|---|---|---|
.base | URLString | Base URL that relative URLs are resolved against, or undefined when not set. readonly |
.schemes | URISchemes | Whitelist of allowed URL schemes, e.g. ["https:", "http:"]. required readonly |
Schema that defines a valid absolute or relative URL string.
- Checks the URL scheme against a whitelist (always), and resolves relative URLs against
basewhen set. - URLs are limited to 512 characters, but generally these won't be
data:URIs so this is a reasonable limit.
Examples
const schema = new URLSchema({ base: "https://example.com" });
schema.validate("/page") // "https://example.com/page"