Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

scrubbr

Package Overview
Dependencies
67
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

2

dist/Scrubbr.d.ts

@@ -94,3 +94,3 @@ import { JSONSchema7 } from 'json-schema';

*/
serialize<Type = any>(schemaType: string, data: unknown, context?: ContextObject, options?: ScrubbrOptions): Type;
serialize<SerializedType = any>(schemaType: string, data: unknown, context?: ContextObject, options?: ScrubbrOptions): SerializedType;
/**

@@ -97,0 +97,0 @@ * Traverse into a node of data on an object to serialize.

@@ -249,8 +249,9 @@ "use strict";

Scrubbr.prototype.walkObjectNode = function (node, state) {
var _a;
var nodeProps = Object.entries(node);
var schemaProps = state.schemaDef.properties || {};
var schemaProps = ((_a = state.schemaDef) === null || _a === void 0 ? void 0 : _a.properties) || {};
var filteredNode = {};
var pathPrefix = state.path ? state.path + "." : '';
for (var i = 0; i < nodeProps.length; i++) {
var _a = nodeProps[i], name_1 = _a[0], value = _a[1];
var _b = nodeProps[i], name_1 = _b[0], value = _b[1];
var propSchema = schemaProps[name_1];

@@ -257,0 +258,0 @@ var propPath = "" + pathPrefix + name_1;

@@ -64,3 +64,3 @@ # Scrubbr

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

@@ -67,0 +67,0 @@

@@ -13,2 +13,16 @@ # Tips & Tricks

## Express Middleware Integration
When you install the [Scrubbr express middleware](https://github.com/jgillick/express-scrubbr) module,
you can seamlessly use scrubbr in your routes.
```ts
app.get('/users', (req, res) => {
const userData = fetchDataHere();
resp.status(200)
.scrubbr('UserList') // serialize userData with the UserList type
.send(userData);
}
```
## Improving startup performance

@@ -15,0 +29,0 @@

@@ -44,3 +44,3 @@ import * as path from 'path';

async function main() {
function main() {
try {

@@ -70,3 +70,3 @@ // Load the typescript schema

// Serialize the data
const serialized = await scrubbr.serialize('PostList', data, context);
const serialized = scrubbr.serialize('PostList', data, context);
console.log('======================');

@@ -73,0 +73,0 @@ console.log('Serialized Output:');

{
"name": "scrubbr",
"version": "1.0.0",
"version": "1.0.1",
"description": "Serialize and sanitize JSON data using TypeScript.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/jgillick/scrubbr",

@@ -64,7 +64,7 @@ # Scrubbr

async function api() {
function api() {
const data = getUsers();
// Serialize the data based on the UserList type defined in schema.ts
return await scrubbr.serialize('UserList', data);
return scrubbr.serialize('UserList', data);
}

@@ -86,2 +86,15 @@ ```

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

@@ -88,0 +101,0 @@

@@ -210,3 +210,3 @@ import * as fs from 'fs';

*/
serialize<Type = any>(
serialize<SerializedType = any>(
schemaType: string,

@@ -216,3 +216,3 @@ data: unknown,

options: ScrubbrOptions = {}
): Type {
): SerializedType {
const schema = this.getSchemaFor(schemaType);

@@ -249,3 +249,3 @@ if (!schema) {

const clonedData = JSON.parse(JSON.stringify(data));
const serialized = this.walkData(clonedData, state) as Type;
const serialized = this.walkData(clonedData, state) as SerializedType;
return serialized;

@@ -279,3 +279,3 @@ }

const nodeProps = Object.entries(node);
const schemaProps = state.schemaDef.properties || {};
const schemaProps = state.schemaDef?.properties || {};
const filteredNode: ObjectNode = {};

@@ -282,0 +282,0 @@ const pathPrefix = state.path ? `${state.path}.` : '';

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc