SlugSchemaclass

new SlugSchema({ max = 32, ...options }: SlugSchemaOptions)
ParamType
optionsSlugSchemaOptions
Options for a SlugSchema. required
    .valuestring
Default string value used when the input is undefined. readonly
    .maxnumber
Maximum allowed character length. Defaults to 32 readonly
    .matchRegExp
Regular expression the sanitized string must match. readonly
    .case"upper"
"lower"
Force the result to "upper" or "lower" case. readonly
    .inputStringInputType
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"