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

sw-js-schema

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sw-js-schema - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

lib/BaseSchema.js

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 @@ };

29

package.json
{
"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)
'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,

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