Files
formbricks-formbricks/packages/lib/utils/strings.ts
Dhruwang Jariwala f358254e3c feat: Product onboarding with XM approach (#2770)
Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com>
Co-authored-by: Johannes <johannes@formbricks.com>
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2024-06-19 12:29:05 +00:00

27 lines
950 B
TypeScript

export const capitalizeFirstLetter = (string: string | null = "") => {
if (string === null) {
return "";
}
return string.charAt(0).toUpperCase() + string.slice(1);
};
// write a function that takes a string and truncates it to the specified length
export const truncate = (str: string, length: number) => {
if (!str) return "";
if (str.length > length) {
return str.substring(0, length) + "...";
}
return str;
};
// write a function that takes a string and removes all characters that could cause issues with the url and truncates it to the specified length
export const sanitizeString = (str: string, delimiter: string = "_", length: number = 255) => {
return str.replace(/[^0-9a-zA-Z\-._]+/g, delimiter).substring(0, length);
};
export const isCapitalized = (str: string) => str.charAt(0) === str.charAt(0).toUpperCase();
export const startsWithVowel = (str: string): boolean => {
return /^[aeiouAEIOU]/.test(str);
};