mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-23 07:42:10 +00:00
19 lines
499 B
TypeScript
19 lines
499 B
TypeScript
import slugify from 'slugify';
|
|
import { customAlphabet } from 'nanoid';
|
|
import { numbers } from 'nanoid-dictionary';
|
|
|
|
export default class Slug {
|
|
public static getSlug(name: string): string {
|
|
name = String(name);
|
|
if (!name || !name.trim()) {
|
|
return '';
|
|
}
|
|
|
|
let slug: string = slugify(name, { remove: /[&*+~.,\\/()|'"!:@]+/g });
|
|
slug = `${slug}-${customAlphabet(numbers, 10)()}`;
|
|
slug = slug.toLowerCase();
|
|
|
|
return slug;
|
|
}
|
|
}
|