Skip to main content Link Search Menu Expand Document (external link)

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:

  1. Convert to lowercase
  2. Replace whitespace sequences with hyphens
  3. Remove non-alphanumeric characters (except hyphens)
  4. Collapse consecutive hyphens
  5. 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