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