mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-22 03:10:42 -06:00
Co-authored-by: Dhruwang Jariwala <67850763+Dhruwang@users.noreply.github.com> Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
21 lines
753 B
TypeScript
21 lines
753 B
TypeScript
export function 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);
|
|
};
|