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

js-data-schema

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-data-schema - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0-alpha.1

4

bower.json

@@ -5,4 +5,4 @@ {

"description": "Define and validate rules, datatypes and schemata in Node and in the browser.",
"version": "0.1.0",
"homepage": "https://github.com/js-data/js-data-schema",
"version": "1.0.0-alpha.1",
"homepage": "http://www.js-data.io/docs/js-data-schema",
"repository": {

@@ -9,0 +9,0 @@ "type": "git",

@@ -0,3 +1,7 @@

##### 1.0.0-alpha.1 - 01 November 2014
Stable Version 1.0.0-alpha.1
##### 0.1.0 - 15 September 2014
Initial Release
# Contributing Guide
First, feel free to contact me with questions. [Mailing List](https://groups.google.com/forum/?fromgroups#!forum/js-data-project). [Issues](https://github.com/js-data/js-data-schema/issues).
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data-schema/issues).

@@ -5,0 +5,0 @@ 1. Contribute to the issue that is the reason you'll be developing in the first place

@@ -0,1 +1,10 @@

/**
* @author Jason Dobry <jason.dobry@gmail.com>
* @file js-data-schema.js
* @version 1.0.0-alpha.1 - Homepage <http://www.js-data.io/docs/js-data-schema>
* @copyright (c) 2014 Jason Dobry
* @license MIT <https://github.com/js-data/js-data-schema/blob/master/LICENSE>
*
* @overview Define and validate rules, datatypes and schemata in Node and in the browser.
*/
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Schemator=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

@@ -2,0 +11,0 @@ 'use strict';

/**
* @author Jason Dobry <jason.dobry@gmail.com>
* @file js-data-schema.min.js
* @version 0.1.0 - Homepage <https://github.com/js-data/js-data-schema/>
* @version 1.0.0-alpha.1 - Homepage <https://github.com/js-data/js-data-schema/>
* @copyright (c) 2013-2014 Jason Dobry <https://github.io/js-data/js-data-schema>

@@ -6,0 +6,0 @@ * @license MIT <https://github.com/js-data/js-data-schema/blob/master/LICENSE>

'use strict';
module.exports = function (grunt) {
require('jit-grunt')(grunt);
require('jit-grunt')(grunt, {
coveralls: 'grunt-karma-coveralls'
});
require('time-grunt')(grunt);

@@ -12,2 +14,4 @@

var pkg = grunt.file.readJSON('package.json');
grunt.initConfig({

@@ -68,13 +72,2 @@ config: config,

groc: {
javascript: [
'dist/js-data-schema.js'
],
options: {
'out': 'doc/',
// 'index': 'doc.md',
'repository-url': 'https://github.com/js-data/js-data-schema'
}
},
browserify: {

@@ -113,3 +106,22 @@ dist: {

grunt.registerTask('banner', function () {
var file = grunt.file.read('dist/js-data-schema.js');
var banner = '/**\n' +
'* @author Jason Dobry <jason.dobry@gmail.com>\n' +
'* @file js-data-schema.js\n' +
'* @version ' + pkg.version + ' - Homepage <http://www.js-data.io/docs/js-data-schema>\n' +
'* @copyright (c) 2014 Jason Dobry \n' +
'* @license MIT <https://github.com/js-data/js-data-schema/blob/master/LICENSE>\n' +
'*\n' +
'* @overview Define and validate rules, datatypes and schemata in Node and in the browser.\n' +
'*/\n';
file = banner + file;
grunt.file.write('dist/js-data-schema.js', file);
});
grunt.registerTask('test', [
'build',
'jshint:test',

@@ -119,3 +131,9 @@ 'mochaTest',

]);
grunt.registerTask('build', ['clean', 'jshint:src', 'browserify', 'uglify']);
grunt.registerTask('build', [
'clean',
'jshint:src',
'browserify',
'banner',
'uglify'
]);
grunt.registerTask('go', ['build', 'watch']);

@@ -122,0 +140,0 @@

