@intlayer/config
Version:
Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.
26 lines • 934 B
JavaScript
import { getConfiguration } from "../configFile/getConfiguration.mjs";
import { getPrefix } from "./detectPlatform.mjs";
import { removeUndefinedValueObject } from "./removeUndefinedValueObject.mjs";
const formatEnvName = (key, prefix) => prefix + key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toUpperCase();
const formatEnvVariable = (platform) => {
const intlayerConfig = getConfiguration();
const prefix = getPrefix(platform);
const env = {};
for (const [key, value] of Object.entries({
...intlayerConfig.content,
...intlayerConfig.internationalization,
...intlayerConfig.middleware,
...intlayerConfig.editor
})) {
if (typeof value === "string") {
env[formatEnvName(key, prefix)] = value;
} else {
env[formatEnvName(key, prefix)] = JSON.stringify(value);
}
}
return removeUndefinedValueObject(env);
};
export {
formatEnvVariable
};
//# sourceMappingURL=formatEnvVariable.mjs.map