Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deep-redact

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-redact

Deeply redact sensitive data from JS primitives

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

deep-redact

Deep redact is a package that recursively redacts sensitive data from JavaScript primitives based on a list of keys.

Features

  • Redaction of data from strings, objects, classes, maps, sets, arrays, and symbols
  • Supports strict mode to throw an error or return original data in the event of an error.
  • Redact data from JSON strings
  • Redact data from URLs

Installation

npm install deep-redact

Usage

import { redact } from "deep-redact";

const data = {
    email: "hello@test.com",
    password: "123456",
    dontReactMe: "123456",
    jsonString: '{ "email": "hello@test.com"}',
    url: "https://cv.moshie.dev/redactor?this=test&password=12345&email=hello@test.com",
};

const result = redact(data, {
    list: ["email", "password"],
    strict: true,
    redactString: "[REDACTED]",
});

console.log(result);
/**
 * {
 *   email: "[REDACTED]",
 *   password: "[REDACTED]",
 *   dontReactMe: "123456",
 *   jsonString: {
 *     email: "[REDACTED]"
 *   },
 *   url: "https://cv.moshie.dev/redactor?email=[REDACTED]&password=[REDACTED]&this=test"
 * }
 */

Replacer

We also expose a replacer function that can be used with JSON.stringify and JSON.parse the redactor does this behind the scenes but you can use it if you want to.

import { replacer } from "deep-redact";

const data = {
    email: "hello@test.com",
    password: "123456",
    dontReactMe: "123456",
};

const replacer = replacer({
    list: ["email", "password"],
    strict: true,
    redactString: "[REDACTED]",
})

try {
    const raw = JSON.stringify(data, replacer);

    const result = JSON.parse(raw);

    console.log(result);
    /**
     * "{
     *   "email": "[REDACTED]",
     *   password: "[REDACTED]",
     *   dontReactMe: "123456",
     * }"
     */
} catch (e) {
    console.log(e);
}

Options

redactString - The string to replace the redacted data with. Default is [REDACTED].

list - An array of keys to redact. Default is [].

strict - A boolean to determine if the data should be redacted or not. Default is false.

Keywords

FAQs

Package last updated on 07 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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