You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ghost/e2e/data-factory/utils.ts

31 lines
714 B

import {randomBytes} from 'crypto';
import {faker} from '@faker-js/faker';
/**
* Generate a MongoDB-style ObjectId
*/
export function generateId(): string {
const timestamp = Math.floor(Date.now() / 1000).toString(16);
const randomHex = randomBytes(8).toString('hex');
return timestamp + randomHex;
}
/**
* Generate a UUID
*/
export function generateUuid(): string {
return faker.string.uuid();
}
/**
* Generate a URL-friendly slug from text
*/
export function generateSlug(text: string): string {
return text
.toLowerCase()
.replace(/[^\w\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/--+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '');
}