Files
pichunt/shared/utils/sluggy.ts
T
2025-08-01 01:38:08 +02:00

33 lines
662 B
TypeScript

import slugify from 'slugify';
export function sluggy(object: {
name?: string | null | undefined;
title?: string | null | undefined;
id: number | string;
}) {
const { id, name, title } = object;
let string = '';
if (!!name && name.length > 0) {
string =
slugify(name.substring(0, 25), {
replacement: '-',
lower: true,
strict: true,
trim: true
}) + '-';
} else if (!!title && title.length > 0) {
string =
slugify(title.substring(0, 25), {
replacement: '-',
lower: true,
strict: true,
trim: true
}) + '-';
}
string += `${id}`;
return string;
}