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

@incanta/config

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@incanta/config - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

lib/config-env.d.ts

4

lib/config.d.ts

@@ -9,3 +9,7 @@ export interface IConfigOptions {

private customValues;
private envVarConfig;
constructor(options?: IConfigOptions);
dir(): string;
private getFormattedConfig;
getConfiguredEnv(): any;
get<T>(key: string): T;

@@ -12,0 +16,0 @@ getWithParts<T>(keyParts: string[]): T;

@@ -15,2 +15,3 @@ "use strict";

customValues;
envVarConfig;
constructor(options) {

@@ -38,3 +39,49 @@ this.values = {};

(0, lodash_merge_1.default)(this.values, defaultValues, envValues, localValues, overrideValues);
// load the environment variables that are configured to be injected
// using config-env
const dirContents = fs_1.default.readdirSync(this.configDir, { encoding: "utf-8" });
this.envVarConfig = {};
for (const file of dirContents) {
if (file.startsWith("environment.")) {
this.envVarConfig = loader_1.Loader.loadFile(path_1.default.join(this.configDir, file));
break;
}
}
}
dir() {
return this.configDir;
}
getFormattedConfig(format) {
let value = "";
while (format.length > 0) {
const match = /\${([a-z.]+)}/g.exec(format);
if (match === null) {
value += format;
format = "";
}
else {
value += format.slice(0, match.index);
format = format.substring(match.index + match[0].length);
const configKey = match[1];
value += `${this.get(configKey)}`;
}
}
return value;
}
getConfiguredEnv() {
const extraEnv = {};
const envKeys = Object.keys(this.envVarConfig);
for (const key of envKeys) {
const configKey = this.envVarConfig[key];
const envValue = this.get(configKey);
if (typeof envValue === "object" &&
typeof envValue.format !== "undefined") {
extraEnv[key] = this.getFormattedConfig(envValue.format);
}
else {
extraEnv[key] = `${envValue}`;
}
}
return extraEnv;
}
get(key) {

@@ -41,0 +88,0 @@ const parts = key.split(".");

{
"name": "@incanta/config",
"version": "0.1.3",
"version": "0.1.4",
"main": "lib/index.js",

@@ -9,2 +9,6 @@ "exports": {

},
"bin": {
"config-env": "./lib/config-env.js"
},
"packageManager": "yarn@1.22.19",
"repository": "git@github.com:IncantaGames/config.git",

@@ -30,2 +34,3 @@ "author": "Incanta Games",

"@typescript-eslint/parser": "^5.48.0",
"cross-env": "^7.0.3",
"eslint": "^8.31.0",

@@ -32,0 +37,0 @@ "eslint-config-prettier": "^8.6.0",

@@ -17,2 +17,4 @@ import merge from "lodash.merge";

private envVarConfig: any;
public constructor(options?: IConfigOptions) {

@@ -52,4 +54,59 @@ this.values = {};

merge(this.values, defaultValues, envValues, localValues, overrideValues);
// load the environment variables that are configured to be injected
// using config-env
const dirContents = fs.readdirSync(this.configDir, { encoding: "utf-8" });
this.envVarConfig = {};
for (const file of dirContents) {
if (file.startsWith("environment.")) {
this.envVarConfig = Loader.loadFile(path.join(this.configDir, file));
break;
}
}
}
public dir(): string {
return this.configDir;
}
private getFormattedConfig(format: string): string {
let value = "";
while (format.length > 0) {
const match = /\${([a-z.]+)}/g.exec(format);
if (match === null) {
value += format;
format = "";
} else {
value += format.slice(0, match.index);
format = format.substring(match.index + match[0].length);
const configKey = match[1];
value += `${this.get<any>(configKey)}`;
}
}
return value;
}
public getConfiguredEnv(): any {
const extraEnv: any = {};
const envKeys = Object.keys(this.envVarConfig);
for (const key of envKeys) {
const configKey = this.envVarConfig[key];
const envValue = this.get<any>(configKey);
if (
typeof envValue === "object" &&
typeof envValue.format !== "undefined"
) {
extraEnv[key] = this.getFormattedConfig(envValue.format);
} else {
extraEnv[key] = `${envValue}`;
}
}
return extraEnv;
}
public get<T>(key: string): T {

@@ -56,0 +113,0 @@ const parts = key.split(".");

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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