unique-slugify
v1.0.6
Published
A library for generating unique slugs in JavaScript and TypeScript.
Downloads
8
Maintainers
Readme
Indroduction
This package provides functionality to generate unique slugs or unique IDs in Node js or ts applications.
Installation
npm i unique-slugify
import { generateUniqueSlug } from 'unique-slugify
Usage
node
---- Javascript and Typescript ---
we can use various scenarios in case of we need to generate unique id as a slug for documents for you can check it out :- other scenarios like need of random unique number you can also you this ;
const uniqueId = generateUniqueSlug();
Example Usage : ( for generating unique id for each document as like ID - use as slug )
const ProductSchema: Schema = new Schema({
name: { type: String, required: true },
slug: { type: String, unique: true, index: true },
description: { type: String, required: true }
});
ProductSchema.pre<Product>('save', async function (next) {
const slug = generateUniqueSlug();
this.slug = slug;
next();
});
```