add eslint / prettier
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-02-23 14:18:51 +01:00
parent 4d1d2e6ed8
commit 33d1425fbb
24 changed files with 1294 additions and 398 deletions

View File

@@ -1,45 +1,46 @@
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";
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, " ");
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.
@@ -48,17 +49,15 @@ const splitCamel = (s: string) =>
* - "camel": split on camelCase boundaries
* - "auto": pick underscore if present, otherwise camel
*/
export function splitAndCapitalize(str?: string, mode: SplitMode = "auto"): string {
if (!str) return "";
export function splitAndCapitalize(str?: string, mode: SplitMode = 'auto'): string {
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());
}