oneuptime/Common/Utils/Slug.ts
Simon Larsen ce9c4cc3c0
fix lint
2022-09-21 21:07:04 +01:00

24 lines
616 B
TypeScript

import slugify from 'slugify';
import { customAlphabet } from 'nanoid';
import { numbers } from 'nanoid-dictionary';
import Faker from './Faker';
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}-${customAlphabet(numbers, 10)()}`;
slug = slug.toLowerCase();
return slug;
}
}