UNPKG

@adonisjs/lucid-slugify

Version:

Generate and persist unique slugs in your database via Lucid models

27 lines (26 loc) 1.09 kB
import type { LucidRow } from '@adonisjs/lucid/types/model'; import { Slugifier } from '../slugifier.js'; import type { SlugifyConfig } from '../types.js'; declare module '@adonisjs/lucid/types/model' { interface LucidModel { /** * A collection of slugifiers in use for a given model */ $slugifiers: Map<string, Slugifier<LucidModel, any>>; } } /** * Convert a Lucid model attribute to a slug field that is auto-computed * and persisted to the database. * * Slug generation relies on one or more source fields whose value is concatenated * and converted to a URL safe slug. * * You can keep slugs unique using different strategies. * * - "dbIncrement": Appends a counter to duplicate slug values to make them * unique. This strategy will query the database first to find similar * slugs. * - "shortId": Appends a short id to every slug to make them unique. */ export declare function slugify<Model extends LucidRow, TKey extends keyof Model & string>(config: SlugifyConfig<Model, TKey>): (target: Model, property: TKey) => void;