Skip to content
Browse files

Merge pull request #49 from Baggz/dev

Amanda v0.4.3
  • Loading branch information...
2 parents 5cdf75a + cfc55c2 commit 7410d02bd692c148fc1b8fc6447ea41c4b13c39e @Baggz committed Dec 26, 2012
Showing with 3,818 additions and 1,699 deletions.
  1. +2 −0 .travis.yml
  2. +9 −0 LICENSE
  3. +77 −80 README.md
  4. +6 −18 docs/README.md
  5. +6 −6 package.json
  6. +2,016 −0 releases/0.4.3/amanda.js
  7. +26 −0 releases/0.4.3/amanda.min.js
  8. +1,646 −1,566 releases/latest/amanda.js
  9. +25 −25 releases/latest/amanda.min.js
  10. +5 −4 src/engines/json/getProperty.js
View
2 .travis.yml
@@ -1,5 +1,7 @@
language: node_js
node_js:
+ - 0.9
+ - 0.8
- 0.6
script: "make && npm test"
View
9 LICENSE
@@ -0,0 +1,9 @@
+(The MIT License)
+
+Copyright (c) 2011 František Hába <hello@frantisekhaba.com>;
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
157 README.md
@@ -1,10 +1,10 @@
<a name="amanda"></a>
# Amanda
-[Amanda](https://github.com/Baggz/Amanda) is aiming to be **a universal validation library**. Currently it supports only the [JSON Schema Internet Draft](http://tools.ietf.org/html/draft-zyp-json-schema-03), but I'm planning to add [Orderly](http://orderly-json.org/), [Relax NG](http://relaxng.org/) and others very soon.
+[Amanda](https://github.com/Baggz/Amanda) is aiming to be **a universal schema validation library**. Currently it supports only the [JSON Schema Internet Draft](http://tools.ietf.org/html/draft-zyp-json-schema-03), but I'm planning to add [Orderly](http://orderly-json.org/), [Relax NG](http://relaxng.org/) and others very soon.
<a name="example"></a>
-#### Example
+### Example
```javascript
/**
@@ -15,8 +15,7 @@ var schema = {
properties: {
name: {
required: true,
- type: 'string',
- length: 7
+ type: 'string'
}
}
};
@@ -28,95 +27,111 @@ var data = {
name: 'Kenneth'
};
-// Initialize a JSON Schema validator
+// Initialize a JSON Schema validator.
var jsonSchemaValidator = amanda('json');
-// Validate the data against the schema
+// Validate the data against the schema.
jsonSchemaValidator.validate(data, schema, function(error) {
+
// Do something...
+
});
```
+# Contents
+
+<ul>
+ <li><a href="#features">Features</a></li>
+ <li><a href="#download">Download</a></li>
+ <li><a href="#status">Status</a></li>
+ <li><a href="#documentation">Documentation</a></li>
+ <li><a href="#compatibility">compatibility</a></li>
+ <li><a href="#building">Building</a></li>
+ <li><a href="#tests">Tests</a></li>
+ <li><a href="#versioning">Versioning</a></li>
+ <li><a href="#release-notes">Release Notes</a></li>
+ <li><a href="#authors">authors</a></li>
+ <li><a href="#license">License</a></li>
+</ul>
+
<a name="features"></a>
-#### Features
+## Features
* **Extendable**, you can create **your own attributes**
* Can be used with **Node.js** and **in a browser**
* Amanda has **no dependencies**
-* **AMD compatible**, you can load it via [RequireJS](https://github.com/jrburke/requirejs)
+* **AMD compatible**, you can load it via [RequireJS](http://requirejs.org/)
* Lightweight
* Fully **documented**
* Tested
-<a name="status"></a>
-#### Status
-
-| **Branch** | **Status** |
-|:-----------|:----------|
-| master | [![Build Status](https://secure.travis-ci.org/Baggz/Amanda.png?branch=master)](http://travis-ci.org/Baggz/Amanda) |
-| dev | [![Build Status](https://secure.travis-ci.org/Baggz/Amanda.png?branch=dev)](http://travis-ci.org/Baggz/Amanda) |
-
-<a name="contents"></a>
-### Contents
+## Download
<ul>
- <li><a href="#Download">Download</a></li>
- <li><a href="#Usage">Usage</a></li>
- <li><a href="#Documentation">Documentation</a></li>
- <li><a href="#Compatibility">Compatibility</a></li>
- <li><a href="#Building">Building</a></li>
- <li><a href="#Tests">Tests</a></li>
- <li><a href="#Versioning">Versioning</a></li>
- <li><a href="#Tests">Tests</a></li>
- <li><a href="#Release Notes">Release Notes</a></li>
- <li><a href="#Contributors">Contributors</a></li>
- <li><a href="#License">License</a></li>
+ <li><a href="#node.js">Node.js</a></li>
+ <li><a href="#browser">Browser</a></li>
</ul>
-<a name="Download"></a>
-## Download [&uarr;](#Contents)
+### Node.js
To install **Amanda**, use [NPM](http://npmjs.org/).
```
$ npm install amanda
```
-Or use use [JAM](http://groundcomputing.co.uk/code/jam).
+Then you can load the library via `require`.
+```javascript
+var amanda = require('amanda');
```
-$ jam install amanda
+
+If you prefer [RequireJS](http://requirejs.org/), go ahead.
+
+```javascript
+// Configuration options, the path should not include the .js extension.
+require.config({
+ paths: {
+ 'amanda': 'path/to/amanda'
+ }
+});
+
+// Load Amanda
+require(['amanda'], function(amanda) {
+
+ // Do something...
+
+});
```
-Releases for a browser are available for download from GitHub.
+### Browser
+
+Releases for the browser are available for download from GitHub.
| **Version** | **Description** | **Size** | **Action** |
|:------------|:----------------|:---------|:-----------|
| `amanda.js` | *uncompressed, with comments* | 36.01 KB (7.11 KB gzipped) | [Download](https://raw.github.com/Baggz/Amanda/master/releases/latest/amanda.js) |
| `amanda.min.js` | *compressed, without comments* | 13.62 KB (3.99 KB gzipped) | [Download](https://raw.github.com/Baggz/Amanda/master/releases/latest/amanda.min.js) |
-<a name="Uage"></a>
-## Usage [&uarr;](#Contents)
-
-### Browser
+Or you can use [JAM](http://jamjs.org/).
```
-<script src="amanda.js"></script>
+$ jam install amanda
```
-### Node.js, RingoJS, Narwhal
+Then you can load the library via the `<script>` tag.
-```javascript
-var amanda = require('amanda');
+```html
+<script src="/path/to/amanda.js"></script>
```
-### RequireJS
+...or via [RequireJS](http://requirejs.org/).
```javascript
-// Configuration options, the path should not include the .js extension
+// Configuration options, the path should not include the .js extension.
require.config({
paths: {
- "robb": "path/to/amanda"
+ 'amanda': 'path/to/amanda'
}
});
@@ -128,42 +143,42 @@ require(['amanda'], function(amanda) {
});
```
-<a name="Documentation"></a>
-## Documentation [&uarr;](#Contents)
+## Status
+
+| **Branch** | **Status** |
+|:-----------|:----------|
+| master | [![Build Status](https://secure.travis-ci.org/Baggz/Amanda.png?branch=master)](http://travis-ci.org/Baggz/Amanda) |
+| dev | [![Build Status](https://secure.travis-ci.org/Baggz/Amanda.png?branch=dev)](http://travis-ci.org/Baggz/Amanda) |
+
+## Documentation
All documentation is available in the [/docs/](https://github.com/Baggz/Amanda/tree/master/examples) folder.
-<a name="Compatibility"></a>
-## Compatibility [&uarr;](#Contents)
+## Compatibility
### Node.js
From version **0.6.0**.
-***Note:** Earlier versions might work OK, but are not tested.*
-
### Browsers
*Testing in progress...*
-<a name="Building"></a>
-## Building [&uarr;](#Contents)
+## Building
I have included a `Makefile` with convenience methods for working with the library.
<ul>
<li><code>make</code> Builds the library</li>
</ul>
-<a name="Tests"></a>
-## Tests [&uarr;](#Contents)
+## Tests
```
$ npm test
```
-<a name="Versioning"></a>
-## Versioning [&uarr;](#Contents)
+## Versioning
Releases will be numbered with the following format.
@@ -179,8 +194,7 @@ And constructed with the following guidelines.
For more information on *semantic versioning*, please visit http://semver.org/.
-<a name="ReleaseNotes"></a>
-## Release Notes [&uarr;](#Contents)
+## Release Notes
* [v0.4.0](https://github.com/Baggz/Amanda/pull/35)
* [v0.3.0](https://github.com/Baggz/Amanda/pull/26)
@@ -189,27 +203,10 @@ For more information on *semantic versioning*, please visit http://semver.org/.
* [v0.2.0](https://github.com/Baggz/Amanda/pull/2)
* [v0.0.2](https://github.com/Baggz/Amanda/pull/1)
-<a name="Contributors"></a>
-## Contributors [&uarr;](#Contents)
-
-The following are the major contributors of Amanda (in random order).
-
-* **František Hába** ([@Baggz](https://github.com/Baggz))
-* **Jakub Nešetřil** ([@zzen](https://github.com/zzen))
-* **Iain Carsberg** ([@iaincarsberg](https://github.com/iaincarsberg))
-* **Adrian Rossouw** ([@Vertice](https://github.com/Vertice))
-* **Leon de Almeida** ([@leondealmeida](https://github.com/leondealmeida))
-
-<a name="License"></a>
-## License [&uarr;](#Contents)
-
-(The MIT License)
-
-Copyright (c) 2011 František Hába &lt;hello@frantisekhaba.com&gt;
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+## Authors
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+František Hába ([@Baggz](https://github.com/Baggz)) created [Amanda](https://github.com/Baggz/Amanda) and [these people](https://github.com/Baggz/Amanda/graphs/contributors) have contributed.
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+## License
+Please see the [LICENSE](https://github.com/Baggz/Amanda/blob/master/LICENSE) file.
View
24 docs/README.md
@@ -1,4 +1,3 @@
-<a name="documentation"></a>
# Documentation
### Engines
@@ -8,25 +7,14 @@
<a name="jsonSchema"></a>
## JSON Schema
-diff.md
-
-### Example
-
-```
-// Initialize a JSON Schema validator
-var jsonSchemaValidator = amanda('json');
-```
-
-<a name="methods"></a>
### Methods
-* [validate](https://github.com/Baggz/Amanda/tree/master/docs/json/methods/validate.md#validate)
-* [addAttribute](https://github.com/Baggz/Amanda/tree/master/docs/json/methods/validate.md#addAttribute)
-* [addAttributeConstructor](https://github.com/Baggz/Amanda/tree/master/docs/json/methods/validate.md#addAttributeConstructor)
+* [validate](./json/methods/validate.md)
+* [addAttribute](./json/methods/addAttribute.md)
+* [addAttributeConstructor](./json/methods/addAttributeConstructor.md)
-<a name="objects"></a>
### Objects
-* [Schema](https://github.com/Baggz/Amanda/tree/master/docs/json/objects/schema.md)
-* [Error](https://github.com/Baggz/Amanda/tree/master/docs/json/objects/error.md)
-* [Options](https://github.com/Baggz/Amanda/tree/master/docs/json/objects/options.md)
+* [Schema](./json/objects/schema.md)
+* [Error](./json/objects/error.md)
+* [Options](./json/objects/options.md)
View
12 package.json
@@ -2,15 +2,15 @@
"name": "amanda",
"description": "JSON Schema validator",
- "version": "0.4.2",
+ "version": "0.4.3",
"author": "František Hába <hello@frantisekhaba.com>",
"devDependencies": {
- "mocha": "0.14.0",
- "expect.js": "0.1.2",
- "debug": "0.5.0",
- "async": "0.1.18",
- "uglify-js": "1.2.5"
+ "mocha": "1.7.4",
+ "expect.js": "0.2.0",
+ "debug": "0.7.0",
+ "async": "0.1.22",
+ "uglify-js": "2.2.2"
},
"keywords": [
View
2,016 releases/0.4.3/amanda.js
2,016 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
26 releases/0.4.3/amanda.min.js
@@ -0,0 +1,26 @@
+(function(){var n={},j=function(a,b,c){var d=function(a,b){if(h(a)&&!m(a))for(var c=0,e=a.length;c<e;c++)b.apply(a,[c,a[c]]);if(g(a)&&!m(a))for(var d in a)a.hasOwnProperty(d)&&b.apply(a,[d,a[d]])},e=function(a,b,c){var e=[],d=function(a,d){var f=e.length+1;e.push(function(){return b(a,d,function(a){var b=e[f];return!a&&b?b():!a&&!b?c():c(a)})})};if(h(a)&&!m(a))for(var f=0,s=a.length;f<s;f++)d(f,a[f]);else if(g(a)&&!m(a))for(f in a)a.hasOwnProperty(f)&&d(f,a[f]);else return c();return e[0]()};return"undefined"===
+typeof c?d.apply(this,arguments):e.apply(this,arguments)},A=function(a,b,c){return Array.prototype.filter.apply(a,[b,c||this])},h=function(a){return"[object Array]"===Object.prototype.toString.call(a)},B=function(a){return"boolean"===typeof a},m=function(a){if(p(a))return!1;if(null===a)return!0;if(h(a)||"string"===typeof a)return 0===a.length;if(g(a))for(var b in a)if(hasOwnProperty.call(a,b))return!1;return!0},v=function(a,b){if(h(a,b))return a.length!==b.length?!1:Array.prototype.every.apply(a,
+[function(a,c){return b[c]===a}]);if(g(a,b)){var c=Object.keys(a),d=Object.keys(b);if(!v(c,d))return!1;for(key in a)if(!b[key]||a[key]!==b[key])return!1;return!0}return!1},t=function(a){return"function"===typeof a},w=function(a){return p(a)&&0===a%1},C=function(a){return null===a},p=function(a){return"number"===typeof a},g=function(a){return"[object Object]"===Object.prototype.toString.call(a)},k=function(a){return"string"===typeof a},u=function(a){return"undefined"===typeof a},x=function(a,b){for(var c in b)b.hasOwnProperty(c)&&
+!a.hasOwnProperty(c)&&(a[c]=b[c]);return a},y=function(a,b){for(var c=[],d=0,e=a.length;d<e;d++){var f=a[d][b];-1===c.indexOf(f)&&c.push(f)}return c},D=function(){return!0},f=function(a){var b=this,c={singleError:!0,messages:E,cache:!1};j(c,function(d,e){b[d]=g(e)&&a[d]?x(a[d],c[d]):g(e)&&!a[d]?x({},c[d]):"undefined"!==typeof a[d]?a[d]:c[d]});this.errors=new r(this)};f.prototype.attributes={};f.prototype.addAttribute=function(a,b){return f.prototype.attributes[a]=b};f.prototype.addAttributeConstructor=
+function(a,b){return f.prototype.attributes[a]=b()};f.prototype.addAttribute("additionalProperties",function(a,b,c,d,e){var f=this;if(!0===c)return e();var l=Object.keys(b),l=A(l,function(a){return!d.properties[a]});if(m(l))return e();if(!1===c)return l.forEach(function(c){this.addError({property:this.joinPath(a,c),propertyValue:b[c]})},this),e();if(g(c))return j(l,function(d,e,l){return f.validateSchema(b[e],c,a+e,l)},e)});f.prototype.addAttribute("divisibleBy",function(a,b,c,d,e){if(0===c)throw Error("The value of this attribute should not be 0.");
+p(b)&&0!==b%c&&this.addError();return e()});f.prototype.addAttribute("enum",function(a,b,c,d,e){-1===c.indexOf(b)&&this.addError();return e()});f.prototype.addAttribute("except",function(a,b,c,d,e){-1!==c.indexOf(b)&&this.addError();return e()});f.prototype.addAttributeConstructor("format",function(){var a={"date-time":{type:"string",pattern:/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/},date:function(a){return k(a)?a.match(/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}$/):g(a)?"[object Date]"===
+Object.prototype.toString.call(a):!1},time:{type:"string",pattern:/^\d{2}:\d{2}:\d{2}$/},"utc-milisec":{type:"number"},regex:function(a){return a&&a.test&&a.exec},color:{type:"string"},style:{type:"string"},phone:{type:"number"},uri:{type:"string",pattern:/^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[-\w\d{1-3}]+\.)+(?:com|org|cat|coop|int|pro|tel|xxx|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2})?)|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/},
+email:{type:"string",pattern:/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/},"ip-address":{type:"string",pattern:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/},ipv6:{type:"string",pattern:/(?:(?:[a-f\d]{1,4}:)*(?:[a-f\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(?:(?:[a-f\d]{1,4}:)*[a-f\d]{1,4})?::(?:(?:[a-f\d]{1,4}:)*(?:[a-f\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))?)/},
+"host-name":{type:"string"},alpha:{required:!0,type:"string",pattern:/^[a-zA-Z]+$/},alphanumeric:{required:!0,type:["string","number"],pattern:/^[a-zA-Z0-9]+$/},decimal:function(a){return!p(a)?!1:(a+"").match(/^[0-9]+(\.[0-9]{1,2})?$/)},percentage:{required:!0,type:["string","number"],pattern:/^-?[0-9]{0,2}(\.[0-9]{1,2})?$|^-?(100)(\.[0]{1,2})?$/,minimum:-100,maximum:100},port:{required:!0,type:["string","number"],pattern:/\:\d+/}};j({url:"uri",ip:"ip-address",ipv4:"ip-address",host:"host-name",hostName:"host-name"},
+function(b,c){a[b]=a[c]});return function(b,c,d,e,f){if(g(d))return this.validateProperty(b,c,d,f);if(k(d)&&!Object.prototype.hasOwnProperty.apply(a,[d]))throw Error("The format \u2018"+d+"\u2019 is not supported.");if(k(d)){d=a[d];if(t(d))return d(c)||this.addError(),f();if(g(d))return this.validateProperty(b,c,d,f)}}});f.prototype.addAttribute("length",function(a,b,c,d,e){k(b)&&b.length!==c&&this.addError();return e()});f.prototype.addAttribute("maximum",function(a,b,c,d,e){p(b)&&(d.exclusiveMaximum&&
+b>=c||b>c)&&this.addError();return e()});f.prototype.addAttribute("maxItems",function(a,b,c,d,e){h(b)&&b.length>c&&this.addError();return e()});f.prototype.addAttribute("maxLength",function(a,b,c,d,e){k(b)&&b.length>c&&this.addError();return e()});f.prototype.addAttribute("minimum",function(a,b,c,d,e){p(b)&&(d.exclusiveMinimum&&b<=c||b<c)&&this.addError();return e()});f.prototype.addAttribute("minItems",function(a,b,c,d,e){h(b)&&b.length<c&&this.addError();return e()});f.prototype.addAttribute("minLength",
+function(a,b,c,d,e){k(b)&&b.length<c&&this.addError();return e()});f.prototype.addAttribute("pattern",function(a,b,c,d,e){k(b)&&!b.match(c)&&this.addError();return e()});f.prototype.addAttribute("patternProperties",function(a,b,c,d,e){var f=this;if(m(c))return e();var l={},z=Object.keys(c);j(b,function(a){j(z,function(b,e){a.match(RegExp(e))&&(l[a]=c[e])})});if(m(l))return e();j(l,function(c,e,d){return f.validateSchema(b[c],e,f.joinPath(a,c),d)},e)});f.prototype.addAttribute("required",function(a,
+b,c,d,e){c&&(a=u(b),b=(k(b)||h(b)||g(b))&&m(b),(a||b)&&this.addError());return e()});f.prototype.addAttributeConstructor("type",function(){var a={string:k,number:p,"function":t,"boolean":B,object:g,array:h,integer:w,"int":w,"null":C,any:D};return function(b,c,d,e,f){if(h(d))d.some(function(b){if(!Object.prototype.hasOwnProperty.apply(a,[b]))throw Error("Type \u2018"+d+"\u2019 is not supported.");return a[b](c)})||this.errors.addError();else{if(!Object.prototype.hasOwnProperty.apply(a,[d]))throw Error("Type \u2018"+
+d+"\u2019 is not supported.");a[d](c)||this.addError()}return f()}});f.prototype.addAttribute("uniqueItems",function(a,b,c,d,e){var f=this;j(b,function(c,e){k(e)&&b.indexOf(e)<c&&f.addError();(g(e)||h(e))&&b.forEach(function(b,d){d!==c&&v(e,b)&&f.addError({property:f.joinPath(a,d)})})});return e()});var r=function(a){this.length=0;this.errorMessages=a.messages};r.prototype.renderErrorMessage=function(a){var b=this.errorMessages[a.attributeName];return b&&t(b)?b(a.property,a.propertyValue,a.attributeValue):
+b&&k(b)?(["property","propertyValue","attributeValue"].forEach(function(c){b=b.replace(RegExp("{{"+c+"}}","g"),a[c])}),b=b.replace(/{{validator}}/g,a.attributeValue),b.replace(/\s+/g," ")):a.message};r.prototype.push=function(a){this[this.length]={property:a.property,propertyValue:a.propertyValue,attributeName:a.attributeName,attributeValue:a.attributeValue,message:this.renderErrorMessage(a),validator:a.attributeName,validatorName:a.attributeName,validatorValue:a.attributeValue};this.length+=1};r.prototype.getProperties=
+function(){return y(this,"property")};r.prototype.getMessages=function(){return y(this,"message")};var E={required:function(a){return"The \u2018"+a+"\u2019 property is required."},minLength:function(a,b,c){return["The "+a+" property must be at least "+c+" characters.","The length of the property is "+b.length+"."].join(" ")},maxLength:function(a,b,c){return["The "+a+" property must not exceed "+c+" character"+(1<c?"s":"")+".","The length of the property is "+b.length+"."].join(" ")},length:function(a,
+b,c){return["The "+a+" property must be exactly "+c+" character"+(1<c?"s":"")+".","The length of the property is "+b.length+"."].join(" ")},format:function(a,b,c){return["The \u2018"+a+"\u2019 property must be a/an \u2018"+c+"\u2019.","The current value of the property is \u2018"+b+"\u2019"].join(" ")},type:function(a,b,c){return["The \u2018"+a+"\u2019 property must be "+(-1<"aeiou".indexOf(c[0])?"an":"a")+" \u2018"+c+"\u2019.","The type of the property is \u2018"+typeof b+"\u2019"].join(" ")},except:function(){},
+minimum:function(a,b,c){return["The minimum value of the \u2018"+a+"\u2019 must be "+c+".","The current value of the property is \u2018"+b+"\u2019"].join(" ")},maximum:function(a,b,c){return["The maximum value of the \u2018"+a+"\u2019 must be "+c+".","The current value of the property is \u2018"+b+"\u2019."].join(" ")},pattern:function(a,b,c){return"The \u2018"+a+"\u2019 does not match the \u2018"+c+"\u2019 pattern."},maxItems:function(a,b,c){return["The \u2018"+a+"\u2019 property must not contain more than \u2018"+
+c+"\u2019 items.","Currently it contains \u2018"+b.items+"\u2019 items."].join(" ")},minItems:function(a,b,c){return["The \u2018"+a+"\u2019 property must contain at least \u2018"+c+"\u2019 items.","Currently it contains \u2018"+b.items+"\u2019 items."].join(" ")},divisibleBy:function(a,b,c){return"The \u2018"+a+"\u2019 is not divisible by \u2018"+c+"\u2019."},uniqueItems:function(a){return"All items in the \u2018"+a+"\u2019 property must be unique."},"enum":function(a,b,c){return"Value of the \u2018"+
+a+"\u2019 must be "+c.join(" or ")+"."}};f.prototype.getProperty=function(a,b){if(b)return b[a]?b[a]:void 0};f.prototype.joinPath=function(a,b){a=a||"";b+="";return b.match(/^[a-zA-Z][a-zA-Z0-9]*$/)?a?a+"."+b:b:b.match(/\d+/)?a+"["+b+"]":a+'["'+b+'"]'};f.prototype.validate=function(a,b,c){var d=this;this.instance=a;this.schema=b;var e=function(){return 0!==d.errors.length?c(d.errors):c()};if(-1!=="string number function boolean integer int null".split(" ").indexOf(b.type))return this.validateProperty(void 0,
+a,b,e);if(-1!==["object","array"].indexOf(b.type)){if(k(a))try{a=JSON.parse(a)}catch(f){}return this.validateSchema(a,b,"",e)}if("any"===b.type||!b.type){if(k(a))try{return a=JSON.parse(a),this.validateSchema(a,b,"",e)}catch(l){}return g(a)||h(a)?this.validateSchema(a,b,"",e):this.validateProperty(void 0,a,b,e)}};f.prototype.validateItems=function(a,b,c,d){var e=this;return h(b.items)?u(b.additionalItems)||!0===b.additionalItems?j(b.items,function(b,d,f){return e.validateSchema(a[b],d,e.joinPath(c,
+b),f)},d):j(a,function(a,d,f){if(b.items[a]||g(b.additionalItems))return e.validateSchema(d,b.items[a],e.joinPath(c,a),f);if(!1===b.additionalItems)return e.errors.push({property:e.joinPath(c,a),propertyValue:d,attributeName:"additionalItems",attributeValue:!1}),f()},d):g(b.items)&&a&&!m(a)?j(a,function(d,f,g){return e.validateSchema(a[d],b.items,e.joinPath(c,d),g)},d):d()};f.prototype.validateProperties=function(a,b,c,d){var e=this;return j(b.properties,function(d,f,g){var k="object"===f.type&&f.properties,
+h="array"===f.type,j=e.getProperty(d,a),s=e.joinPath(c,d);return k||h?e.validateSchema(j,b.properties[d],s,g):e.validateProperty(s,j,f,g)},d)};f.prototype.validateProperty=function(a,b,c,d){var e=this,f={};"validateItems validateProperties validateSchema validateProperty getProperty attributes errors joinPath".split(" ").forEach(function(a){f[a]=this[a]},e);return!0!==c.required&&u(b)?d():j(e.attributes,function(d,j,h){var m=e.errors.length;f.addError=function(f){return g(f)?e.errors.push({property:f.property||
+a,propertyValue:f.propertyValue||b,attributeName:f.attributeName||d,attributeValue:f.attributeValue||c[d],message:f.message||void 0}):e.errors.push({property:a,propertyValue:b,attributeName:d,attributeValue:c[d],message:f})};var n=function(a){return!0===a||k(a)?(f.addError(a),h(!0)):e.errors.length>m&&e.singleError?h(!0):h()};return"undefined"!==typeof c[d]?j.apply(f,[a,b,c[d],c,n]):h()},d)};f.prototype.validateSchema=function(a,b,c,d){var e=this;return e.validateProperty(c,a,b,function(){return b.properties?
+e.validateProperties(a,b,c,d):b.items?e.validateItems(a,b,c,d):d()})};n.json={validate:function(a,b,c,d){"function"===typeof c&&(d=c,c={});return(new f(c)).validate(a,b,d)},addAttribute:function(a,b){return f.prototype.addAttribute.apply(f,arguments)},addAttributeConstructor:function(a,b){return f.prototype.addAttributeConstructor.apply(f,arguments)}};var q=function(a){if(!Object.prototype.hasOwnProperty.apply(n,[a]))throw Error("The \u2018"+a+"\u2019 engine is not supported. Please use a different one.");
+return n[a]};q.validate=function(a,b,c,d){var e=n.json;return e.validate.apply(e,arguments)};q.addValidator=function(a,b){var c=n.json;return c.addAttribute.apply(c,arguments)};q.addAttribute=function(a,b){var c=n.json;return c.addAttribute.apply(c,arguments)};q.addAttributeConstructor=function(a,b){var c=n.json;return c.addAttributeConstructor.apply(c,arguments)};"undefined"!==typeof module&&module.exports?module.exports=q:"undefined"!==typeof define?define(function(){return q}):this.amanda=q})();
View
3,212 releases/latest/amanda.js
1,646 additions, 1,566 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
50 releases/latest/amanda.min.js
@@ -1,26 +1,26 @@
-(function(){var p={},n=function(a,g,h){var f=function(b,f,a){var c=[],j=function(b,i){var j=c.length+1;c.push(function(){return f(b,i,function(b){var f=c[j];return!b&&f?f():!b&&!f?a():a(b)})})};if(l(b)&&!o(b))for(var i=0,g=b.length;i<g;i++)j(i,b[i]);else if(k(b)&&!o(b))for(i in b)b.hasOwnProperty(i)&&j(i,b[i]);else return a();return c[0]()};return"undefined"===typeof h?function(b,f){if(l(b)&&!o(b))for(var a=0,c=b.length;a<c;a++)f.apply(b,[a,b[a]]);if(k(b)&&!o(b))for(var j in b)b.hasOwnProperty(j)&&
-f.apply(b,[j,b[j]])}.apply(this,arguments):f.apply(this,arguments)},A=function(a,g,h){return Array.prototype.filter.apply(a,[g,h||this])},l=function(a){return"[object Array]"===Object.prototype.toString.call(a)},B=function(a){return"boolean"===typeof a},s=function(a){return"undefined"!==typeof a},o=function(a){if(q(a))return!1;if(null===a)return!0;if(l(a)||"string"===typeof a)return 0===a.length;if(k(a))for(var g in a)if(hasOwnProperty.call(a,g))return!1;return!0},w=function(a,g){if(l(a,g))return a.length!==
-g.length?!1:Array.prototype.every.apply(a,[function(b,f){return g[f]===b}]);if(k(a,g)){var h=Object.keys(a),f=Object.keys(g);if(!w(h,f))return!1;for(key in a)if(!g[key]||a[key]!==g[key])return!1;return!0}return!1},t=function(a){return"function"===typeof a},x=function(a){return q(a)&&0===a%1},C=function(a){return null===a},q=function(a){return"number"===typeof a},k=function(a){return"[object Object]"===Object.prototype.toString.call(a)},m=function(a){return"string"===typeof a},u=function(a){return"undefined"===
-typeof a},y=function(a,g){for(var h in g)g.hasOwnProperty(h)&&!a.hasOwnProperty(h)&&(a[h]=g[h]);return a},z=function(a,g){for(var h=[],f=0,b=a.length;f<b;f++){var d=a[f][g];-1===h.indexOf(d)&&h.push(d)}return h},D=function(){return!0};(function(){var a=function(f){var b=this,d={singleError:!0,messages:h,cache:!1};n(d,function(a,c){b[a]=k(c)&&f[a]?y(f[a],d[a]):k(c)&&!f[a]?y({},d[a]):s(f[a])?f[a]:d[a]});this.errors=new g(this)};a.prototype.attributes={};a.prototype.addAttribute=function(f,b){return a.prototype.attributes[f]=
-b};a.prototype.addAttributeConstructor=function(f,b){return a.prototype.attributes[f]=b()};a.prototype.addAttribute("additionalProperties",function(f,b,d,a,c){var j=this;if(!0===d)return c();var i=Object.keys(b),i=A(i,function(b){return!a.properties[b]});if(o(i))return c();if(!1===d)return i.forEach(function(a){this.addError({property:this.joinPath(f,a),propertyValue:b[a]})},this),c();if(k(d))return n(i,function(a,c,e){return j.validateSchema(b[c],d,f+c,e)},c)});a.prototype.addAttribute("divisibleBy",
-function(f,b,a,e,c){if(0===a)throw Error("The value of this attribute should not be 0.");q(b)&&0!==b%a&&this.addError();return c()});a.prototype.addAttribute("enum",function(f,b,a,e,c){-1===a.indexOf(b)&&this.addError();return c()});a.prototype.addAttribute("except",function(f,b,a,e,c){-1!==a.indexOf(b)&&this.addError();return c()});a.prototype.addAttributeConstructor("format",function(){var f={"date-time":{type:"string",pattern:/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/},
-date:function(b){return m(b)?b.match(/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}$/):k(b)?"[object Date]"===Object.prototype.toString.call(b):!1},time:{type:"string",pattern:/^\d{2}:\d{2}:\d{2}$/},"utc-milisec":{type:"number"},regex:function(b){return b&&b.test&&b.exec},color:{type:"string"},style:{type:"string"},phone:{type:"number"},uri:{type:"string",pattern:/^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[-\w\d{1-3}]+\.)+(?:com|org|cat|coop|int|pro|tel|xxx|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2})?)|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/},
+(function(){var n={},j=function(a,b,c){var d=function(a,b){if(h(a)&&!m(a))for(var c=0,e=a.length;c<e;c++)b.apply(a,[c,a[c]]);if(g(a)&&!m(a))for(var d in a)a.hasOwnProperty(d)&&b.apply(a,[d,a[d]])},e=function(a,b,c){var e=[],d=function(a,d){var f=e.length+1;e.push(function(){return b(a,d,function(a){var b=e[f];return!a&&b?b():!a&&!b?c():c(a)})})};if(h(a)&&!m(a))for(var f=0,s=a.length;f<s;f++)d(f,a[f]);else if(g(a)&&!m(a))for(f in a)a.hasOwnProperty(f)&&d(f,a[f]);else return c();return e[0]()};return"undefined"===
+typeof c?d.apply(this,arguments):e.apply(this,arguments)},A=function(a,b,c){return Array.prototype.filter.apply(a,[b,c||this])},h=function(a){return"[object Array]"===Object.prototype.toString.call(a)},B=function(a){return"boolean"===typeof a},m=function(a){if(p(a))return!1;if(null===a)return!0;if(h(a)||"string"===typeof a)return 0===a.length;if(g(a))for(var b in a)if(hasOwnProperty.call(a,b))return!1;return!0},v=function(a,b){if(h(a,b))return a.length!==b.length?!1:Array.prototype.every.apply(a,
+[function(a,c){return b[c]===a}]);if(g(a,b)){var c=Object.keys(a),d=Object.keys(b);if(!v(c,d))return!1;for(key in a)if(!b[key]||a[key]!==b[key])return!1;return!0}return!1},t=function(a){return"function"===typeof a},w=function(a){return p(a)&&0===a%1},C=function(a){return null===a},p=function(a){return"number"===typeof a},g=function(a){return"[object Object]"===Object.prototype.toString.call(a)},k=function(a){return"string"===typeof a},u=function(a){return"undefined"===typeof a},x=function(a,b){for(var c in b)b.hasOwnProperty(c)&&
+!a.hasOwnProperty(c)&&(a[c]=b[c]);return a},y=function(a,b){for(var c=[],d=0,e=a.length;d<e;d++){var f=a[d][b];-1===c.indexOf(f)&&c.push(f)}return c},D=function(){return!0},f=function(a){var b=this,c={singleError:!0,messages:E,cache:!1};j(c,function(d,e){b[d]=g(e)&&a[d]?x(a[d],c[d]):g(e)&&!a[d]?x({},c[d]):"undefined"!==typeof a[d]?a[d]:c[d]});this.errors=new r(this)};f.prototype.attributes={};f.prototype.addAttribute=function(a,b){return f.prototype.attributes[a]=b};f.prototype.addAttributeConstructor=
+function(a,b){return f.prototype.attributes[a]=b()};f.prototype.addAttribute("additionalProperties",function(a,b,c,d,e){var f=this;if(!0===c)return e();var l=Object.keys(b),l=A(l,function(a){return!d.properties[a]});if(m(l))return e();if(!1===c)return l.forEach(function(c){this.addError({property:this.joinPath(a,c),propertyValue:b[c]})},this),e();if(g(c))return j(l,function(d,e,l){return f.validateSchema(b[e],c,a+e,l)},e)});f.prototype.addAttribute("divisibleBy",function(a,b,c,d,e){if(0===c)throw Error("The value of this attribute should not be 0.");
+p(b)&&0!==b%c&&this.addError();return e()});f.prototype.addAttribute("enum",function(a,b,c,d,e){-1===c.indexOf(b)&&this.addError();return e()});f.prototype.addAttribute("except",function(a,b,c,d,e){-1!==c.indexOf(b)&&this.addError();return e()});f.prototype.addAttributeConstructor("format",function(){var a={"date-time":{type:"string",pattern:/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/},date:function(a){return k(a)?a.match(/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}$/):g(a)?"[object Date]"===
+Object.prototype.toString.call(a):!1},time:{type:"string",pattern:/^\d{2}:\d{2}:\d{2}$/},"utc-milisec":{type:"number"},regex:function(a){return a&&a.test&&a.exec},color:{type:"string"},style:{type:"string"},phone:{type:"number"},uri:{type:"string",pattern:/^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[-\w\d{1-3}]+\.)+(?:com|org|cat|coop|int|pro|tel|xxx|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2})?)|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/},
email:{type:"string",pattern:/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/},"ip-address":{type:"string",pattern:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/},ipv6:{type:"string",pattern:/(?:(?:[a-f\d]{1,4}:)*(?:[a-f\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(?:(?:[a-f\d]{1,4}:)*[a-f\d]{1,4})?::(?:(?:[a-f\d]{1,4}:)*(?:[a-f\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))?)/},
-"host-name":{type:"string"},alpha:{required:!0,type:"string",pattern:/^[a-zA-Z]+$/},alphanumeric:{required:!0,type:["string","number"],pattern:/^[a-zA-Z0-9]+$/},decimal:function(b){return!q(b)?!1:(b+"").match(/^[0-9]+(\.[0-9]{1,2})?$/)},percentage:{required:!0,type:["string","number"],pattern:/^-?[0-9]{0,2}(\.[0-9]{1,2})?$|^-?(100)(\.[0]{1,2})?$/,minimum:-100,maximum:100},port:{required:!0,type:["string","number"],pattern:/\:\d+/}};n({url:"uri",ip:"ip-address",ipv4:"ip-address",host:"host-name",hostName:"host-name"},
-function(b,a){f[b]=f[a]});return function(b,a,e,c,j){if(k(e))return this.validateProperty(b,a,e,j);if(m(e)&&!Object.prototype.hasOwnProperty.apply(f,[e]))throw Error("The format \u2018"+e+"\u2019 is not supported.");if(m(e)){e=f[e];if(t(e))return e(a)||this.addError(),j();if(k(e))return this.validateProperty(b,a,e,j)}}});a.prototype.addAttribute("length",function(f,b,a,e,c){m(b)&&b.length!==a&&this.addError();return c()});a.prototype.addAttribute("maximum",function(f,b,a,e,c){q(b)&&(e.exclusiveMaximum&&
-b>=a||b>a)&&this.addError();return c()});a.prototype.addAttribute("maxItems",function(f,b,a,e,c){l(b)&&b.length>a&&this.addError();return c()});a.prototype.addAttribute("maxLength",function(f,b,a,e,c){m(b)&&b.length>a&&this.addError();return c()});a.prototype.addAttribute("minimum",function(f,b,a,e,c){q(b)&&(e.exclusiveMinimum&&b<=a||b<a)&&this.addError();return c()});a.prototype.addAttribute("minItems",function(f,b,a,e,c){l(b)&&b.length<a&&this.addError();return c()});a.prototype.addAttribute("minLength",
-function(f,b,a,e,c){m(b)&&b.length<a&&this.addError();return c()});a.prototype.addAttribute("pattern",function(f,b,a,e,c){m(b)&&!b.match(a)&&this.addError();return c()});(function(){a.prototype.addAttribute("patternProperties",function(f,b,a,e,c){var j=this;if(o(a))return c();var i={},g=Object.keys(a);n(b,function(b){n(g,function(f,c){b.match(RegExp(c))&&(i[b]=a[c])})});if(o(i))return c();n(i,function(a,c,d){return j.validateSchema(b[a],c,j.joinPath(f,a),d)},c)})})();a.prototype.addAttribute("required",
-function(a,b,d,e,c){d&&(a=u(b),b=(m(b)||l(b)||k(b))&&o(b),(a||b)&&this.addError());return c()});a.prototype.addAttributeConstructor("type",function(){var a={string:m,number:q,"function":t,"boolean":B,object:k,array:l,integer:x,"int":x,"null":C,any:D};return function(b,d,e,c,j){if(l(e))e.some(function(b){if(!Object.prototype.hasOwnProperty.apply(a,[b]))throw Error("Type \u2018"+e+"\u2019 is not supported.");return a[b](d)})||this.errors.addError();else{if(!Object.prototype.hasOwnProperty.apply(a,[e]))throw Error("Type \u2018"+
-e+"\u2019 is not supported.");a[e](d)||this.addError()}return j()}});(function(){a.prototype.addAttribute("uniqueItems",function(a,b,d,e,c){var j=this;n(b,function(c,d){m(d)&&b.indexOf(d)<c&&j.addError();(k(d)||l(d))&&b.forEach(function(b,e){e!==c&&w(d,b)&&j.addError({property:j.joinPath(a,e)})})});return c()})})();var g=function(a){this.length=0;this.errorMessages=a.messages};g.prototype.renderErrorMessage=function(a){var b=this.errorMessages[a.attributeName];return b&&t(b)?b(a.property,a.propertyValue,
-a.attributeValue):b&&m(b)?(["property","propertyValue","attributeValue"].forEach(function(d){b=b.replace(RegExp("{{"+d+"}}","g"),a[d])}),b=b.replace(/{{validator}}/g,a.attributeValue),b.replace(/\s+/g," ")):a.message};g.prototype.push=function(a){this[this.length]={property:a.property,propertyValue:a.propertyValue,attributeName:a.attributeName,attributeValue:a.attributeValue,message:this.renderErrorMessage(a),validator:a.attributeName,validatorName:a.attributeName,validatorValue:a.attributeValue};
-this.length+=1};g.prototype.getProperties=function(){return z(this,"property")};g.prototype.getMessages=function(){return z(this,"message")};var h={required:function(a){return"The \u2018"+a+"\u2019 property is required."},minLength:function(a,b,d){return["The "+a+" property must be at least "+d+" characters.","The length of the property is "+b.length+"."].join(" ")},maxLength:function(a,b,d){return["The "+a+" property must not exceed "+d+" characters.","The length of the property is "+b.length+"."].join(" ")},
-length:function(a,b,d){return["The "+a+" property must be exactly "+d+" characters.","The length of the property is "+b.length+"."].join(" ")},format:function(a,b,d){return["The \u2018"+a+"\u2019 property must be a/an \u2018"+d+"\u2019.","The current value of the property is \u2018"+b+"\u2019"].join(" ")},type:function(a,b,d){return["The \u2018"+a+"\u2019 property must be a/an \u2018"+d+"\u2019.","The type of the property is \u2018"+typeof b+"\u2019"].join(" ")},except:function(){},minimum:function(a,
-b,d){return["The minimum value of the \u2018"+a+"\u2019 must be "+d+".","The current value of the property is \u2018"+b+"\u2019"].join(" ")},maximum:function(a,b,d){return["The maximum value of the \u2018"+a+"\u2019 must be "+d+".","The current value of the property is \u2018"+b+"\u2019."].join(" ")},pattern:function(a,b,d){return"The \u2018"+a+"\u2019 does not match the \u2018"+d+"\u2019 pattern."},maxItems:function(a,b,d){return["The \u2018"+a+"\u2019 property must not contain more than \u2018"+
-d+"\u2019 items.","Currently it contains \u2018"+b.items+"\u2019 items."].join(" ")},minItems:function(a,b,d){return["The \u2018"+a+"\u2019 property must contain at least \u2018"+d+"\u2019 items.","Currently it contains \u2018"+b.items+"\u2019 items."].join(" ")},divisibleBy:function(a,b,d){return"The \u2018"+a+"\u2019 is not divisible by \u2018"+d+"\u2019."},uniqueItems:function(a){return"All items in the \u2018"+a+"\u2019 property must be unique."},"enum":function(a,b,d){return"Value of the \u2018"+
-a+"\u2019 must be "+d.join(" or ")+"."}};a.prototype.getProperty=function(a,b){return a.match(/([a-zA-Z0-9\s]+)/g).reduce(function(a,b){return a&&s(a[b])?a[b]:void 0},b)};a.prototype.joinPath=function(a,b){a=a||"";b+="";return b.match(/^[a-zA-Z]+$/)?a?a+"."+b:b:b.match(/\d+/)?a+"["+b+"]":a+'["'+b+'"]'};a.prototype.validate=function(a,b,d){var e=this;this.instance=a;this.schema=b;var c=function(){return 0!==e.errors.length?d(e.errors):d()};if(-1!=="string,number,function,boolean,integer,int,null".split(",").indexOf(b.type))return this.validateProperty(void 0,
-a,b,c);if(-1!==["object","array"].indexOf(b.type)){if(m(a))try{a=JSON.parse(a)}catch(j){}return this.validateSchema(a,b,"",c)}if("any"===b.type||!b.type){if(m(a))try{return a=JSON.parse(a),this.validateSchema(a,b,"",c)}catch(i){}return k(a)||l(a)?this.validateSchema(a,b,"",c):this.validateProperty(void 0,a,b,c)}};a.prototype.validateItems=function(a,b,d,e){var c=this;return l(b.items)?u(b.additionalItems)||!0===b.additionalItems?n(b.items,function(b,e,g){return c.validateSchema(a[b],e,c.joinPath(d,
-b),g)},e):n(a,function(a,f,e){if(b.items[a]||k(b.additionalItems))return c.validateSchema(f,b.items[a],c.joinPath(d,a),e);if(!1===b.additionalItems)return c.errors.push({property:c.joinPath(d,a),propertyValue:f,attributeName:"additionalItems",attributeValue:!1}),e()},e):k(b.items)&&a&&!o(a)?n(a,function(e,i,g){return c.validateSchema(a[e],b.items,c.joinPath(d,e),g)},e):e()};a.prototype.validateProperties=function(a,b,d,e){var c=this;return n(b.properties,function(e,i,g){var h="object"===i.type&&i.properties,
-k="array"===i.type,m=c.getProperty(e,a),v=c.joinPath(d,e);return h||k?c.validateSchema(m,b.properties[e],v,g):c.validateProperty(v,m,i,g)},e)};a.prototype.validateProperty=function(a,b,d,e){var c=this,g={};"validateItems,validateProperties,validateSchema,validateProperty,getProperty,attributes,errors,joinPath".split(",").forEach(function(a){g[a]=this[a]},c);return!0!==d.required&&u(b)?e():n(c.attributes,function(e,h,l){var n=c.errors.length;g.addError=function(g){return k(g)?c.errors.push({property:g.property||
-a,propertyValue:g.propertyValue||b,attributeName:g.attributeName||e,attributeValue:g.attributeValue||d[e],message:g.message||void 0}):c.errors.push({property:a,propertyValue:b,attributeName:e,attributeValue:d[e],message:g})};var o=function(a){return!0===a||m(a)?(g.addError(a),l(!0)):c.errors.length>n&&c.singleError?l(!0):l()};return s(d[e])?h.apply(g,[a,b,d[e],d,o]):l()},e)};a.prototype.validateSchema=function(a,b,d,e){var c=this;return c.validateProperty(d,a,b,function(){return b.properties?c.validateProperties(a,
-b,d,e):b.items?c.validateItems(a,b,d,e):e()})};p.json=function(){return{validate:function(f,b,d,e){"function"===typeof d&&(e=d,d={});return(new a(d)).validate(f,b,e)},addAttribute:function(f,b){return a.prototype.addAttribute.apply(a,arguments)},addAttributeConstructor:function(f,b){return a.prototype.addAttributeConstructor.apply(a,arguments)}}}()})();var r=function(a){if(!Object.prototype.hasOwnProperty.apply(p,[a]))throw Error("The \u2018"+a+"\u2019 engine is not supported. Please use a different one.");
-return p[a]};r.validate=function(a,g,h,f){var b=p.json;return b.validate.apply(b,arguments)};r.addValidator=function(a,g){var h=p.json;return h.addAttribute.apply(h,arguments)};r.addAttribute=function(a,g){var h=p.json;return h.addAttribute.apply(h,arguments)};r.addAttributeConstructor=function(a,g){var h=p.json;return h.addAttributeConstructor.apply(h,arguments)};"undefined"!==typeof module&&module.exports?module.exports=r:"undefined"!==typeof define?define(function(){return r}):this.amanda=r})();
+"host-name":{type:"string"},alpha:{required:!0,type:"string",pattern:/^[a-zA-Z]+$/},alphanumeric:{required:!0,type:["string","number"],pattern:/^[a-zA-Z0-9]+$/},decimal:function(a){return!p(a)?!1:(a+"").match(/^[0-9]+(\.[0-9]{1,2})?$/)},percentage:{required:!0,type:["string","number"],pattern:/^-?[0-9]{0,2}(\.[0-9]{1,2})?$|^-?(100)(\.[0]{1,2})?$/,minimum:-100,maximum:100},port:{required:!0,type:["string","number"],pattern:/\:\d+/}};j({url:"uri",ip:"ip-address",ipv4:"ip-address",host:"host-name",hostName:"host-name"},
+function(b,c){a[b]=a[c]});return function(b,c,d,e,f){if(g(d))return this.validateProperty(b,c,d,f);if(k(d)&&!Object.prototype.hasOwnProperty.apply(a,[d]))throw Error("The format \u2018"+d+"\u2019 is not supported.");if(k(d)){d=a[d];if(t(d))return d(c)||this.addError(),f();if(g(d))return this.validateProperty(b,c,d,f)}}});f.prototype.addAttribute("length",function(a,b,c,d,e){k(b)&&b.length!==c&&this.addError();return e()});f.prototype.addAttribute("maximum",function(a,b,c,d,e){p(b)&&(d.exclusiveMaximum&&
+b>=c||b>c)&&this.addError();return e()});f.prototype.addAttribute("maxItems",function(a,b,c,d,e){h(b)&&b.length>c&&this.addError();return e()});f.prototype.addAttribute("maxLength",function(a,b,c,d,e){k(b)&&b.length>c&&this.addError();return e()});f.prototype.addAttribute("minimum",function(a,b,c,d,e){p(b)&&(d.exclusiveMinimum&&b<=c||b<c)&&this.addError();return e()});f.prototype.addAttribute("minItems",function(a,b,c,d,e){h(b)&&b.length<c&&this.addError();return e()});f.prototype.addAttribute("minLength",
+function(a,b,c,d,e){k(b)&&b.length<c&&this.addError();return e()});f.prototype.addAttribute("pattern",function(a,b,c,d,e){k(b)&&!b.match(c)&&this.addError();return e()});f.prototype.addAttribute("patternProperties",function(a,b,c,d,e){var f=this;if(m(c))return e();var l={},z=Object.keys(c);j(b,function(a){j(z,function(b,e){a.match(RegExp(e))&&(l[a]=c[e])})});if(m(l))return e();j(l,function(c,e,d){return f.validateSchema(b[c],e,f.joinPath(a,c),d)},e)});f.prototype.addAttribute("required",function(a,
+b,c,d,e){c&&(a=u(b),b=(k(b)||h(b)||g(b))&&m(b),(a||b)&&this.addError());return e()});f.prototype.addAttributeConstructor("type",function(){var a={string:k,number:p,"function":t,"boolean":B,object:g,array:h,integer:w,"int":w,"null":C,any:D};return function(b,c,d,e,f){if(h(d))d.some(function(b){if(!Object.prototype.hasOwnProperty.apply(a,[b]))throw Error("Type \u2018"+d+"\u2019 is not supported.");return a[b](c)})||this.errors.addError();else{if(!Object.prototype.hasOwnProperty.apply(a,[d]))throw Error("Type \u2018"+
+d+"\u2019 is not supported.");a[d](c)||this.addError()}return f()}});f.prototype.addAttribute("uniqueItems",function(a,b,c,d,e){var f=this;j(b,function(c,e){k(e)&&b.indexOf(e)<c&&f.addError();(g(e)||h(e))&&b.forEach(function(b,d){d!==c&&v(e,b)&&f.addError({property:f.joinPath(a,d)})})});return e()});var r=function(a){this.length=0;this.errorMessages=a.messages};r.prototype.renderErrorMessage=function(a){var b=this.errorMessages[a.attributeName];return b&&t(b)?b(a.property,a.propertyValue,a.attributeValue):
+b&&k(b)?(["property","propertyValue","attributeValue"].forEach(function(c){b=b.replace(RegExp("{{"+c+"}}","g"),a[c])}),b=b.replace(/{{validator}}/g,a.attributeValue),b.replace(/\s+/g," ")):a.message};r.prototype.push=function(a){this[this.length]={property:a.property,propertyValue:a.propertyValue,attributeName:a.attributeName,attributeValue:a.attributeValue,message:this.renderErrorMessage(a),validator:a.attributeName,validatorName:a.attributeName,validatorValue:a.attributeValue};this.length+=1};r.prototype.getProperties=
+function(){return y(this,"property")};r.prototype.getMessages=function(){return y(this,"message")};var E={required:function(a){return"The \u2018"+a+"\u2019 property is required."},minLength:function(a,b,c){return["The "+a+" property must be at least "+c+" characters.","The length of the property is "+b.length+"."].join(" ")},maxLength:function(a,b,c){return["The "+a+" property must not exceed "+c+" character"+(1<c?"s":"")+".","The length of the property is "+b.length+"."].join(" ")},length:function(a,
+b,c){return["The "+a+" property must be exactly "+c+" character"+(1<c?"s":"")+".","The length of the property is "+b.length+"."].join(" ")},format:function(a,b,c){return["The \u2018"+a+"\u2019 property must be a/an \u2018"+c+"\u2019.","The current value of the property is \u2018"+b+"\u2019"].join(" ")},type:function(a,b,c){return["The \u2018"+a+"\u2019 property must be "+(-1<"aeiou".indexOf(c[0])?"an":"a")+" \u2018"+c+"\u2019.","The type of the property is \u2018"+typeof b+"\u2019"].join(" ")},except:function(){},
+minimum:function(a,b,c){return["The minimum value of the \u2018"+a+"\u2019 must be "+c+".","The current value of the property is \u2018"+b+"\u2019"].join(" ")},maximum:function(a,b,c){return["The maximum value of the \u2018"+a+"\u2019 must be "+c+".","The current value of the property is \u2018"+b+"\u2019."].join(" ")},pattern:function(a,b,c){return"The \u2018"+a+"\u2019 does not match the \u2018"+c+"\u2019 pattern."},maxItems:function(a,b,c){return["The \u2018"+a+"\u2019 property must not contain more than \u2018"+
+c+"\u2019 items.","Currently it contains \u2018"+b.items+"\u2019 items."].join(" ")},minItems:function(a,b,c){return["The \u2018"+a+"\u2019 property must contain at least \u2018"+c+"\u2019 items.","Currently it contains \u2018"+b.items+"\u2019 items."].join(" ")},divisibleBy:function(a,b,c){return"The \u2018"+a+"\u2019 is not divisible by \u2018"+c+"\u2019."},uniqueItems:function(a){return"All items in the \u2018"+a+"\u2019 property must be unique."},"enum":function(a,b,c){return"Value of the \u2018"+
+a+"\u2019 must be "+c.join(" or ")+"."}};f.prototype.getProperty=function(a,b){if(b)return b[a]?b[a]:void 0};f.prototype.joinPath=function(a,b){a=a||"";b+="";return b.match(/^[a-zA-Z][a-zA-Z0-9]*$/)?a?a+"."+b:b:b.match(/\d+/)?a+"["+b+"]":a+'["'+b+'"]'};f.prototype.validate=function(a,b,c){var d=this;this.instance=a;this.schema=b;var e=function(){return 0!==d.errors.length?c(d.errors):c()};if(-1!=="string number function boolean integer int null".split(" ").indexOf(b.type))return this.validateProperty(void 0,
+a,b,e);if(-1!==["object","array"].indexOf(b.type)){if(k(a))try{a=JSON.parse(a)}catch(f){}return this.validateSchema(a,b,"",e)}if("any"===b.type||!b.type){if(k(a))try{return a=JSON.parse(a),this.validateSchema(a,b,"",e)}catch(l){}return g(a)||h(a)?this.validateSchema(a,b,"",e):this.validateProperty(void 0,a,b,e)}};f.prototype.validateItems=function(a,b,c,d){var e=this;return h(b.items)?u(b.additionalItems)||!0===b.additionalItems?j(b.items,function(b,d,f){return e.validateSchema(a[b],d,e.joinPath(c,
+b),f)},d):j(a,function(a,d,f){if(b.items[a]||g(b.additionalItems))return e.validateSchema(d,b.items[a],e.joinPath(c,a),f);if(!1===b.additionalItems)return e.errors.push({property:e.joinPath(c,a),propertyValue:d,attributeName:"additionalItems",attributeValue:!1}),f()},d):g(b.items)&&a&&!m(a)?j(a,function(d,f,g){return e.validateSchema(a[d],b.items,e.joinPath(c,d),g)},d):d()};f.prototype.validateProperties=function(a,b,c,d){var e=this;return j(b.properties,function(d,f,g){var k="object"===f.type&&f.properties,
+h="array"===f.type,j=e.getProperty(d,a),s=e.joinPath(c,d);return k||h?e.validateSchema(j,b.properties[d],s,g):e.validateProperty(s,j,f,g)},d)};f.prototype.validateProperty=function(a,b,c,d){var e=this,f={};"validateItems validateProperties validateSchema validateProperty getProperty attributes errors joinPath".split(" ").forEach(function(a){f[a]=this[a]},e);return!0!==c.required&&u(b)?d():j(e.attributes,function(d,j,h){var m=e.errors.length;f.addError=function(f){return g(f)?e.errors.push({property:f.property||
+a,propertyValue:f.propertyValue||b,attributeName:f.attributeName||d,attributeValue:f.attributeValue||c[d],message:f.message||void 0}):e.errors.push({property:a,propertyValue:b,attributeName:d,attributeValue:c[d],message:f})};var n=function(a){return!0===a||k(a)?(f.addError(a),h(!0)):e.errors.length>m&&e.singleError?h(!0):h()};return"undefined"!==typeof c[d]?j.apply(f,[a,b,c[d],c,n]):h()},d)};f.prototype.validateSchema=function(a,b,c,d){var e=this;return e.validateProperty(c,a,b,function(){return b.properties?
+e.validateProperties(a,b,c,d):b.items?e.validateItems(a,b,c,d):d()})};n.json={validate:function(a,b,c,d){"function"===typeof c&&(d=c,c={});return(new f(c)).validate(a,b,d)},addAttribute:function(a,b){return f.prototype.addAttribute.apply(f,arguments)},addAttributeConstructor:function(a,b){return f.prototype.addAttributeConstructor.apply(f,arguments)}};var q=function(a){if(!Object.prototype.hasOwnProperty.apply(n,[a]))throw Error("The \u2018"+a+"\u2019 engine is not supported. Please use a different one.");
+return n[a]};q.validate=function(a,b,c,d){var e=n.json;return e.validate.apply(e,arguments)};q.addValidator=function(a,b){var c=n.json;return c.addAttribute.apply(c,arguments)};q.addAttribute=function(a,b){var c=n.json;return c.addAttribute.apply(c,arguments)};q.addAttributeConstructor=function(a,b){var c=n.json;return c.addAttributeConstructor.apply(c,arguments)};"undefined"!==typeof module&&module.exports?module.exports=q:"undefined"!==typeof define?define(function(){return q}):this.amanda=q})();
View
9 src/engines/json/getProperty.js
@@ -5,8 +5,9 @@
* @param {object} source
*/
Validation.prototype.getProperty = function(property, source) {
- var tree = property.match(/([a-zA-Z0-9\s]+)/g);
- return tree.reduce(function(previousValue, currentValue, index) {
- return (previousValue && isDefined(previousValue[currentValue])) ? previousValue[currentValue] : undefined;
- }, source);
+ if (source) {
+ return (source[property]) ? source[property] : undefined;
+ } else {
+ return undefined;
+ }
};

0 comments on commit 7410d02

Please sign in to comment.
Something went wrong with that request. Please try again.