-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
70 lines (60 loc) · 1.66 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { clsx, type ClassValue } from 'clsx';
import { customAlphabet } from 'nanoid';
import slugify from 'slugify';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const generateSlug = (title: string) => {
const slug = slugify(title, {
lower: true,
strict: true,
replacement: '-',
});
return slug;
};
export const nanoid = customAlphabet(
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
7,
); //
export const ToTitleCase = (str: string) => {
return str
.split('_')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(' ');
};
export const ToSnakeCase = (str: string) => {
return str
.split(' ')
.map((word) => word.toLowerCase())
.join('_');
};
export const getPricingCardWidth = (count: number) => {
if (count === 1) return 'w-full';
if (count === 2) return 'md:w-1/2';
if (count === 3) return 'lg:w-1/3';
return 'md:w-80 lg:w-96'; // Fixed width for overflow cases
};
export const isLocalEnvironment =
process.env.NEXT_PUBLIC_SITE_URL?.includes('localhost');
export const generateSlugWithNanoId = (title: string, {
withNanoIdSuffix = true,
prefix = ''
}: {
withNanoIdSuffix?: boolean
prefix?: string
} = {}) => {
const slug = slugify(title, {
lower: true,
strict: true,
replacement: '-',
});
const withSuffix = withNanoIdSuffix ? `${slug}-${nanoid()}` : slug;
return prefix ? `${prefix}-${withSuffix}` : withSuffix;
}
export const generateOrganizationSlug = (title: string) => {
return generateSlugWithNanoId(title, {
prefix: 'o',
withNanoIdSuffix: true,
});
}