Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

normalize-json

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalize-json - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

21

package.json
{
"name": "normalize-json",
"version": "0.1.3",
"description": "Simple JSON validation/normalization using terse object literals",
"version": "0.1.4",
"description": "Terse syntax for validating and normalizing JavaScript objects",
"main": "normalize-json.js",

@@ -10,3 +10,6 @@ "scripts": {

"keywords": [
"json"
"json",
"schema",
"validation",
"normalization"
],

@@ -17,3 +20,13 @@ "author": "Nigel Nelson",

"jasmine": "^2.5.3"
}
},
"dependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/shamblesides/normalizeJson.git"
},
"bugs": {
"url": "https://github.com/shamblesides/normalizeJson/issues"
},
"homepage": "https://github.com/shamblesides/normalizeJson#readme",
"runkitExampleFilename": "usage.js"
}

@@ -264,2 +264,3 @@ /* global describe it expect */

expect({'someEnum': 'String'}).not.toFitSchema(schema)
expect({'someEnum': ' string '}).not.toFitSchema(schema)
expect({'someEnum': 0}).not.toFitSchema(schema)

@@ -305,2 +306,3 @@ expect({'someEnum': false}).not.toFitSchema(schema)

expect({'someEnum': [7,'9',true,'false',undefined] }).not.toFitSchema(schema)
expect({'someEnum': ' 7 '}).not.toFitSchema(schema)
expect({'someEnum': '7'}).not.toFitSchema(schema)

@@ -307,0 +309,0 @@ expect({'someEnum': 9}).not.toFitSchema(schema)

20

usage.js

@@ -1,18 +0,22 @@

const nJ = require('normalizeJson');
const nJ = require('normalize-json');
// a schema looks like this!
let validator = nJ({
name: [String, 30],
age: [Number, 0, 100],
color: ['red', 'yellow', 'blue']
name: [String, 30], // a string with <= 30 characters
age: [Number, 0, 100], // a number between 0 and 100, inclusive
color: ['red', 'yellow', 'blue'] // must be one of these three values
});
// here's how we might validate/normalize an object
let obj = {
name: 'Nigel',
name: ' Nigel ', // this string will be trimmed!
age: 23,
color: ' blue '
color: 'blue',
someUndefinedField: undefined // undefined fields will be stripped out
};
let result = validator(obj);
let result = validator(obj); // 'result' is a new object; 'obj' has not been changed
console.log(result); // { name: 'Nigel', age: 23, color: 'blue' }
// here's a bad object; this will fail validation
let badObj = {

@@ -29,3 +33,3 @@ name: 'Somebody',

catch (err) {
console.log(err); // string containing information about failure
console.log(err.message); // will give the first found error: "age is not a number"
}
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