extract server transform and validation helpers
This commit is contained in:
parent
aea2c9d56b
commit
e79bc2e339
10 changed files with 373 additions and 139 deletions
27
server/contentTransforms.js
Normal file
27
server/contentTransforms.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import path from "path";
|
||||
|
||||
export function normalizeBackgroundTileId(value, idToSymbol = null) {
|
||||
const normalizedId = String(value || "").trim();
|
||||
if (!normalizedId) {
|
||||
return "";
|
||||
}
|
||||
if (idToSymbol instanceof Map && idToSymbol.size > 0 && !idToSymbol.has(normalizedId)) {
|
||||
return "";
|
||||
}
|
||||
return normalizedId;
|
||||
}
|
||||
|
||||
export function areRowsOnlyFillChar(rows, fillChar = ".") {
|
||||
if (!Array.isArray(rows) || rows.length === 0) {
|
||||
return true;
|
||||
}
|
||||
return rows.every((row) => {
|
||||
const normalizedRow = String(row || "");
|
||||
return normalizedRow.length === 0 || normalizedRow.split("").every((ch) => ch === fillChar);
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveContentPath(contentRoot, relativePath) {
|
||||
const normalized = String(relativePath || "").replace(/\\/g, "/").replace(/^\/+/, "");
|
||||
return path.resolve(contentRoot, normalized);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue