SlugSchemaclass
new SlugSchema({ max = 32, ...options }: SlugSchemaOptions)| Param | Type | |
|---|---|---|
options | SlugSchemaOptions | Options for a SlugSchema. required |
.value | string | Default string value used when the input is undefined. readonly |
.max | number | Maximum allowed character length. Defaults to 32 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. readonly |
| Return | |
|---|---|
SlugSchema | Schema that defines a valid slug, e.g. this-is-a-slug. |
Schema that defines a valid slug, e.g. this-is-a-slug.
- Useful for URL components, usernames, etc.
- Input is sanitized into a lowercase, hyphen-separated slug.
- Slugs are limited to 32 characters.
Examples
const schema = new SlugSchema({});
schema.validate("This is a Slug!") // "this-is-a-slug"