Split toolbox storage by module

This commit is contained in:
Shinuwa 2026-08-14 09:45:48 +02:00
parent 97253acb00
commit 588c1298cd
18 changed files with 1248 additions and 1180 deletions

View file

@ -0,0 +1,28 @@
// Rôle : normalise et compacte les compteurs toolbox.
import { uid } from "./shared.js";
function normalizeCounterValue(value) {
const parsed = Number.parseInt(value, 10);
return Number.isFinite(parsed) ? parsed : 0;
}
export function normalizeCountersData(data) {
return {
counters: (data?.counters || [])
.map((counter) => ({
id: counter?.id || uid("counter"),
label: String(counter?.label || "").trim(),
value: normalizeCounterValue(counter?.value)
}))
.filter((counter) => counter.label)
};
}
export function compactCountersDataForStorage(value) {
const counters = normalizeCountersData(value).counters.map((counter) => ({
id: counter.id,
label: counter.label,
value: counter.value
}));
return counters.length ? { counters } : null;
}