This commit is contained in:
@@ -1,46 +1,48 @@
|
||||
export function formatDate(value: string, seconds = false): string {
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
...(seconds ? { second: '2-digit' } : {}),
|
||||
};
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
...(seconds ? { second: '2-digit' } : {}),
|
||||
};
|
||||
|
||||
return new Date(value).toLocaleString('it-IT', options);
|
||||
return new Date(value).toLocaleString('it-IT', options);
|
||||
}
|
||||
|
||||
export const capitalize = (str: string) =>
|
||||
str
|
||||
.toLowerCase()
|
||||
.split(' ')
|
||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(' ');
|
||||
str
|
||||
.toLowerCase()
|
||||
.split(' ')
|
||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(' ');
|
||||
|
||||
export type SplitMode = 'underscore' | 'camel' | 'auto';
|
||||
|
||||
/** Title-case a string while preserving short all-caps acronyms (e.g., XML) */
|
||||
const toTitleCase = (s: string) =>
|
||||
s
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.split(/\s+/)
|
||||
.map((w) => (/^[A-Z]{2,4}$/.test(w) ? w : w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()))
|
||||
.join(' ');
|
||||
s
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.split(/\s+/)
|
||||
.map((w) =>
|
||||
/^[A-Z]{2,4}$/.test(w) ? w : w.charAt(0).toUpperCase() + w.slice(1).toLowerCase(),
|
||||
)
|
||||
.join(' ');
|
||||
|
||||
const splitUnderscoreHyphen = (s: string) => s.replaceAll(/[_-]+/g, ' ');
|
||||
|
||||
/** Insert spaces at camelCase boundaries and around digit/letter edges */
|
||||
const splitCamel = (s: string) =>
|
||||
s
|
||||
// fooBar -> foo Bar ; foo2D -> foo 2D
|
||||
.replaceAll(/([a-z0-9])([A-Z])/g, '$1 $2')
|
||||
// XMLHttp -> XML Http (acronym + word)
|
||||
.replaceAll(/([A-Z])([A-Z][a-z])/g, '$1 $2')
|
||||
// letter<->digit boundaries
|
||||
.replaceAll(/([a-zA-Z])([0-9])/g, '$1 $2')
|
||||
.replaceAll(/([0-9])([a-zA-Z])/g, '$1 $2');
|
||||
s
|
||||
// fooBar -> foo Bar ; foo2D -> foo 2D
|
||||
.replaceAll(/([a-z0-9])([A-Z])/g, '$1 $2')
|
||||
// XMLHttp -> XML Http (acronym + word)
|
||||
.replaceAll(/([A-Z])([A-Z][a-z])/g, '$1 $2')
|
||||
// letter<->digit boundaries
|
||||
.replaceAll(/([a-zA-Z])([0-9])/g, '$1 $2')
|
||||
.replaceAll(/([0-9])([a-zA-Z])/g, '$1 $2');
|
||||
|
||||
/**
|
||||
* Split and capitalize either by underscores/hyphens or camelCase.
|
||||
@@ -50,14 +52,14 @@ const splitCamel = (s: string) =>
|
||||
* - "auto": pick underscore if present, otherwise camel
|
||||
*/
|
||||
export function splitAndCapitalize(str?: string, mode: SplitMode = 'auto'): string {
|
||||
if (!str) return '';
|
||||
if (!str) return '';
|
||||
|
||||
// normalize underscores/hyphens first for auto decision
|
||||
const hasUnderscoreLike = /[_-]/.test(str);
|
||||
const chosen: SplitMode = mode === 'auto' ? (hasUnderscoreLike ? 'underscore' : 'camel') : mode;
|
||||
// normalize underscores/hyphens first for auto decision
|
||||
const hasUnderscoreLike = /[_-]/.test(str);
|
||||
const chosen: SplitMode = mode === 'auto' ? (hasUnderscoreLike ? 'underscore' : 'camel') : mode;
|
||||
|
||||
const spaced = chosen === 'underscore' ? splitUnderscoreHyphen(str) : splitCamel(str);
|
||||
const spaced = chosen === 'underscore' ? splitUnderscoreHyphen(str) : splitCamel(str);
|
||||
|
||||
// collapse extra spaces, then title-case
|
||||
return toTitleCase(spaced.replaceAll(/\s+/g, ' ').trim());
|
||||
// collapse extra spaces, then title-case
|
||||
return toTitleCase(spaced.replaceAll(/\s+/g, ' ').trim());
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
type VerifiedEmailVisibilityOptions = {
|
||||
verifiedAt: string | null;
|
||||
persistedEmail: string;
|
||||
currentEmail: string;
|
||||
isEditing: boolean;
|
||||
verifiedAt: string | null;
|
||||
persistedEmail: string;
|
||||
currentEmail: string;
|
||||
isEditing: boolean;
|
||||
};
|
||||
|
||||
export function shouldShowVerifiedEmailBadge(options: VerifiedEmailVisibilityOptions): boolean {
|
||||
const { verifiedAt, persistedEmail, currentEmail, isEditing } = options;
|
||||
const { verifiedAt, persistedEmail, currentEmail, isEditing } = options;
|
||||
|
||||
if (!verifiedAt) {
|
||||
return false;
|
||||
}
|
||||
if (!verifiedAt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isEditing) {
|
||||
return true;
|
||||
}
|
||||
if (!isEditing) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return persistedEmail.trim() === currentEmail.trim();
|
||||
return persistedEmail.trim() === currentEmail.trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user