Things
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m6s

This commit is contained in:
2026-10-13 22:50:51 +02:00
parent 50828af674
commit af76cf1050
18 changed files with 847 additions and 86 deletions

View File

@@ -0,0 +1,32 @@
// Small helpers shared by the Foundry -> Dragonroll document mappers
// (services/actor-foundry.js and services/item-foundry.js).
function numberOr(value, fallback) {
const number = Number(value);
return Number.isFinite(number) ? number : fallback;
}
function asText(value) {
return typeof value === 'string' ? value : '';
}
function plainText(value) {
return asText(value)
.replace(/<br\s*\/?>/gi, '\n')
.replace(/<\/p\s*>/gi, '\n')
.replace(/<[^>]*>/g, ' ')
.replace(/&nbsp;/gi, ' ')
.replace(/&amp;/gi, '&')
.replace(/&lt;/gi, '<')
.replace(/&gt;/gi, '>')
.replace(/\s+\n/g, '\n')
.trim();
}
function stringList(value) {
if (Array.isArray(value)) return value.map(asText).filter(Boolean);
if (typeof value === 'string') return [value];
return [];
}
module.exports = { numberOr, asText, plainText, stringList };