@ueno/config
Advanced tools
Comparing version 0.0.1 to 0.0.2
'use strict'; | ||
const config = {}; | ||
const browser = {}; | ||
const defaults = {}; | ||
// Only server side | ||
if (typeof window === 'undefined') { | ||
// Setup dotenv | ||
require('dotenv').config(); | ||
// Assign env to config | ||
Object.assign(config, process.env); | ||
// TODO: Warn when stuff is accessed without any default declerations. | ||
} | ||
// Set defaults | ||
function defaults(defaultConfig) { | ||
console.log('defaults', defaultConfig); | ||
return true; | ||
config.setDefaults = function setDefaults(defaultConfig) { | ||
// Update default config | ||
Object.assign(defaults, defaultConfig); | ||
// Update the real config object | ||
Object.entries(defaultConfig) | ||
.forEach(([key, value]) => { | ||
if (typeof config[key] === 'undefined') { | ||
// Every key is treated as string to maintain persistency | ||
// between POSIX and JS environment. | ||
config[key] = String(value); | ||
} | ||
}); | ||
} | ||
// Set available config to the browser | ||
function browser() { | ||
console.log('browser', browserConfig); | ||
return true; | ||
// get browser config | ||
config.getBrowser = function getBrowser() { | ||
const res = {}; | ||
Object.entries(browser) | ||
.forEach(([key, value]) => { | ||
// Make sure the environment already exists | ||
if (typeof config[key] === 'undefined') { | ||
return; | ||
} | ||
if (value !== false) { | ||
res[key] = config[key]; | ||
} | ||
if (typeof value === 'function') { | ||
res[key] = String(value(res[key])); | ||
} | ||
}); | ||
return res; | ||
} | ||
// Rehydration function for the browser | ||
function rehydrate() { | ||
console.log('rehydrate'); | ||
config.rehydrate = function rehydrate(obj) { | ||
Object.assign(config, obj); | ||
} | ||
module.exports = { | ||
config, | ||
defaults, | ||
browser, | ||
rehydrate, | ||
} | ||
module.exports = config; |
{ | ||
"name": "@ueno/config", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Environment configuration toolkit", | ||
@@ -5,0 +5,0 @@ "repository": "ueno-llc/create-react-app", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1814
49
2