# scrubbr

> Serialize and sanitize JSON data using TypeScript.

Latest version **1.1.1** (published 2022-01-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install scrubbr
pnpm add scrubbr
yarn add scrubbr
bun add scrubbr
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2022-01-06 |
| First published | 2021-06-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jeremy Gillick |
| Maintainers | jgillick |

## Links

- npm: https://www.npmjs.com/package/scrubbr
- Repository: https://github.com/jgillick/scrubbr
- Homepage: https://jgillick.github.io/scrubbr/
- Issues: https://github.com/jgillick/scrubbr/issues
- npm.io page: https://npm.io/package/scrubbr

## Dependencies (1)

- [ts-json-schema-generator](https://npm.io/package/ts-json-schema-generator.md) ^0.93.0

## Recent versions

- 1.1.1 (latest) — 2022-01-06
- 1.1.0 — 2021-10-08
- 1.0.1 — 2021-10-07
- 1.0.0 — 2021-08-03
- 0.1.1 — 2021-08-03
- 0.1.0 — 2021-07-15
- 0.0.1-alpha.10 — 2021-06-30
- 0.0.1-alpha.9 — 2021-06-28
- 0.0.1-alpha.8 — 2021-06-28
- 0.0.1-alpha.7 — 2021-06-26
- 0.0.1-alpha.6 — 2021-06-23
- 0.0.1-alpha.5 — 2021-06-23
- 0.0.1-alpha.4 — 2021-06-22
- 0.0.1-alpha.3 — 2021-06-21
- 0.0.1-alpha.2 — 2021-06-15
- … 1 more at https://npm.io/package/scrubbr/versions

## README

# Scrubbr

[![Tests](https://github.com/jgillick/scrubbr/actions/workflows/test.yml/badge.svg)](https://github.com/jgillick/scrubbr/actions)
[![npm version](https://img.shields.io/npm/v/scrubbr)](https://badge.fury.io/js/scrubbr)
[![downloads](https://img.shields.io/npm/dm/scrubbr)](https://www.npmjs.com/package/scrubbr)

Serialize JSON data using TypeScript.

![Simple Example](https://github.com/jgillick/scrubbr/raw/main/example.png)

Serializing data sent from the webserver to the client shouldn't be hard. If you're already using TypeScript, you have everything you need. Scrubbr will use your TypeScript types to deeply transform and sanitize your data.

[Documentation](https://jgillick.github.io/scrubbr/) | [API](https://jgillick.github.io/scrubbr/api/scrubbr/)

## Install

```shell
npm i -S scrubbr
```

## Quick Start

The simplest example is to filter out sensitive data.

In this example we want to filter the email and password out of this sample data:

```javascript
{
  users: [
    {
      name: 'John Doe',
      image: 'http://i.pravatar.cc/300',
      email: 'donotspam@me.com',
      password: 'xxxsecretxxx',
    },
  ],
};
```

1. Define a TypeScript file as your master schema:

```typescript
// schema.ts

type UserList = {
  users: User[];
};

type User = {
  name: string;
  image: string;
};
```

2. Load it into Scrubbr and serialize your data:

```typescript
import Scrubbr from 'scrubbr';

// PERFORMANCE NOTE: this is a synchronous call!
// Load early and cache to a shared variable.
const scrubbr = new Scrubbr('./schema.ts');

function api() {
  const data = getUsers();

  // Serialize the data based on the UserList type defined in schema.ts
  return scrubbr.serialize('UserList', data);
}
```

3. Ouput

```typescript
{
  "users": [
    {
      "name": "John Doe",
      "image": "http://i.pravatar.cc/300"
    }
  ]
}
```

## Express Middleware

To make things even easier in express, install the [Scrubbr express middleware](https://github.com/jgillick/express-scrubbr).

```ts
app.get('/users', (req, res) => {
  const userData = fetchDataHere();
  resp.status(200)
    .scrubbr('UserList')
    .send(userData);
}
```

# Documentation

Read the [documentation](https://jgillick.github.io/scrubbr/) to learn how do do more with Scrubbr.

# License

[MIT](https://github.com/ajv-validator/ajv/blob/HEAD/LICENSE)

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