buddhism/utils/pathUtils.js

22 lines
422 B
JavaScript
Raw Normal View History

// utils/pathUtils.js
const path = require("path");
let normalizeCount = 0;
const MAX_NORMALIZE_DEPTH = 20;
export function safeNormalize(p) {
if (normalizeCount++ > MAX_NORMALIZE_DEPTH) {
console.error("[Path Normalize] Maximum depth reached:", p);
return p;
}
try {
return path
.normalize(p)
.replace(/\\/g, "/")
.replace(/\/{2,}/g, "/");
} finally {
normalizeCount--;
}
}