'use strict'; var fs = require('fs'); var path = require('path'); function readFileSync(filepath, options) { if (!filepath) return; return fs.existsSync(filepath) ? fs.readFileSync(filepath, options) : undefined; } function readFileAsNormalizedStrSync(filepath, options) { const str = readFileSync(filepath, options); return str ? str.toString().replace(/(\r\n|\r|\n)/g, '\n') : undefined; } function readJSONFileSync(filepath, options) { const str = readFileAsNormalizedStrSync(filepath, options); return str ? JSON.parse(str) : undefined; } function writeFileSync(filePath, data, options) { if (!filePath) return; if (typeof data === 'object') { data = JSON.stringify(data); } if (!fs.existsSync(filePath)) { fs.mkdirSync(path.dirname(filePath), { recursive: true }); } fs.writeFileSync(filePath, data, options); } function writeJSONFileSync(filePath, data, options) { if (!filePath || !data) return; if (typeof data === 'object') { data = JSON.stringify(data); } writeFileSync(filePath, data, options); } exports.readFileAsNormalizedStrSync = readFileAsNormalizedStrSync; exports.readFileSync = readFileSync; exports.readJSONFileSync = readJSONFileSync; exports.writeFileSync = writeFileSync; exports.writeJSONFileSync = writeJSONFileSync;