1.1.1 • Published 2 years ago

scrubbr v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Scrubbr

Tests npm version downloads

Serialize JSON data using TypeScript.

Simple Example

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 | API

Install

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:

{
  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:
// schema.ts

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

type User = {
  name: string;
  image: string;
};
  1. Load it into Scrubbr and serialize your data:
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);
}
  1. Ouput
{
  "users": [
    {
      "name": "John Doe",
      "image": "http://i.pravatar.cc/300"
    }
  ]
}

Express Middleware

To make things even easier in express, install the Scrubbr express middleware.

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

Documentation

Read the documentation to learn how do do more with Scrubbr.

License

MIT

1.1.1

2 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.1-alpha.10

3 years ago

0.0.1-alpha.8

3 years ago

0.0.1-alpha.9

3 years ago

0.0.1-alpha.7

3 years ago

0.0.1-alpha.6

3 years ago

0.0.1-alpha.5

3 years ago

0.0.1-alpha.4

3 years ago

0.0.1-alpha.3

3 years ago

0.0.1-alpha.2

3 years ago

0.0.1-alpha.1

3 years ago