# @cdssnc/sanitize-pii

> TypeScript module for removing personally identifiable information (PII) from text

Latest version **2.2.0** (published 2026-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cdssnc/sanitize-pii
pnpm add @cdssnc/sanitize-pii
yarn add @cdssnc/sanitize-pii
bun add @cdssnc/sanitize-pii
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2026-04-09 |
| First published | 2025-07-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 67.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 3 |
| Author | Government of Canada / Gouvernement du Canada |
| Maintainers | timarney, stephenmcmurtry, maxneuvians, ethanwallace, melaniebmn, dainetrinidad, clement.janin, bryan_robitaille, patheard |

## Links

- npm: https://www.npmjs.com/package/@cdssnc/sanitize-pii
- Repository: https://github.com/cds-snc/sanitize-pii
- Homepage: https://github.com/cds-snc/sanitize-pii#readme
- Issues: https://github.com/cds-snc/sanitize-pii/issues
- npm.io page: https://npm.io/package/@cdssnc/sanitize-pii

## Recent versions

- 2.2.0 (latest) — 2026-04-09
- 2.1.2 — 2026-02-23
- 2.1.1 — 2026-02-02
- 2.1.0 — 2025-10-29
- 2.0.3 — 2025-10-06
- 2.0.2 — 2025-08-27
- 2.0.1 — 2025-08-26
- 2.0.0 — 2025-08-06
- 1.2.2 — 2025-08-05
- 1.2.1 — 2025-07-29
- 1.2.0 — 2025-07-29
- 1.1.1 — 2025-07-28
- 1.1.0 — 2025-07-28
- 1.0.2 — 2025-07-25
- 1.0.1 — 2025-07-25
- … 1 more at https://npm.io/package/@cdssnc/sanitize-pii/versions

## README

# Sanitize PII

TypeScript module for removing personally identifiable information (PII) from text.  The PII this module removes by default can be seen in [`src/patterns.ts`](./src/patterns.ts).

## Installation

```sh
npm install @cdssnc/sanitize-pii
```

## Quick start

```typescript
import { sanitizePii, PiiSanitizer } from '@cdssnc/sanitize-pii';

// Simple usage with default patterns
const text = "Contact me at (555) 123-4567 with Account ID 1234";
const sanitized = sanitizePii(text);
console.log(sanitized);
// Output: "Contact me at [Redacted: phone_number] with Account ID 1234"

// Sanitizer with custom replacement template and pattern
const sanitizer = new PiiSanitizer({
  replacementTemplate: '***{name}***',
  patterns: [
    {
      name: 'account_id',
      regex: /\bAccount\sID\s\d{4}\b/g,
    }
  ]
});

const result = sanitizer.sanitize(text);
console.log(result);
// Output: "Contact me at ***phone_number*** with ***account_id***"
```

You can also use the module directly in a browser with the following CDN:
```html
<script src="https://cdn.jsdelivr.net/npm/@cdssnc/sanitize-pii@1.1.1/dist/umd/sanitize-pii.min.js"></script>
<script>
  const textareas = document.querySelectorAll('textarea');
  textareas.forEach(textarea => {
    textarea.value = sanitizePii(textarea.value);
  });
</script>
```

## Development

A [devcontainer](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers) has been provided to create a local or Codespaces dev environment.  If you submit a pull request, you can run the following to make sure everything works as expected:

```sh
npm ci
npm test
npm run lint
npm run format
npm run build
npm run test:build
```

---
_Source: https://npm.io/package/@cdssnc/sanitize-pii · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
