normalize-json
Advanced tools
Comparing version 0.1.3 to 0.1.4
{ | ||
"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" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
26204
541
1
1
0