UNPKG

@mdf.js/utils

Version:

MMS - API Core - Common utils tools

43 lines 1.22 kB
"use strict"; /** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.loadFile = loadFile; const tslib_1 = require("tslib"); const crash_1 = require("@mdf.js/crash"); const fs_1 = tslib_1.__importDefault(require("fs")); /** * Load the file from the path if this exist * @param path - path to file * @returns */ function loadFile(path, logger) { const ownLogger = (message) => { if (logger) { logger.debug(message); } }; if (!path) { ownLogger('No path provided'); return undefined; } else if (path && fs_1.default.existsSync(path)) { try { return fs_1.default.readFileSync(path); } catch (rawError) { ownLogger(crash_1.Crash.from(rawError).message); return undefined; } } else { // Stryker disable next-line all ownLogger(`No such file at path ${path}`); return undefined; } } //# sourceMappingURL=loadFile.js.map