| 1 |
/** |
| 2 |
* Migrate legacy comma-separated numeric ID strings into block attribute ID arrays. |
| 3 |
* Returns [] if the string contains any non‑numeric token (e.g. old slug-based values). |
| 4 |
*/ |
| 5 |
export function migrateNumericCsvPairToIds( |
| 6 |
legacyA?: string, |
| 7 |
legacyB?: string, |
| 8 |
): number[] { |
| 9 |
const raw = [legacyA ?? "", legacyB ?? ""].find( |
| 10 |
(s) => String(s).trim() !== "", |
| 11 |
); |
| 12 |
if (raw === undefined) { |
| 13 |
return []; |
| 14 |
} |
| 15 |
const parts = String(raw) |
| 16 |
.split(",") |
| 17 |
.map((s) => s.trim()) |
| 18 |
.filter(Boolean); |
| 19 |
const ids: number[] = []; |
| 20 |
for (const p of parts) { |
| 21 |
if (!/^\d+$/.test(p)) { |
| 22 |
return []; |
| 23 |
} |
| 24 |
const n = parseInt(p, 10); |
| 25 |
if (n > 0) { |
| 26 |
ids.push(n); |
| 27 |
} |
| 28 |
} |
| 29 |
return [...new Set(ids)]; |
| 30 |
} |
| 31 |
|