New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

safe-env

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

safe-env - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

2

package.json
{
"name": "safe-env",
"version": "1.1.0",
"version": "1.2.0",
"description": "Returns all environment variables with sensitive values hidden, great for logs",

@@ -5,0 +5,0 @@ "author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",

@@ -47,2 +47,20 @@ # safe-env

## Custom predicate function
You can pass a custom predicate function that returns true based on the
property name to filter custom values. For example to hide all properties
with string 'token' in them
```js
const o = {
foo: 42,
myToken: 'secret',
'another-token': 'very secret'
}
const tokenName = (key) => key.toLowerCase().indexOf('token') !== -1
const out = safeEnv(tokenName, o)
// out has both 'myToken' and 'another-token' values replaced
// with '<hidden>'
```
### Small print

@@ -52,3 +70,2 @@

* [@bahmutov](https://twitter.com/bahmutov)

@@ -58,3 +75,2 @@ * [glebbahmutov.com](http://glebbahmutov.com)

License: MIT - do anything with the code, but don't blame me if it does not work.

@@ -61,0 +77,0 @@

@@ -6,2 +6,3 @@ 'use strict'

const privateKeys = require('./private-keys')
const replacement = '<hidden>'

@@ -14,13 +15,32 @@ function upperCaseEnvVariables (object) {

function hideSomeVariables (o, names) {
const hideSpecifiedKeys = (val, key) => {
return R.contains(key, names) ? '<hidden>' : val
function valueKeyPredicate (keyPredicate) {
return function (val, key) {
return keyPredicate(key) ? replacement : val
}
return R.mapObjIndexed(hideSpecifiedKeys, o)
}
function hideSomeVariables (o, names) {
const hideSpecifiedKeys = valueKeyPredicate((key) => R.contains(key, names))
return filterPredicate(hideSpecifiedKeys, o)
}
function filterStringMatches (names, object) {
const ups = upperCaseEnvVariables(object)
return hideSomeVariables(ups, names)
}
function filterPredicate (predicate, object) {
return R.mapObjIndexed(predicate, object)
}
function safeEnv (names, object) {
names = names || privateKeys
const ups = upperCaseEnvVariables(object || process.env)
return hideSomeVariables(ups, names)
object = object || process.env
if (Array.isArray(names)) {
return filterStringMatches(names, object)
}
if (typeof names === 'function') {
return filterPredicate(valueKeyPredicate(names), object)
}
throw new Error('Not sure what to do with these arguments')
}

@@ -27,0 +47,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