@cipherr/slug-generator
v1.0.1
Published
A quick slug generator for blog applications and apps that require keeping track of slugs
Readme
@cipherr/slug-generator
A quick slug generator for blog applications and apps that require keeping track of unique slugs.
Installation
You can install the package using npm:
npm install @cipherr/slug-generatorUsage
Here is a simple example of how to use the slug generator in your project:
const generateSlug = require("@cipherr/slug-generator");
const title = "My First Blog Post";
const slug = generateSlug(title);
console.log(slug);
// Output example: my-first-blog-post-c8317e3371f44e82b3d37c35c91152a5How It Works
The generateSlug function takes a string as input and performs the following operations:
- Converts the text to lowercase.
- Replaces spaces with hyphens
-. - Appends a generated UUID (with hyphens removed) to the end of the string to guarantee uniqueness.
This is particularly useful for systems where you need unique URL slugs for posts or items that might share similar titles.
API
generateSlug(text)
- text (string): The text you want to convert into a slug.
- Returns (string): The formatted slug identifying the text uniquely.
License
ISC
