🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

simple_validator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple_validator - npm Package Compare versions

Comparing version
0.0.1
to
0.0.2
+13
test/resources/schema.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "https://switchpaas.rocks/schema.json#test_simple_validator_1",
"title" : "A simple json schema for testing validation",
"type" : "object",
"properties": {
"aProperty": {
"type": "integer",
"minimum": 1,
"exclusiveMinimum": true
}
}
}
+2
-1
{
"name": "simple_validator",
"description": "Basic building bricks for validations",
"version": "0.0.1",
"version": "0.0.2",
"keywords": [

@@ -30,2 +30,3 @@ "validator",

"dependencies": {
"jsonschema": "1.1.1"
},

@@ -32,0 +33,0 @@ "devDependencies": {

@@ -7,3 +7,24 @@ /*

'use strict';
var schemaFiles = {};
var jsonschema = require('jsonschema');
var fs = require('fs');
exports.validateWithSchema = function (doc, schemaFile, schemaName) {
var schemaObject;
if (!schemaFiles[schemaFile]) {
var schemaString = fs.readFileSync(schemaFile).toString('utf8');
schemaFiles[schemaFile] = JSON.parse(schemaString);
}
schemaObject = schemaFiles[schemaFile];
var v = new jsonschema.Validator();
v.addSchema(schemaObject, schemaName);
return v.validate(doc, schemaObject).errors.map(function (e) {
var prop = e.property.split('.');
prop.shift();
prop = prop.join('');
return [prop, e.message].join(' ');
});
};
exports.hasProperty = function (object, property) {

@@ -10,0 +31,0 @@ return object[property] !== undefined;

@@ -11,2 +11,16 @@ /*

describe('Validator', function () {
describe('JSON schemas', function () {
assert.equal(
m.validateWithSchema(
{aProperty: 2}, __dirname + '/resources/schema.json', 'testSchema'
).length,
0
);
assert.deepEqual(
m.validateWithSchema(
{aProperty: 1}, __dirname + '/resources/schema.json', 'testSchema'
),
['aProperty must have a minimum value of 1']
);
});
describe('Numbers', function () {

@@ -13,0 +27,0 @@ it('integer ranges (including boundaries)', function () {