Socket
Socket
Sign inDemoInstall

@pnpm/config.env-replace

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pnpm/config.env-replace - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

dist/preview-1680634751300.js

13

dist/env-replace.js

@@ -13,3 +13,3 @@ "use strict";

}
const envValue = env[name];
const envValue = getEnvValue(env, name);
if (envValue === undefined) {

@@ -20,2 +20,13 @@ throw new Error(`Failed to replace env in config: ${orig}`);

}
const ENV_VALUE = /([^:-]+)(:?)-(.+)/;
function getEnvValue(env, name) {
const matched = name.match(ENV_VALUE);
if (!matched)
return env[name];
const [, variableName, colon, fallback] = matched;
if (Object.prototype.hasOwnProperty.call(env, variableName)) {
return !env[variableName] && colon ? fallback : env[variableName];
}
return fallback;
}
//# sourceMappingURL=env-replace.js.map

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

bar: 'bar_value',
zoo: '',
};

@@ -14,2 +15,5 @@ test.each([

['\\\\${foo}', '\\foo_value'],
['-${foo-fallback-value}-${bar:-fallback-value}', '-foo_value-bar_value'],
['-${qar-fallback-value}-${zoo-fallback-value}', '-fallback-value-'],
['-${qar-fallback-value}-${zoo:-fallback-for-empty-value}', '-fallback-value-fallback-for-empty-value']
])('success %s => %s', (settingValue, expected) => {

@@ -21,3 +25,5 @@ const actual = (0, env_replace_1.envReplace)(settingValue, ENV);

expect(() => (0, env_replace_1.envReplace)('${baz}', ENV)).toThrow(`Failed to replace env in config: \${baz}`);
expect(() => (0, env_replace_1.envReplace)('${foo-}', ENV)).toThrow(`Failed to replace env in config: \${foo-}`);
expect(() => (0, env_replace_1.envReplace)('${foo:-}', ENV)).toThrow(`Failed to replace env in config: \${foo:-}`);
});
//# sourceMappingURL=env-replace.spec.js.map

@@ -6,2 +6,3 @@ import { envReplace } from './env-replace';

bar: 'bar_value',
zoo: '',
}

@@ -14,2 +15,5 @@

['\\\\${foo}', '\\foo_value'],
['-${foo-fallback-value}-${bar:-fallback-value}', '-foo_value-bar_value'],
['-${qar-fallback-value}-${zoo-fallback-value}', '-fallback-value-'],
['-${qar-fallback-value}-${zoo:-fallback-for-empty-value}', '-fallback-value-fallback-for-empty-value']
])('success %s => %s', (settingValue, expected) => {

@@ -22,3 +26,5 @@ const actual = envReplace(settingValue, ENV);

expect(() => envReplace('${baz}', ENV)).toThrow(`Failed to replace env in config: \${baz}`);
expect(() => envReplace('${foo-}', ENV)).toThrow(`Failed to replace env in config: \${foo-}`);
expect(() => envReplace('${foo:-}', ENV)).toThrow(`Failed to replace env in config: \${foo:-}`);
})

@@ -11,3 +11,3 @@ const ENV_EXPR = /(?<!\\)(\\*)\$\{([^${}]+)\}/g

}
const envValue = env[name]
const envValue = getEnvValue(env, name)
if (envValue === undefined) {

@@ -18,1 +18,13 @@ throw new Error(`Failed to replace env in config: ${orig}`)

}
const ENV_VALUE = /([^:-]+)(:?)-(.+)/
function getEnvValue (env: NodeJS.ProcessEnv, name: string): string {
const matched = name.match(ENV_VALUE)
if (!matched) return env[name]
const [, variableName, colon, fallback] = matched
if (Object.prototype.hasOwnProperty.call(env, variableName)) {
return !env[variableName] && colon ? fallback : env[variableName]
}
return fallback
}

9

package.json
{
"name": "@pnpm/config.env-replace",
"version": "1.0.0",
"version": "1.1.0",
"homepage": "https://bit.cloud/pnpm/config/env-replace",
"main": "dist/index.js",

@@ -8,9 +9,9 @@ "componentId": {

"name": "env-replace",
"version": "1.0.0"
"version": "1.1.0"
},
"dependencies": {},
"devDependencies": {
"@babel/runtime": "7.20.0",
"@types/jest": "26.0.20",
"@types/node": "12.20.4",
"@types/jest": "26.0.20"
"@babel/runtime": "7.20.0"
},

@@ -17,0 +18,0 @@ "peerDependencies": {},

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