2022-04-05 19:56:10 +00:00
|
|
|
import slugify from 'slugify';
|
|
|
|
import { customAlphabet } from 'nanoid';
|
|
|
|
import { numbers } from 'nanoid-dictionary';
|
|
|
|
|
|
|
|
export default class Slug {
|
2022-04-12 19:23:49 +00:00
|
|
|
public static getSlug(name: string): string {
|
2022-04-05 19:56:10 +00:00
|
|
|
name = String(name);
|
2022-04-14 13:40:04 +00:00
|
|
|
if (!name || !name.trim()) {
|
|
|
|
return '';
|
|
|
|
}
|
2022-04-05 19:56:10 +00:00
|
|
|
|
2022-04-14 21:23:02 +00:00
|
|
|
let slug: string = slugify(name, { remove: /[&*+~.,\\/()|'"!:@]+/g });
|
2022-04-25 13:21:09 +00:00
|
|
|
slug = `${slug}-${customAlphabet(numbers, 10)()}`;
|
2022-04-05 19:56:10 +00:00
|
|
|
slug = slug.toLowerCase();
|
|
|
|
|
|
|
|
return slug;
|
|
|
|
}
|
|
|
|
}
|