Scrubbr
Serialize JSON data using TypeScript.
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
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',
},
],
};
- Define a TypeScript file as your master schema:
type UserList = {
users: User[];
};
type User = {
name: string;
image: string;
};
- Load it into Scrubbr and serialize your data:
import Scrubbr from 'scrubbr';
const scrubbr = new Scrubbr('./schema.ts');
async function api() {
const data = getUsers();
return await scrubbr.serialize('UserList', data);
}
- Ouput
{
"users": [
{
"name": "John Doe",
"image": "http://i.pravatar.cc/300"
}
]
}
Documentation
Read the documentation to learn how do do more with Scrubbr.
License
MIT