Files
Studio_Grasso/src/lib/format.ts
T
Claude 601d13cfaf test: suite completa di §11 e npm run verify verde
- html-validate su tutte le pagine; linkinator su astro preview (link, asset,
  CSS e ancore), con modalità --external per i siti esterni
- e2e Playwright: struttura e metadati di ogni pagina, 404, navigazione,
  sottomenu, menu mobile, ancore del vecchio sito, nessuna richiesta esterna,
  nessun cookie, localStorage vuoto, mappa solo dopo il clic, funzionamento
  senza JavaScript, modulo di contatto
- a11y: axe su tutte le pagine a 1440 e 390 px e negli stati interattivi,
  tastiera (skip link, sottomenu, menu mobile), focus visibile, testo al 200 %,
  reflow a 320 px, movimento ridotto
- check-compliance.mjs: P.IVA, link legali, risorse sicure, segnaposto,
  JSON-LD, sitemap, robots, .htaccess, badge e servizi, uso di
  «commercialista», riferimento L. 4/2013, budget
- fix: punti di interruzione in em, focus ciclico nel menu mobile,
  rel="noopener" sui link esterni del Markdown, numeri di telefono non spezzabili

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zJ9ZWGKvoKoxYwbmnRKdJ
2026-10-15 22:55:46 +00:00

73 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Funzioni di formattazione condivise (indirizzi, orari, link telefonici e mappe).
*/
import type { Phone, PostalAddress } from '../data/studio';
import { studio } from '../data/studio';
/** «Via XX Settembre, 163 — 14048 Montegrosso d’Asti (AT)» */
export function addressLine(a: PostalAddress): string {
return `${a.streetAddress} — ${a.postalCode} ${a.locality} (${a.province})`;
}
/** «14048 Montegrosso d’Asti (AT)» */
export function cityLine(a: PostalAddress): string {
return `${a.postalCode} ${a.locality} (${a.province})`;
}
export function telHref(phone: Phone): string {
return `tel:${phone.e164}`;
}
/** Numero da mostrare con spazi non separabili, così non va mai a capo. */
export function telText(phone: Phone | string): string {
return (typeof phone === 'string' ? phone : phone.display).replace(/ /g, '\u00a0');
}
export function mailtoHref(email: string, subject?: string): string {
return subject ? `mailto:${email}?subject=${encodeURIComponent(subject)}` : `mailto:${email}`;
}
/** Fasce orarie leggibili: «9:00 – 12:30 | 15:00 – 18:30». */
export function hoursLine(): string {
const short = (t: string) => t.replace(/^0/, '');
return studio.orari.fasce.map((f) => `${short(f.apertura)} – ${short(f.chiusura)}`).join(' | ');
}
/** Ricerca per indirizzo (le coordinate non sono verificate, brief §4.6). */
export function googleMapsUrl(query: string): string {
return `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}`;
}
export function googleDirectionsUrl(query: string): string {
return `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(query)}`;
}
export function openStreetMapUrl(query: string): string {
return `https://www.openstreetmap.org/search?query=${encodeURIComponent(query)}`;
}
/** Dominio leggibile di un URL esterno (es. «agenziaentrate.gov.it»). */
export function displayDomain(url: string): string {
return new URL(url).hostname.replace(/^www\./, '');
}
/** Data in italiano: «15 ottobre 2026». */
export function formatDateIt(date: Date): string {
return new Intl.DateTimeFormat('it-IT', {
day: 'numeric',
month: 'long',
year: 'numeric',
timeZone: 'Europe/Rome',
}).format(date);
}
/** Iniziali per l'avatar: «Dott.ssa Giulia Grasso» → «GG». */
export function initials(name: string): string {
return name
.replace(/^(Dott\.ssa|Dott\.|Avv\.|Rag\.)\s+/i, '')
.split(/\s+/)
.map((p) => p.charAt(0).toUpperCase())
.join('')
.slice(0, 2);
}