{
"name": "js-data-schema",
"description": "Define and validate rules, datatypes and schemata in Node and in the browser.",
"version": "0.1.0",
"homepage": "https://github.com/js-data/js-data-schema",
"version": "1.0.0-alpha.1",
"homepage": "http://www.js-data.io/docs/js-data-schema",
"repository": {

@@ -38,30 +38,29 @@ "type": "git",

"dependencies": {
"mout": "^0.10.0"
"mout": "0.10.0"
},
"devDependencies": {
"chai": "^1.9.1",
"grunt": "^0.4.5",
"grunt-browserify": "^3.0.1",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "^0.5.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-groc": "^0.4.5",
"grunt-karma": "^0.9.0",
"grunt-karma-coveralls": "^2.5.2",
"grunt-mocha-test": "^0.12.0",
"jit-grunt": "^0.8.0",
"karma": "^0.12.23",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^0.1.4",
"karma-coverage": "^0.2.6",
"karma-firefox-launcher": "^0.1.3",
"karma-mocha": "^0.1.9",
"karma-phantomjs-launcher": "^0.1.4",
"karma-script-launcher": "^0.1.0",
"karma-sinon": "^1.0.3",
"chai": "1.9.2",
"grunt": "0.4.5",
"grunt-browserify": "3.1.0",
"grunt-contrib-clean": "0.6.0",
"grunt-contrib-jshint": "0.10.0",
"grunt-contrib-uglify": "0.6.0",
"grunt-contrib-watch": "0.6.1",
"grunt-karma": "0.9.0",
"grunt-karma-coveralls": "2.5.2",
"grunt-mocha-test": "0.12.2",
"jit-grunt": "0.9.0",
"karma": "0.12.24",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "0.1.5",
"karma-coverage": "0.2.6",
"karma-firefox-launcher": "0.1.3",
"karma-mocha": "0.1.9",
"karma-phantomjs-launcher": "0.1.4",
"karma-script-launcher": "0.1.0",
"karma-sinon": "1.0.3",
"karma-spec-reporter": "0.0.13",
"mocha": "^1.21.4",
"sinon": "^1.10.3",
"time-grunt": "^1.0.0"
"mocha": "2.0.1",
"sinon": "1.11.1",
"time-grunt": "1.0.0"
},

@@ -68,0 +67,0 @@ "bugs": {

@@ -5,2 +5,5 @@ ## js-data-schema

## API Documentation
[Schemator API](http://www.js-data.io/docs/js-data-schema)
## Install

@@ -66,298 +69,4 @@

### Schemator
[js-data-schema api](http://www.js-data.io/docs/js-data-schema)
#### Schemator()
```js
var schemator = new Schemator();
```
#### Schemator#availableDataTypes()
```js
schemator.availableDataTypes(); // ['boolean', 'string', 'etc.']
```
#### Schemator#availableRules()
```js
schemator.availableRules(); // ['type', 'minLength', 'etc.']
```
#### Schemator#availableSchemata()
```js
schemator.defineSchema('PersonSchema', { ... });
schemator.availableSchemata(); // ['PersonSchema']
```
#### Schemator#getDataType(name)
```js
schemator.getDataType('myDataType');
```
#### Schemator#getRule(name)
```js
schemator.getRule('myRule');
```
#### Schemator#getSchema(name)
```js
schemator.getSchema('PersonSchema');
```
#### Schemator#removeDataType(name)
```js
schemator.removeDataType('myDataType');
```
#### Schemator#removeRule(name)
```js
schemator.removeRule('myRule');
```
#### Schemator#removeSchema(name)
```js
schemator.removeSchema('PersonSchema');
```
#### Schemator#defineDataType(name, typeDefinition)
```js
schemator.defineDataType('NaN', function (x) {
if (isNaN(x)) {
return null;
} else {
return {
rule: 'type',
actual: typeof x,
expected: 'NaN'
};
}
});
```
#### Schemator#defineRule(name, ruleFunc[, async])
```js
schemator.defineRule('divisibleBy', function (x, divisor) {
if (typeof x === 'number' && typeof divisor === 'number' && x % divisor !== 0) {
return {
rule: 'divisibleBy',
actual: '' + x + ' % ' + divisor + ' === ' + (x % divisor),
expected: '' + x + ' % ' + divisor + ' === 0'
};
}
return null;
});
schemator.defineSchema('mySchema', {
seats: {
divisibleBy: 4
}
});
var errors = schemator.getSchema('mySchema').validateSync({
seats: 16
});
errors; // null
errors = schemator.getSchema('mySchema').validateSync({
seats: 17
});
errors; // {
// seats: {
// errors: [ {
// rule: 'divisibleBy',
// actual: '17 % 4 === 1',
// expected: '17 % 4 === 0'
// } ]
// }
// }
```
Asynchronous rule:
```js
schemator.defineRule('divisibleBy', function (x, divisor, cb) {
// asynchronity here is fake, but you could do something async, like make an http request
setTimeout(function () {
if (typeof x === 'number' && typeof divisor === 'number' && x % divisor !== 0) {
cb({
rule: 'divisibleBy',
actual: '' + x + ' % ' + divisor + ' === ' + (x % divisor),
expected: '' + x + ' % ' + divisor + ' === 0'
});
}
cb(null);
}, 1);
}, true); // pass true as the third argument
schemator.defineSchema('mySchema', {
seats: {
divisibleBy: 4
}
});
var errors = schemator.getSchema('mySchema').validate({
seats: 16
}, function (err) {
errors; // null
errors = schemator.getSchema('mySchema').validate({
seats: 17
}, function (err) {
errors; // {
// seats: {
// errors: [ {
// rule: 'divisibleBy',
// actual: '17 % 4 === 1',
// expected: '17 % 4 === 0'
// } ]
// }
// }
});
});
```
#### Schemator#defineSchema(name, definition)
```js
schemator.defineSchema('PersonSchema', {
name: {
first: {
type: 'string',
maxLength: 255
},
last: {
type: 'string',
maxLength: 255
}
},
age: {
type: 'number',
max: 150,
min: 0
}
});
```
#### Schemator#validate(schemaName, attrs[, options], cb)
See `Schema#validate(attrs[, options], cb)`
#### Schemator#validateSync(schemaName, attrs[, options])
See `Schema#validateSync(attrs[, options])`
#### Schemator#setDefaults(schemaName, attrs)
See `Schema#setDefaults(attrs)`
#### Schemator#getDefaults()
See `Schema#getDefaults()`
#### Schemator#addDefaultsToTarget(schemaName, target[, overwrite])
See `Schema#addDefaultsToTarget(target)`
#### Schemator#stripNonSchemaAttrs(schemaName, target)
See `Schema#stripNonSchemaAttrs(target)`
### Schema
#### Schema#validate(attrs[, options], cb)
```js
PersonSchema.validate({
name: 'John Anderson'
}, function (err) {
err; // null
});
PersonSchema.validate({
name: 5
}, function (err) {
err; // {
// name: {
// errors: [{
// rule: 'type',
// actual: 'number',
// expected: 'string'
// }]
// }
// }
});
```
#### Schema#validateSync(attrs[, options])
```js
var errors = PersonSchema.validate({
name: 'John Anderson'
});
errors; // null
errors = mySchema.validate({
name: 5
});
errors; // {
// name: {
// errors: [{
// rule: 'type',
// actual: 'number',
// expected: 'string'
// }]
// }
// }
```
#### Schema#setDefaults(attrs)
```js
PersonSchema.setDefaults({
first: '',
last: '',
plan: 'free'
});
```
#### Schema#getDefaults()
```js
PersonSchema.getDefaults(); // {
first: '',
last: '',
age: 0
}
```
#### Schema#addDefaultsToTarget(target[, overwrite])
```js
var person = {
first: 'John',
plan: 'premium'
};
PersonSchema.addDefaultsToTarget(person);
person; // {
first: 'John',
last: '',
plan: 'premium'
}
PersonSchema.addDefaultsToTarget(person, true);
person; // {
first: '',
last: '',
plan: 'free'
}
```
#### Schema#stripNonSchemaAttrs(target)
```js
var person = {
first: 'John',
plan: 'premium',
nonSchema: 'value'
};
PersonSchema.stripNonSchemaAttrs(person);
person; // {
first: 'John',
plan: 'premium'
}
```
## License

@@ -364,0 +73,0 @@ [MIT License](https://github.com/js-data/js-data-schema/blob/master/LICENSE)

Sorry, the diff of this file is not supported yet

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