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.7 to 0.1.8

2

package.json
{
"name": "@incanta/config",
"version": "0.1.7",
"version": "0.1.8",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "exports": {

@@ -130,13 +130,44 @@ import merge from "lodash.merge";

const variableRegex = /\$\{[a-zA-Z\-_0-9.]+\}/g;
const replaceValue = (value: string): void => {
const regexResult = value.matchAll(variableRegex);
for (const match of regexResult) {
const keyToReplace = match[0].slice(2, match[0].length - 1);
const value = this.tryGet<string | number | boolean>(keyToReplace);
if (value !== null) {
obj = obj.replace(match[0], `${value}`);
}
}
};
// replace all ${value} with the value from the config
if (typeof obj === "string") {
replaceValue(obj);
} else if (typeof obj === "object") {
// walk the object and replace all strings with the value from the config
const walkObject = (curObj: any): void => {
for (const property of Object.keys(curObj)) {
const value = curObj[property];
if (typeof value === "string") {
replaceValue(value);
} else if (typeof value === "object") {
walkObject(value);
}
}
};
walkObject(obj);
}
return obj as T;
}
public has(key: string): boolean {
public tryGet<T>(key: string): T | null {
try {
this.get(key);
const value = this.get<T>(key);
return value;
} catch {
return false;
return null;
}
return true;
}

@@ -143,0 +174,0 @@

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