vike
Version:
The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.
33 lines (32 loc) • 1.67 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfigValueTyped = getConfigValueTyped;
const utils_js_1 = require("../utils.js");
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
function getConfigValueTyped(configValue, configName, type) {
/* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
// Enable users to suppress global config values by setting the local config value to null
if (configValue.value === null) return null
*/
const { value, definedAtData } = configValue;
if (type)
assertConfigValueType(value, type, configName, definedAtData);
return configValue;
}
function assertConfigValueType(value, type, configName, definedAtData) {
(0, utils_js_1.assert)(value !== null);
const typeActual = typeof value;
if (typeActual === type)
return;
const valuePrintable = (0, utils_js_1.getValuePrintable)(value);
const problem = valuePrintable !== null
? `value ${picocolors_1.default.cyan(valuePrintable)}`
: `type ${picocolors_1.default.cyan(typeActual)}`;
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAtOptional)('Config', configName, definedAtData);
const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`;
(0, utils_js_1.assertUsage)(false, errMsg);
}