Add stuff
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user