Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ueno/config

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ueno/config - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

75

lib/index.js
'use strict';
const config = {};
const browser = {};
const defaults = {};
function Config() {
const proto = Object.getPrototypeOf(this);
const browser = {};
const defaults = {};
const variableName = '__uenoConfig';
// 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.
}
// Only server side
if (typeof window === 'undefined') {
// Setup dotenv
require('dotenv').config();
} else if (typeof window[variableName] === 'object') {
// Update real config object
Object.assign(this, window[variableName]);
}
// Set defaults
config.setDefaults = function setDefaults(defaultConfig) {
// Update default config
Object.assign(defaults, defaultConfig);
proto.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') {
// Update the real config object
Object.entries(defaultConfig).forEach(([key, value]) => {
if (typeof this[key] !== 'undefined') {
return;
}
if (typeof process.env[key] !== 'undefined') {
this[key] = process.env[key];
} else {
// Every key is treated as string to maintain persistency
// between POSIX and JS environment.
config[key] = String(value);
this[key] = String(value);
}
});
}
};
// get browser config
config.getBrowser = function getBrowser() {
const res = {};
proto.setBrowser = function setBrowser(browserConfig) {
Object.assign(browser, browserConfig);
};
Object.entries(browser)
.forEach(([key, value]) => {
// get browser config
proto.getBrowser = function getBrowser() {
const res = {};
Object.entries(browser).forEach(([key, value]) => {
// Make sure the environment already exists
if (typeof config[key] === 'undefined') {
if (typeof this[key] === 'undefined') {
return;

@@ -44,3 +53,3 @@ }

if (value !== false) {
res[key] = config[key];
res[key] = String(this[key]);
}

@@ -53,10 +62,6 @@

return res;
return res;
};
}
// Rehydration function for the browser
config.rehydrate = function rehydrate(obj) {
Object.assign(config, obj);
}
module.exports = config;
module.exports = new Config();
{
"name": "@ueno/config",
"version": "0.0.2",
"version": "0.0.3",
"description": "Environment configuration toolkit",

@@ -5,0 +5,0 @@ "repository": "ueno-llc/create-react-app",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc