Slug overview
Slug generation utilities and schemas.
Added in v0.1.0
Table of contents
Brands
SlugBrand (type alias)
Brand type for slugified strings.
Signature
export type SlugBrand = typeof SlugBrandedString.Type
Added in v0.1.0
Schema
Slug
Schema that transforms a string into its slug form.
Signature
export declare const Slug: Schema.Schema<string, string, never>
Example
import * as Schema from "effect/Schema"
import { Slug } from "@effect-native/schemas/Slug"
Schema.decodeUnknownSync(Slug)("Hello World") // "hello-world"
Added in v0.1.0
SlugBranded
Schema for a branded slug type.
The input string is slugified and branded.
Signature
export declare const SlugBranded: Schema.Schema<string & Brand<"Slug">, string, never>
Example
import * as Schema from "effect/Schema"
import { SlugBranded } from "@effect-native/schemas/Slug"
const slug = Schema.decodeUnknownSync(SlugBranded)("Hello World")
// slug: SlugBrand = "hello-world"
Added in v0.1.0
Slug
slugify
Converts a title string to a URL-safe slug.
Algorithm:
- Convert to lowercase
- Replace whitespace sequences with hyphens
- Remove non-alphanumeric characters (except hyphens)
- Collapse consecutive hyphens
- Trim leading/trailing hyphens
Signature
export declare const slugify: (title: string) => string
Example
import { slugify } from "@effect-native/schemas/Slug"
slugify("Hello World") // "hello-world"
slugify("This is My Title!") // "this-is-my-title"
Added in v0.1.0