p5.js-web-editor/client/utils/getConfig.js

25 lines
616 B
JavaScript
Raw Normal View History

2020-06-13 12:51:26 +02:00
function isTestEnvironment() {
// eslint-disable-next-line no-use-before-define
return getConfig('NODE_ENV', { warn: false }) === 'test';
}
/**
* Returns config item from environment
*/
2020-06-13 12:51:26 +02:00
function getConfig(key, options = { warn: !isTestEnvironment() }) {
if (key == null) {
throw new Error('"key" must be provided to getConfig()');
}
2020-06-13 12:51:26 +02:00
const env = (typeof global !== 'undefined' ? global : window)?.process?.env || {};
const value = env[key];
2020-06-13 12:51:26 +02:00
if (value == null && options?.warn !== false) {
console.warn(`getConfig("${key}") returned null`);
}
return value;
}
2020-06-13 12:51:26 +02:00
export default getConfig;