UNPKG

@sentzunhat/zacatl

Version:

A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.

47 lines 1.52 kB
import fs from 'fs'; import { BadRequestError } from '../../error/index.js'; export const isPlainObject = (value) => { return (typeof value === 'object' && value !== null && !Array.isArray(value) && Object.prototype.toString.call(value) === '[object Object]'); }; export const deepMerge = (base, override) => { const out = { ...base }; for (const [key, overrideValue] of Object.entries(override)) { const baseValue = out[key]; if (isPlainObject(baseValue) && isPlainObject(overrideValue)) { out[key] = deepMerge(baseValue, overrideValue); continue; } out[key] = overrideValue; } return out; }; export const readJsonFile = (filePath) => { const content = fs.readFileSync(filePath, 'utf-8'); const parsed = JSON.parse(content); if (!isPlainObject(parsed)) { throw new BadRequestError({ message: `Invalid locale JSON shape in ${filePath}`, reason: 'Locale file must contain a plain JSON object', component: 'I18nNode', operation: 'readJsonFile', metadata: { filePath }, }); } return parsed; }; export const findExistingDir = (candidates) => { for (const candidate of candidates) { try { if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) { return candidate; } } catch { } } return null; }; //# sourceMappingURL=helpers.js.map