Socket
Socket
Sign inDemoInstall

scrubbr

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scrubbr

Serialize and sanitize JSON data using TypeScript.


Version published
Weekly downloads
1
decreased by-94.44%
Maintainers
1
Weekly downloads
 
Created
Source

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

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');

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

  // Serialize the data based on the UserList type defined in schema.ts
  return await scrubbr.serialize('UserList', data);
}
  1. 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

FAQs

Package last updated on 26 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc