Skip to content

Arcjet Redact quick start

The Arcjet Redaction library makes it easy to redact sensitive information locally. It is a utility library independent of the main Arcjet SDK so can be used with or without other Arcjet rules.

What is Arcjet? Arcjet helps developers protect their apps in just a few lines of code. Implement rate limiting, bot protection, email validation, and defense against common attacks.

SDK installation

Follow these steps to get started:

1. Install Arcjet Redact

In your project root, run the following command to install the Arcjet redact library:

Terminal window
npm i @arcjet/redact

2. Redact some text

Now all you have to do to Redact text is to call the redact function. It can be configured to redact a number of built-in entity types, or else you can provide a custom detect function to redact your own types. The types that we support by default are: email, phone-number, ip-address, credit-card.

import { redact } from "@arcjet/redact";
const text = "my email address is test@example.com";
const [redacted] = await redact(text, {
entities: ["email"],
});
console.log(redacted);
// my email address is <Redacted email #1>

3. Unredact a response

If you want to un-redact some text that contains the replacements from the redact function just call unredact, it is passed as the value in the return array.

import { redact } from "@arcjet/redact";
const text = "My email address is test@example.com";
const [redacted, unredact] = await redact(text, {
entities: ["email"],
});
console.log(redacted);
// My email address is <Redacted email #1>
const unredacted = unredact("Your email address is <Redacted email #1>");
console.log(unredacted);
// Your email address is test@example.com

Get help

Need help with anything? Email us or join our Discord to get support from our engineering team.

Discussion