ffbt
Version:
Build a Typescript app without pain
24 lines (23 loc) • 653 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.readJson = void 0;
const path = require("path");
const fs = require("fs");
const jsonExtension = ".json";
function isJsonFile(pathToFile) {
const fileExtension = path.extname(pathToFile);
return fileExtension === jsonExtension;
}
function readJson(pathToFile) {
if (!isJsonFile(pathToFile)) {
throw new Error("Only json files are supported");
}
try {
const jsonFile = fs.readFileSync(pathToFile, { encoding: "utf8" });
return JSON.parse(jsonFile);
}
catch (e) {
throw e;
}
}
exports.readJson = readJson;