sw-js-schema
Advanced tools
Comparing version 1.0.0 to 1.1.0
31
index.js
'use strict'; | ||
var flatten = require('flat'); | ||
var schema = require('js-schema'); | ||
let schema = require('./lib/schema'); | ||
// Patterns | ||
require('./lib/patterns/reference'); | ||
require('./lib/patterns/nothing'); | ||
require('./lib/patterns/anything'); | ||
require('./lib/patterns/object'); | ||
require('./lib/patterns/or'); | ||
require('./lib/patterns/equality'); | ||
require('./lib/patterns/regexp'); | ||
require('./lib/patterns/class'); | ||
require('./lib/patterns/schema'); | ||
// Extensions | ||
require('./lib/extensions/Boolean'); | ||
require('./lib/extensions/Number'); | ||
require('./lib/extensions/String'); | ||
require('./lib/extensions/Object'); | ||
require('./lib/extensions/Array'); | ||
require('./lib/extensions/Function'); | ||
require('./lib/extensions/Schema'); | ||
var flatten = require('./lib/flatten'); | ||
/** | ||
@@ -11,8 +33,7 @@ * Return errors that are flatten to JSON Pointer references. | ||
*/ | ||
var jpErrors = function (errs, options) { | ||
if (!errs) return errs; | ||
options = options || {}; | ||
options.prefix = options.prefix || '/'; | ||
options.delimiter = options.delimiter || '/'; | ||
return flatten(errs, options); | ||
@@ -19,0 +40,0 @@ }; |
{ | ||
"name": "sw-js-schema", | ||
"version": "1.0.0", | ||
"description": "Enhances js-schema with JSON Pointer (RFC 6901)", | ||
"version": "1.1.0", | ||
"description": "JS schemas", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"start": "node index.js", | ||
"test": "node ./node_modules/mocha/bin/mocha" | ||
"test": "./node_modules/.bin/mocha --bail --reporter spec" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/swanest/js-schema-6901" | ||
"url": "https://github.com/swanest/sw-js-schema" | ||
}, | ||
"keywords": [ | ||
"json", | ||
"schema", | ||
"validation", | ||
"pointer", | ||
"6901" | ||
], | ||
"author": "Richard Schneider <makaretu@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/richardschneider/js-schema-6901/issues" | ||
}, | ||
"homepage": "https://github.com/richardschneider/js-schema-6901", | ||
"homepage": "https://github.com/swanest/sw-js-schema", | ||
"dependencies": { | ||
"flat": "https://github.com/richardschneider/flat/tarball/master", | ||
"js-schema": "github:swanest/js-schema" | ||
"is-buffer": "~1.1.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
"chai": "^3.5.0", | ||
"mocha": "^2.5.3" | ||
} | ||
} |
@@ -1,18 +0,12 @@ | ||
# js-schema-6901 [![Build status](https://ci.appveyor.com/api/projects/status/l79mft3t4nvi5ja6?svg=true)](https://ci.appveyor.com/project/richardschneider/js-schema-6901) | ||
__!!This module regroups [js-schema](https://www.npmjs.com/package/js-schema) and [js-schema-6901](https://github.com/richardschneider/js-schema-6901) together__ | ||
[JSON Pointer](http://www.rfc-base.org/txt/rfc-6901.txt), RFC 6901, defines a string syntax for identifying a specific value within a JavaScript Object Notation (JSON) document. For example, evaluating "foo/0/bar" against `{ foo: [ { bar: 1}, { bar: 2} }` returns 1; | ||
## Getting started | ||
[js-schema](https://www.npmjs.com/package/js-schema) is simple and intuitive object validation library. It provides support for [JSON Schema](http://json-schema.org/). | ||
Install with `$ npm install sw-js-schema`. | ||
This package reports schema validation errors with a JSON Pointer to the offending field by adding the `jpErrors` method to a schema. | ||
## Getting started [![npm version](https://badge.fury.io/js/js-schema-6901.svg)](https://badge.fury.io/js/js-schema-6901) | ||
Install with `$ npm install js-schema-6901`. Bower will be coming soon. | ||
## Usage | ||
```` | ||
var schema = require('js-schema-6901'); | ||
var schema = require('sw-js-schema'); | ||
var person = schema({ | ||
@@ -46,5 +40,1 @@ name: String, | ||
# License | ||
The MIT license | ||
Copyright © 2015 Richard Schneider (makaretu@gmail.com) |
71
test.js
'use strict'; | ||
var schema = require('./index'); | ||
var should = require('should'); | ||
var schema = require('./index').schema; | ||
var should = require('chai').should(); | ||
var person = schema({ | ||
name: String, | ||
dob: /\d{4}\-\d{2}\-\d{2}/, | ||
name: String, | ||
dob: /\d{4}\-\d{2}\-\d{2}/, | ||
children: Array.of(schema.self) | ||
}); | ||
describe ('Validation error', function() { | ||
var bad = { | ||
name: 'me', | ||
children: [ | ||
{dob: '2000-01-01', children: []}, | ||
{dob: '2000-1-01'} | ||
]}; | ||
var good = { | ||
name: 'me', | ||
dob: '2000-01-01', | ||
children: [] | ||
}; | ||
it('should allow no validation errors', function() { | ||
var errs = person.jpErrors(good); | ||
errs.should.be.false; | ||
describe('Validation error', function () { | ||
var bad = { | ||
name: 'me', | ||
children: [ | ||
{dob: '2000-01-01', children: []}, | ||
{dob: '2000-1-01'} | ||
] | ||
}; | ||
var good = { | ||
name: 'me', | ||
dob: '2000-01-01', | ||
children: [] | ||
}; | ||
it('should allow no validation errors', function () { | ||
var errs = person.jpErrors(good); | ||
errs.should.be.false; | ||
}); | ||
it('should have JSON pointer', function() { | ||
var errs = person.jpErrors(bad); | ||
errs.should.have.property('/dob'); | ||
}); | ||
it('should support arrays and other objects', function() { | ||
var errs = person.jpErrors(bad); | ||
errs.should.have.property('/children/0/name'); | ||
it('should have JSON pointer', function () { | ||
var errs = person.jpErrors(bad); | ||
errs.should.have.property('dob'); | ||
}); | ||
it('should have a string message', function() { | ||
var errs = person.jpErrors(bad); | ||
errs['/dob'].should.be.a.type('string'); | ||
it('should support arrays and other objects', function () { | ||
var errs = person.jpErrors(bad); | ||
errs.should.have.property('children/0/name'); | ||
}); | ||
it('should allow js-schema options passed to jpErrors', function() { | ||
var errs = person.jpErrors(bad, { prefix: '$' }); | ||
errs.should.have.property('$dob'); | ||
it('should have a string message', function () { | ||
var errs = person.jpErrors(bad); | ||
errs['dob'].should.be.a('string'); | ||
}); | ||
// it('should allow js-schema options passed to jpErrors', function () { | ||
// var errs = person.jpErrors(bad, {prefix: '$', delimiter: "."}); | ||
// errs.should.have.property('$dob'); | ||
// }); | ||
}); |
"use strict"; | ||
const index_1 = require("../index"); | ||
var index_1 = require("../index"); | ||
var Duck = index_1.schema({ | ||
@@ -4,0 +4,0 @@ swim: Function, |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
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
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
44164
1
28
1147
0
3
40
1
+ Addedis-buffer@~1.1.2
+ Addedis-buffer@1.1.6(transitive)
- Removedflat@https://github.com/richardschneider/flat/tarball/master
- Removedjs-schema@github:swanest/js-schema