New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

schema-inspector

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

schema-inspector - npm Package Compare versions

Comparing version 1.5.9 to 1.6.0

3

lib/schema-inspector.js

@@ -136,3 +136,3 @@ /*

"date": function (element) {
return element != null && element.constructor === Date;
return element != null && element instanceof Date;
},

@@ -1068,2 +1068,3 @@ "object": function (element) {

self._asyncSanitize(globing, post[i], function (err, res) {
if (err) { /* Error can safely be ignored here */ }
if (typeof res !== 'undefined') {

@@ -1070,0 +1071,0 @@ post[i] = res;

{
"name": "schema-inspector",
"description": "Schema-Inspector is a powerful tool to sanitize and validate JS objects.",
"version": "1.5.9",
"version": "1.6.0",
"main": "index.js",

@@ -6,0 +6,0 @@ "author": {

@@ -33,30 +33,59 @@ [![schema-inspector logo](https://raw.githubusercontent.com/Atinux/schema-inspector/master/misc/schema-inspector.png)](http://atinux.github.io/schema-inspector/)

// Your object you want to validate (can be a JSON from your API)
var candidate = {
type: 'sms',
to: [ 12, 'email@example.com', 'test']
// Data that we want to sanitize and validate
var data = {
firstname: 'sterling ',
lastname: ' archer',
jobs: 'Special agent, cocaine Dealer',
email: 'NEVER!',
};
// Your validation schema
var schema = {
// Sanitization Schema
var sanitization = {
type: 'object',
properties: {
type: { type: 'string', eq: 'email' },
to: {
firstname: { type: 'string', rules: ['trim', 'title'] },
lastname: { type: 'string', rules: ['trim', 'title'] },
jobs: {
type: 'array',
items: { type: 'string', pattern: 'email' }
}
splitWith: ',',
items: { type: 'string', rules: ['trim', 'title'] }
},
email: { type: 'string', rules: ['trim', 'lower'] }
}
};
// Let's update the data
inspector.sanitize(sanitization, data);
/*
data is now:
{
firstname: 'Sterling',
lastname: 'Archer',
jobs: ['Special Agent', 'Cocaine Dealer'],
email: 'never!'
}
*/
var result = inspector.validate(schema, candidate); // Candidate is not valid
// Validation schema
var validation = {
type: 'object',
properties: {
firstname: { type: 'string', minLength: 1 },
lastname: { type: 'string', minLength: 1 },
jobs: {
type: 'array',
items: { type: 'string', minLength: 1 }
},
email: { type: 'string', pattern: 'email' }
}
};
var result = inspector.validate(schema, candidate);
if (!result.valid)
console.log(result.format());
/*
Property @.type: must be equal to "email", but is equal to "sms"
Property @.to[0]: must be a string, but is number
Property @.dolor[4]: must match [email], but is equal to "test"
Property @.email: must match [email], but is equal to "never!"
*/
```
**Tips:** it's recommended to use one schema for the sanitzation and another for the validation,
## In the browser

@@ -134,3 +163,3 @@

* `null`
* `date` (constructor === Date)
* `date` (instanceof Date)
* `object` (constructor === Object)

@@ -137,0 +166,0 @@ * `array` (constructor === Array)

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