dailyShare.js held fillTemplate and formatCountdown, used across the whole TCG, under a Daily Card name. They now live in textFormat.js at the root, and the Daily Card helpers in daily/dailyFormat.js. 173 exported functions that other files call now explain what they return and how they treat missing values: the server game rules, the toolbox storage chain, the shared hooks and utilities, and the TCG display helpers. website/AGENTS.md asks the same of new shared functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 lines
802 B
JavaScript
20 lines
802 B
JavaScript
/**
|
|
* @file Met en forme les textes, dates et tailles affichés autour d'un envoi de toolbox.
|
|
*/
|
|
|
|
const MIB = 1024 * 1024;
|
|
|
|
/** Remplace chaque `{clé}` connue ; une clé absente de `values` reste écrite telle quelle. */
|
|
export function fillTemplate(text, values = {}) {
|
|
return String(text || "").replace(/\{(\w+)\}/g, (match, key) => (key in values ? String(values[key]) : match));
|
|
}
|
|
|
|
/** Date et heure en français, format moyen (« 3 déc. 2026, 14:05 »). */
|
|
export function formatShareDate(value) {
|
|
return new Intl.DateTimeFormat("fr-FR", { dateStyle: "medium", timeStyle: "short" }).format(new Date(value));
|
|
}
|
|
|
|
/** Taille en Mio, avec une décimale au plus. */
|
|
export function formatMiB(bytes) {
|
|
return new Intl.NumberFormat("fr-FR", { maximumFractionDigits: 1 }).format(bytes / MIB);
|
|
}
|