33 lines
657 B
TypeScript
33 lines
657 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;
|
|
}
|