Skip to content
Back to skills

Stacks Slug

ASecurity

Use when generating URL slugs in Stacks - creating unique slugs with database collision detection, the uniqueSlug function with table/column configuration, or basic slugification. Covers @stacksjs/slug.

  • 631 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 5, 2026
developmenttypescriptgobashdatabase

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add stacksjs/stacks --skill stacks-slug --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Stacks Slug?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Stacks Slug
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/stacksjs-stacks-slug/badge)](https://www.skillsdirectory.com/skills/stacksjs-stacks-slug)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: stacks-slug
description: Use when generating URL slugs in Stacks - creating unique slugs with database collision detection, the uniqueSlug function with table/column configuration, or basic slugification. Covers @stacksjs/slug.
license: MIT
compatibility: Bun >= 1.3.0, TypeScript
allowed-tools: Read Edit Write Bash Grep Glob
---

# Stacks Slug

URL-friendly slug generation with database uniqueness checking.

## Key Paths
- Core package: `storage/framework/core/slug/src/`

## Unique Slug (with Database Check)

```typescript
import { uniqueSlug } from '@stacksjs/slug'

// Basic usage — checks 'slug' column in inferred table
const slug = await uniqueSlug('My Blog Post Title')
// → 'my-blog-post-title'

// If 'my-blog-post-title' exists in DB:
// → 'my-blog-post-title-2'

// With options
const slug = await uniqueSlug('Product Name', {
  table: 'products',     // database table to check
  column: 'slug'         // column name (default: 'slug')
})
```

### How Collision Detection Works
1. Slugifies the input string
2. Queries the database for existing slug
3. If collision found, appends `-2`, `-3`, etc.
4. Returns the first available slug

## Basic Slugify (No Database Check)

```typescript
import { slugify } from '@stacksjs/slug'

slugify('Hello World!')           // 'hello-world'
slugify('Ünïcödé Têxt')          // 'unicode-text'
slugify('  Extra   Spaces  ')    // 'extra-spaces'
```

Re-exported from `ts-slug` — handles Unicode transliteration.

## Model Usage

Models typically use slugs via the `slug` attribute:

```typescript
defineModel({
  name: 'Post',
  attributes: {
    title: { validation: { rule: schema.string() } },
    slug: {
      unique: true,
      validation: { rule: schema.string() },
      // Auto-generated from title via uniqueSlug()
    }
  }
})
```

## SlugifyOptions

```typescript
interface SlugifyOptions {
  table?: string         // database table for uniqueness check
  column?: string        // column name (default: 'slug')
}
```

## Gotchas
- `uniqueSlug()` is async — it queries the database
- `slugify()` is sync — no database interaction
- Collision detection appends `-2`, `-3`, etc. (not random suffixes)
- Unicode characters are transliterated (u → u, e → e, etc.)
- For string-only slugification without DB, use `slug()` from `@stacksjs/strings` instead
- Tags and Categories both use unique slugs by default
- Slug columns should have a unique index in the database

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.