@buka/nestjs-config
Version:
An easy to use nestjs config module
30 lines (29 loc) • 1.26 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "@nestjs/common", "fs/promises", "../utils/fs-exists.js"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonFileLoader = void 0;
const common_1 = require("@nestjs/common");
const promises_1 = require("fs/promises");
const fs_exists_js_1 = require("../utils/fs-exists.js");
function jsonFileLoader(filepath, encoding = 'utf-8') {
return async (options) => {
if (!await (0, fs_exists_js_1.fsExist)(filepath)) {
if (!options.suppressWarnings) {
common_1.Logger.warn(`json file not found: ${filepath}`, '@buka/nestjs-config/jsonFileLoader');
}
return {};
}
const content = await (0, promises_1.readFile)(filepath);
return JSON.parse(content.toString(encoding));
};
}
exports.jsonFileLoader = jsonFileLoader;
});