@cocalc/backend
Version:
CoCalc backend functionality: functionality used by either the hub, the next.js server or the project.
43 lines • 1.63 kB
JavaScript
;
/*
* This file is part of CoCalc: Copyright © 2023 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.envToFloat = exports.envToInt = void 0;
const logger_1 = __importDefault(require("../logger"));
const L = (0, logger_1.default)("env-to-number").debug;
// parse environment variable and convert to integer, with fallback if number could not be parsed
function envToInt(name, fallback) {
const value = process.env[name];
if (value == null) {
L(`envToInt: using fallback value ${fallback} for ${name}`);
return fallback;
}
const parsed = parseInt(value);
if (isNaN(parsed)) {
L(`envToInt: could not parse ${name}=${value}, using fallback value ${fallback}`);
return fallback;
}
return parsed;
}
exports.envToInt = envToInt;
// parse environment variable and convert to float, with fallback if number could not be parsed
function envToFloat(name, fallback) {
const value = process.env[name];
if (value == null) {
L(`envToFloat: using fallback value ${fallback} for ${name}`);
return fallback;
}
const parsed = parseFloat(value);
if (isNaN(parsed)) {
L(`envToFloat: could not parse ${name}=${value}, using fallback value ${fallback}`);
return fallback;
}
return parsed;
}
exports.envToFloat = envToFloat;
//# sourceMappingURL=env-to-number.js.map