https://github.com/pallad-ts/secret
Prevent your secrets from accidental leak
https://github.com/pallad-ts/secret
config credentials logging logs nodejs password passwords secret typescript
Last synced: 10 months ago
JSON representation
Prevent your secrets from accidental leak
- Host: GitHub
- URL: https://github.com/pallad-ts/secret
- Owner: pallad-ts
- License: mit
- Created: 2020-01-02T22:01:34.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T05:34:30.000Z (over 3 years ago)
- Last Synced: 2025-07-12T11:04:32.256Z (12 months ago)
- Topics: config, credentials, logging, logs, nodejs, password, passwords, secret, typescript
- Language: TypeScript
- Homepage:
- Size: 756 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Secret 🤫
Prevent your secrets from accidental leak
---
[](https://circleci.com/gh/pallad-ts/secret/tree/master)
[](https://badge.fury.io/js/@pallad%2Fsecret)
[](https://coveralls.io/github/pallad-ts/secret?branch=master)
[](https://opensource.org/licenses/MIT)
---

Wraps any value and prevents it to:
* be converted to string
* serialized (for example by `JSON.stringify`)
* inspected (through `util.inspect`)
* logged (through `console.log`) or debugged.
# Use cases
* Passing around un/encrypted passwords
* Storing confidential credentials (api keys, database passwords)
* Wrapping config values
# Features
* 👷 Built with Typescript - full type friendly
* ✅ Supports auto wrapping functions results with Secret
* 😍 Easy integration with literally any library/framework
# Community
Join our [discord server](https://discord.gg/paTBKBxXnA)
# Installation
```shell
npm install @pallad/secret
```
# Usage
Just wrap it with `secret` or `new Secret`. It order to retrieve value you need to explicitly call `getValue` method
```typescript
import {Secret, secret} from '@pallad/secret';
const SECRET = 'someProtectedValue!3234#@#%4';
const protectedValue = new Secret(SECRET);
// or
const protectedValue2 = secret(SECRET);
protectedValue + ''; // '**SECRET**'
protectedValue.toString(); // '**SECRET**'
util.inspect(protectedValue); // **SECRET**
console.log(protectedValue); // **SECRET**
util.inspect(protectedValue, {customInspect: false}); // Secret [**SECRET**] {}
console.log(protectedValue.getValue()); // 'someProtectedValue!3234#@#%4'
```
## Custom description
Instead of `'**SECRET**'` you can print something else.
```typescript
import {Secret} from '@pallad/secret';
const protectedValue = new Secret(SECRET, 'CustomDescription');
String(protectedValue); // 'CustomDescription'
console.log(protectedValue); // CustomDescription
util.inspect(protectedValue, {customInspect: false}); // CustomDescription
```
## Wrapping function result
`protect` wraps a function with another function that wraps returned value with secret for you.
```typescript
import {protect, Secret} from '@pallad/secret';
const result1 = protect(x => 'protectedValue')();
Secret.is(result1); // true
result1.getValue(); // 'protectedValue')
```
Promises are also handled (full type support)
```typescript
const result2 = protect(x => Promise.resolve('protectedValue'))();
result2.then(x => {
Secret.is(x); // true
x.getValue(); // 'protectedValue'
})
```
## Checking if value is Secret
```typescript
import {Secret, secret} from '@pallad/secret';
Secret.is(new Secret('test')) // true
Secret.is(secret('test')) // true
Secret.is(protect(() => 'test')()) // true
Secret.is('secret') // false
```