takin
Version:
Front end engineering base toolchain and scaffold
53 lines • 2.22 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.readJsonLike = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const json5 = __importStar(require("json5"));
const jsoncParser = __importStar(require("jsonc-parser"));
const path_1 = __importDefault(require("path"));
const constants_1 = require("../constants");
/**
* 读取类 json 文件
* 支持 json / jsonc / json5 三种格式
* @param filePath - 类 json 文件
* @returns json 文件内容
*/
async function readJsonLike(filePath) {
const extname = path_1.default.extname(filePath);
if (extname === constants_1.SupportConfigExtensions.json) {
return await fs_extra_1.default.readJson(filePath);
}
const fileContent = (await fs_extra_1.default.readFile(filePath)).toString('utf-8');
if (extname === constants_1.SupportConfigExtensions.jsonc) {
return jsoncParser.parse(fileContent);
}
return json5.parse(fileContent);
}
exports.readJsonLike = readJsonLike;
//# sourceMappingURL=readJsonLike.js.map