| Server IP : 159.203.156.69 / Your IP : 216.73.217.172 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/vinext/dist/utils/ |
Upload File : |
import fs from "node:fs";
//#region src/utils/safe-json-file.ts
/**
* Read and parse a JSON file, returning `null` if the file is missing,
* unreadable, or contains invalid JSON.
*
* Pass `onError` to log/observe failures while still receiving `null`. The
* callback is invoked for any thrown error from `readFileSync` or
* `JSON.parse` (e.g. `ENOENT`, syntax errors).
*
* Callers that need a default value other than `null` should map the result:
* `readJsonFile<string[]>(p) ?? []`
*/
function readJsonFile(filePath, options) {
try {
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
} catch (err) {
options?.onError?.(err);
return null;
}
}
//#endregion
export { readJsonFile };
//# sourceMappingURL=safe-json-file.js.map