@burakbey/redacted
v1.0.2
Published
A library that protects sensitive data in your code by redacting values and preventing unintentional exposure.
Downloads
22
Readme
🔐 @burakbey/redacted
This is a library designed to safeguard sensitive data in your code. It provides a Redacted
class that uses various techniques to prevent unintentional exposure of sensitive information. Even if an attempt is made to expose the data, it will appear as <redacted>
.
📚 Credits
This library is inspired by concepts discussed in this YouTube video.
🚀 Installation
To install the package, use your preferred package manager. Here’s an example using pnpm
:
pnpm add @burakbey/redacted
📝 Example Usage
The following example demonstrates usage in TypeScript. The library is also compatible with JavaScript.
import { Redacted } from '@burakbey/redacted';
// Unsafe Example:
// The value can be exposed if logged or written to a file without caution.
const password = 'super-secret-password';
console.log(password); // super-secret-password
// Safe Example:
// Use the `wrap` method to protect the value.
// The `unwrap` method explicitly reveals the original value, ensuring intentional access.
const password = Redacted.wrap('super-secret-password');
console.log(password); // <redacted>
console.log(Redacted.unwrap(password)); // super-secret-password
🔄 Change the Redacted Message
You can customize the default redacted message (<redacted>
) to any string you prefer. To do this, set the environment variable REDACTED_MESSAGE
to your desired value.
For example, if you set REDACTED_MESSAGE="[REDACTED]"
and run the code, the output will reflect this change.
import { Redacted } from '@burakbey/redacted';
const password = Redacted.wrap('super-secret-password');
console.log(password); // [REDACTED]
🧪 Code Coverage and Tests
Tests are crucial for ensuring that the library functions as expected. You can review the code coverage reports by visiting Codecov. The primary objective is to achieve complete coverage of the entire codebase through rigorous testing.
☕ Support
If you find this project useful and would like to support me, you can do so by visiting my website.