X Enterprises
fastify-xconfig

xSlugify(string)

Converts a string to a URL-safe, lowercase, hyphenated slug.

xSlugify(string)

Converts any string to a URL-safe slug: lowercases, trims whitespace, replaces spaces with hyphens, strips non-word characters, and collapses consecutive hyphens.

Signature

fastify.xSlugify(string: string): string

Params

NameTypeRequiredDescription
stringstringYesThe input string to slugify

Returns

string — the slugified result.

Throws

Never throws. Non-string inputs are coerced via .toString().

Examples

Basic usage

fastify.xSlugify("Hello World");           // "hello-world"
fastify.xSlugify("  Blog Post Title!  ");  // "blog-post-title"
fastify.xSlugify("café au lait");          // "caf-au-lait"
fastify.xSlugify("C++ Programming");       // "c-programming"

Generating slugs for database records

fastify.post("/posts", async (request) => {
  const { title, content } = request.body;
  const slug = fastify.xSlugify(title);

  const post = await fastify.prisma.post.create({
    data: { title, slug, content },
  });

  return post;
});

See also

AI Context

package: "@xenterprises/fastify-xconfig"
method: fastify.xSlugify(string)
use-when: Convert any string to a URL-safe slug (lowercase, hyphenated)
returns: string
Copyright © 2026