oneuptime/Common/Utils/Slug.ts
Simon Larsen b66fcd0ce7
fix tests
2023-08-21 13:09:13 +01:00

22 lines
524 B
TypeScript

import slugify from 'slugify';
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}-${Faker.randomNumbers(10)}`;
slug = slug.toLowerCase();
return slug;
}
}