diff --git a/dist/react-json-editor.js b/dist/react-json-editor.js index 545221b..9a42204 100644 --- a/dist/react-json-editor.js +++ b/dist/react-json-editor.js @@ -257,6 +257,10 @@ return /******/ (function(modules) { // webpackBootstrap return typeof x == 'number' && x >= 0 && x % 1 == 0; }; + var isNil = function(x) { + return (typeof x === 'undefined' || x === null); + }; + var object = function() { var args = Array.prototype.slice.call(arguments); var result = []; @@ -391,7 +395,8 @@ return /******/ (function(modules) { // webpackBootstrap prune : prune, split : split, map : map, - mapKeys: mapKeys + mapKeys: mapKeys, + isNil : isNil }; @@ -848,6 +853,7 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; var React = __webpack_require__(2); + var ou = __webpack_require__(3); var $ = React.DOM; var normalizer = __webpack_require__(12); @@ -873,10 +879,11 @@ return /******/ (function(modules) { // webpackBootstrap } }, render: function() { + var value = ou.isNil(this.props.value)? '' : this.props.value; return $.input({ type : "text", name : this.props.label, - value : this.props.value || '', + value : value, onKeyPress: this.handleKeyPress, onChange : this.handleChange }); } @@ -922,18 +929,18 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; var normalizer = __webpack_require__(12); - + var ou = __webpack_require__(3); exports.string = function(text) { return normalizer.string(text); }; exports.integer = function(text) { - return text ? parseInt(normalizer.integer(text)) : null; + return ou.isNil(text) ? null : parseInt(normalizer.integer(text)); }; exports.number = function(text) { - return text ? parseFloat(normalizer.number(text)) : null; + return ou.isNil(text) ? null : parseFloat(normalizer.number(text)); }; @@ -1190,7 +1197,6 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; var ou = __webpack_require__(3); - var alternative = __webpack_require__(8); var checkNumber = function(schema, instance) { var errors = []; @@ -1343,9 +1349,6 @@ return /******/ (function(modules) { // webpackBootstrap if (instance == null) instance = {}; - var alternativeSchema = alternative.schema(instance, schema, context); - schema = alternativeSchema || schema; - if (instance.constructor !== Object) result.push({ path: [], errors: ['must be a plain object'] }); else { diff --git a/dist/react-json-editor.min.js b/dist/react-json-editor.min.js index 7ca8a25..fa8bde6 100644 --- a/dist/react-json-editor.min.js +++ b/dist/react-json-editor.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports["react-json-editor"]=t(require("react")):e["react-json-editor"]=t(e.react)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var s=r[n]={exports:{},id:n,loaded:!1};return e[n].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";e.exports=r(1)},function(e,t,r){"use strict";function n(e){var t,r,n={};for(t=0;t=0&&e%1==0},n=function(){var e,t=Array.prototype.slice.call(arguments),n=[];for(e=0;e+1=0&&i.push(n);for(r in s)n=s[r],i.indexOf(n)<0&&i.push(n);return i}var s=r(3),i=r(8),a={alternative:function(e,t){var r=i.schema(t.getValue(t.path),t.schema,t.context);return a.object(e,s.merge(t,{schema:r}))},array:function(e,t){for(var r=function(e,t,r){return function(s){if(n(t,r)||a(t,r)){var i=e.getValue(e.path),o=i.splice(s,1);i.splice(t,0,o[0]),e.update(e.path,i,i)}}},n=function(e,t){return e>0&&t-1>e},i=function(e,t,r){return function(){if(n(t,r)){var s=e.getValue(e.path),i=s.splice(t,1);s.splice(t-1,0,i[0]),e.update(e.path,s,s)}}},a=function(e,t){return t>1&&t-2>e},o=function(e,t,r){return function(){if(a(t,r)){var n=e.getValue(e.path),s=n.splice(t,1);n.splice(t+1,0,s[0]),e.update(e.path,n,n)}}},u=function(e,t){return t>e},p=function(e,t,r){return function(){if(u(t,r)){var n=e.getValue(e.path);n.splice(t,1),e.update(e.path,n,n)}}},l=(t.getValue(t.path)||[]).length+1,c=[],h=0;l>h;++h)c.push(e.make(e,s.merge(t,{schema:t.schema.items,path:t.path.concat(h),move:r(t,h,l),moveUp:i(t,h,l),moveDown:o(t,h,l),canMoveUp:n(h,l),canMoveDown:a(h,l),removeItem:p(t,h,l),canRemoveItem:u(h,l)})));return c},object:function(e,t){var r=n(t.schema["x-ordering"],t.schema.properties);return r.map(function(r){return e.make(e,s.merge(t,{schema:t.schema.properties[r],path:t.path.concat(r)}))})}};e.exports=a},function(e,t,r){"use strict";var n=r(3),s=r(9);t.schema=function(e,t,r){var i,a,o;if(i=n.getIn(t,["x-hints","form","selector"])){var u=t.oneOf.map(function(e){return s(e,r)});return a=u.map(function(e){return n.getIn(e,["properties",i,"enum",0])||""}),o=(e||{})[i]||a[0],n.merge(n.setIn(u[a.indexOf(o)],["properties",i],n.merge(n.getIn(t,["properties",i]),{"enum":a})),{type:"object"})}}},function(e,t,r){"use strict";function n(e){var t=[].slice.call(arguments),r=Array.isArray(e)?[]:{};for(var n in e)t.indexOf(n)<0&&(r[n]=e[n]);return r}var s=r(3);e.exports=function(e,t){var r=e.$ref;if(r){if(!r.match(/^#(\/([a-zA-Z_][a-zA-Z_0-9]*|[0-9]+))*$/))throw new Error("reference "+r+" has unsupported format");return s.merge(s.getIn(t,r.split("/").slice(1)),n(e,"$ref"))}return e}},function(e,t,r){"use strict";var n=r(2),s=n.DOM,i=r(3),a=function(e){return e&&0!==e.length?"error":""},o=function(e,t){var r=[];return e&&e.length>0&&r.push(e),t&&t.length>0&&r.push(t.join("\n")),r.join("\n\n")},u=n.createClass({displayName:"FieldWrapper",render:function(){var e=[].concat(a(this.props.errors)||[],"form-element",this.props.classes||[]);return s.div({className:e.join(" "),key:this.props.label,title:o(this.props.description,this.props.errors)},s.label({htmlFor:this.props.label},this.props.title),this.props.children)}}),p=n.createClass({displayName:"SectionWrapper",render:function(){var e=this.props.path.length,t=[].concat("form-section",e>0?"form-subsection":[],this.props.classes||[]),r=[].concat(a(this.props.errors)||[],"form-section-title");return s.fieldset({className:t.join(" "),key:this.props.label},s.legend({className:r.join(" "),title:o(this.props.description,this.props.errors)},this.props.title),this.props.children)}}),l=function(e,t){var r={key:e.key,label:e.label,path:e.path,errors:e.errors,classes:i.getIn(e.schema,["x-hints","form","classes"]),title:e.schema.title,type:e.schema.type,description:e.schema.description,schema:e.schema};if(t&&e.isArrayItem){if(e.isArrayItem){var n=e.getValue(e.path),s=e.title;if(n){var a=i.getIn(e.schema,["x-hints","itemHeader","property"]),o=a&&n[a]||n.title||n.name;s=s&&o?s+" - "+o:o||s}r=i.merge(r,{title:s||r.title,move:e.move,moveUp:e.moveUp,moveDown:e.moveDown,canMoveUp:e.canMoveUp,canMoveDown:e.canMoveDown,removeItem:e.removeItem,canRemoveItem:e.canRemoveItem})}r=i.merge(r,{isArrayItem:e.isArrayItem})}return r};t.section=function(e,t){return n.isValidElement(e.sectionWrapper)?n.cloneElement(e.sectionWrapper,l(e,!0),t):n.createElement(e.sectionWrapper||p,l(e,!0),t)},t.field=function(e,t){return n.isValidElement(e.fieldWrapper)?n.cloneElement(e.fieldWrapper,l(e),t):n.createElement(e.fieldWrapper||u,l(e),t)}},function(e,t,r){"use strict";var n=r(2),s=n.DOM,i=r(12),a=r(13),o=n.createClass({displayName:"InputField",normalize:function(e){return i[this.props.type](e)},parse:function(e){return a[this.props.type](e)},handleChange:function(e){var t=this.normalize(e.target.value);this.props.update(this.props.path,t,this.parse(t))},handleKeyPress:function(e){13===e.keyCode&&e.preventDefault()},render:function(){return s.input({type:"text",name:this.props.label,value:this.props.value||"",onKeyPress:this.handleKeyPress,onChange:this.handleChange})}});e.exports=o},function(e,t){"use strict";t.string=function(e){return e.replace(/\s+/g," ").replace(/^ /,"").replace(/\u00ad/g,"")},t.integer=function(e){return e.replace(/[^-\d]/g,"").replace(/(.)-/g,"$1")},t.number=function(e){return e.replace(/[^-\.e\d]/gi,"").replace(/(e[^e]*)e/gi,"$1").replace(/([e.][^.]*)\./gi,"$1").replace(/([^e])-/gi,"$1").replace(/(e-?\d\d\d)\d/gi,"$1")}},function(e,t,r){"use strict";var n=r(12);t.string=function(e){return n.string(e)},t.integer=function(e){return e?parseInt(n.integer(e)):null},t.number=function(e){return e?parseFloat(n.number(e)):null}},function(e,t,r){"use strict";var n=r(2),s=r(12),i=r(13),a=n.createClass({displayName:"UserDefinedField",normalize:function(e){var t=s[this.props.type];return t?t(e):e},parse:function(e){var t=i[this.props.type];return t?t(e):e},handleChange:function(e){var t=this.normalize(e);this.props.update(this.props.path,t,this.parse(t))},handleKeyPress:function(e){13===e.keyCode&&e.preventDefault()},render:function(){return n.createElement(this.props.component,{schema:this.props.schema,value:this.props.value||"",onKeyPress:this.handleKeyPress,onChange:this.handleChange})}});e.exports=a},function(e,t,r){"use strict";var n=r(2),s=n.DOM,i=r(12),a=r(13),o=n.createClass({displayName:"Selection",normalize:function(e){var t=this.props.type||"string";return i[t](e)},parse:function(e){var t=this.props.type||"string";return a[t](e)},handleChange:function(e){var t=this.normalize(e.target.value);this.props.update(this.props.path,t,this.parse(t))},render:function(){var e=this.props.names;return s.select({name:this.props.label,value:this.props.value||this.props.values[0],onChange:this.handleChange},this.props.values.map(function(t,r){return s.option({key:t,value:t},e[r]||t)}))}});e.exports=o},function(e,t,r){"use strict";function n(e){return e.join("_")}var s=r(2),i=r(3),a=r(9),o=r(7),u=r(10);e.exports=function(e,t){var r=a(t.schema,t.context),p=r["x-hints"]||{},l=i.getIn(p,["form","inputComponent"]),c=n(t.path);if(t=i.merge(t,{schema:r,key:c,label:c,value:t.getValue(t.path),errors:t.getErrors(t.path),type:r.type}),void 0!==t.moveUp&&(t.isArrayItem?(delete t.isArrayItem,delete t.canMoveUp,delete t.canMoveDown,delete t.move,delete t.moveUp,delete t.moveDown):t.isArrayItem=!0),l)return t=i.merge(t,{component:t.handlers[l]}),u.field(t,s.createElement(e.UserDefinedField,t));if(p.fileUpload)return console.warn("DEPRECATION WARNING: built-in file upload will be removed"),t=i.merge(t,{fields:e}),s.createElement(e.FileField,i.merge(t,{mode:p.fileUpload.mode}));if(r.oneOf)return u.section(t,o.alternative(e,t));if(r["enum"])return t=i.merge(t,{values:r["enum"],names:r.enumNames||r["enum"]}),u.field(t,s.createElement(e.Selection,t));switch(r.type){case"boolean":return u.field(t,s.createElement(e.CheckBox,t));case"object":return u.section(t,o.object(e,t));case"array":return u.section(t,o.array(e,t));case"number":case"integer":case"string":default:return u.field(t,s.createElement(e.InputField,t))}}},function(e,t,r){"use strict";function n(e,t,r){var o,u,p=a(t,r);if(p.oneOf&&(p=i.schema(e,p,r)),p["enum"])o=e||p["enum"][0];else if("object"===p.type){o=s.merge(e);for(u in p.properties)o[u]=n((e||{})[u],p.properties[u],r)}else if("array"===p.type)for(o=[],u=0;u<(e||[]).length;++u)o[u]=n((e||[])[u],p.items,r);else o=e;return o}var s=r(3),i=r(8),a=r(9);e.exports=function(e,t,r){return s.prune(n(e,t,r))}},function(e,t,r){"use strict";var n=r(3),s=r(8),i=function(e,t){var r=[];return null!==e.maximum&&(t>e.maximum?r.push("may be at most "+e.maximum):e.exclusiveMaximum&&t>=e.maximum&&r.push("must be less than "+e.maximum)),null!==e.minimum&&(t0?[{path:[],errors:e}]:[]},o={};o["boolean"]=function(e,t){var r=[];return"boolean"!=typeof t&&r.push("must be boolean"),a(r)},o["enum"]=function(e,t){var r=[];return e["enum"].indexOf(t)<0&&r.push("value not in list"),a(r)},o.number=function(e,t){var r=[];return"number"!=typeof t?r.push("must be a number"):r=i(e,t),a(r)},o.integer=function(e,t){var r=[];return"number"!=typeof t?r.push("must be a number"):(r=i(e,t),t%1>0&&r.unshift("must be an integer")),a(r)},o.string=function(e,t){var r=[];return"string"!=typeof t?r.push("must be a string"):(null!=e.maxLength&&t.length>e.maxLength&&r.push("may have at most "+e.maxLength+" characters"),null!=e.minLength&&t.lengthe.maxItems&&o.push("may have at most "+e.maxItems+" items"),null!=e.minItems&&t.length=0?"must be present":(r=e.properties[t],"array"==r.type&&r.minItems>0?"must have at least "+r.minItems+" items":null)};o.object=function(e,t,r){var n,i,a,o=[];null==t&&(t={});var p=s.schema(t,e,r);if(e=p||e,t.constructor!==Object)o.push({path:[],errors:["must be a plain object"]});else for(n in e.properties)if(t.hasOwnProperty(n))for(i=c(e.properties[n],t[n],r),a=0;a=0&&e%1==0},n=function(e){return"undefined"==typeof e||null===e},s=function(){var e,t=Array.prototype.slice.call(arguments),n=[];for(e=0;e+1=0&&i.push(n);for(r in s)n=s[r],i.indexOf(n)<0&&i.push(n);return i}var s=r(3),i=r(8),a={alternative:function(e,t){var r=i.schema(t.getValue(t.path),t.schema,t.context);return a.object(e,s.merge(t,{schema:r}))},array:function(e,t){for(var r=function(e,t,r){return function(s){if(n(t,r)||a(t,r)){var i=e.getValue(e.path),o=i.splice(s,1);i.splice(t,0,o[0]),e.update(e.path,i,i)}}},n=function(e,t){return e>0&&t-1>e},i=function(e,t,r){return function(){if(n(t,r)){var s=e.getValue(e.path),i=s.splice(t,1);s.splice(t-1,0,i[0]),e.update(e.path,s,s)}}},a=function(e,t){return t>1&&t-2>e},o=function(e,t,r){return function(){if(a(t,r)){var n=e.getValue(e.path),s=n.splice(t,1);n.splice(t+1,0,s[0]),e.update(e.path,n,n)}}},u=function(e,t){return t>e},p=function(e,t,r){return function(){if(u(t,r)){var n=e.getValue(e.path);n.splice(t,1),e.update(e.path,n,n)}}},l=(t.getValue(t.path)||[]).length+1,c=[],h=0;l>h;++h)c.push(e.make(e,s.merge(t,{schema:t.schema.items,path:t.path.concat(h),move:r(t,h,l),moveUp:i(t,h,l),moveDown:o(t,h,l),canMoveUp:n(h,l),canMoveDown:a(h,l),removeItem:p(t,h,l),canRemoveItem:u(h,l)})));return c},object:function(e,t){var r=n(t.schema["x-ordering"],t.schema.properties);return r.map(function(r){return e.make(e,s.merge(t,{schema:t.schema.properties[r],path:t.path.concat(r)}))})}};e.exports=a},function(e,t,r){"use strict";var n=r(3),s=r(9);t.schema=function(e,t,r){var i,a,o;if(i=n.getIn(t,["x-hints","form","selector"])){var u=t.oneOf.map(function(e){return s(e,r)});return a=u.map(function(e){return n.getIn(e,["properties",i,"enum",0])||""}),o=(e||{})[i]||a[0],n.merge(n.setIn(u[a.indexOf(o)],["properties",i],n.merge(n.getIn(t,["properties",i]),{"enum":a})),{type:"object"})}}},function(e,t,r){"use strict";function n(e){var t=[].slice.call(arguments),r=Array.isArray(e)?[]:{};for(var n in e)t.indexOf(n)<0&&(r[n]=e[n]);return r}var s=r(3);e.exports=function(e,t){var r=e.$ref;if(r){if(!r.match(/^#(\/([a-zA-Z_][a-zA-Z_0-9]*|[0-9]+))*$/))throw new Error("reference "+r+" has unsupported format");return s.merge(s.getIn(t,r.split("/").slice(1)),n(e,"$ref"))}return e}},function(e,t,r){"use strict";var n=r(2),s=n.DOM,i=r(3),a=function(e){return e&&0!==e.length?"error":""},o=function(e,t){var r=[];return e&&e.length>0&&r.push(e),t&&t.length>0&&r.push(t.join("\n")),r.join("\n\n")},u=n.createClass({displayName:"FieldWrapper",render:function(){var e=[].concat(a(this.props.errors)||[],"form-element",this.props.classes||[]);return s.div({className:e.join(" "),key:this.props.label,title:o(this.props.description,this.props.errors)},s.label({htmlFor:this.props.label},this.props.title),this.props.children)}}),p=n.createClass({displayName:"SectionWrapper",render:function(){var e=this.props.path.length,t=[].concat("form-section",e>0?"form-subsection":[],this.props.classes||[]),r=[].concat(a(this.props.errors)||[],"form-section-title");return s.fieldset({className:t.join(" "),key:this.props.label},s.legend({className:r.join(" "),title:o(this.props.description,this.props.errors)},this.props.title),this.props.children)}}),l=function(e,t){var r={key:e.key,label:e.label,path:e.path,errors:e.errors,classes:i.getIn(e.schema,["x-hints","form","classes"]),title:e.schema.title,type:e.schema.type,description:e.schema.description,schema:e.schema};if(t&&e.isArrayItem){if(e.isArrayItem){var n=e.getValue(e.path),s=e.title;if(n){var a=i.getIn(e.schema,["x-hints","itemHeader","property"]),o=a&&n[a]||n.title||n.name;s=s&&o?s+" - "+o:o||s}r=i.merge(r,{title:s||r.title,move:e.move,moveUp:e.moveUp,moveDown:e.moveDown,canMoveUp:e.canMoveUp,canMoveDown:e.canMoveDown,removeItem:e.removeItem,canRemoveItem:e.canRemoveItem})}r=i.merge(r,{isArrayItem:e.isArrayItem})}return r};t.section=function(e,t){return n.isValidElement(e.sectionWrapper)?n.cloneElement(e.sectionWrapper,l(e,!0),t):n.createElement(e.sectionWrapper||p,l(e,!0),t)},t.field=function(e,t){return n.isValidElement(e.fieldWrapper)?n.cloneElement(e.fieldWrapper,l(e),t):n.createElement(e.fieldWrapper||u,l(e),t)}},function(e,t,r){"use strict";var n=r(2),s=r(3),i=n.DOM,a=r(12),o=r(13),u=n.createClass({displayName:"InputField",normalize:function(e){return a[this.props.type](e)},parse:function(e){return o[this.props.type](e)},handleChange:function(e){var t=this.normalize(e.target.value);this.props.update(this.props.path,t,this.parse(t))},handleKeyPress:function(e){13===e.keyCode&&e.preventDefault()},render:function(){var e=s.isNil(this.props.value)?"":this.props.value;return i.input({type:"text",name:this.props.label,value:e,onKeyPress:this.handleKeyPress,onChange:this.handleChange})}});e.exports=u},function(e,t){"use strict";t.string=function(e){return e.replace(/\s+/g," ").replace(/^ /,"").replace(/\u00ad/g,"")},t.integer=function(e){return e.replace(/[^-\d]/g,"").replace(/(.)-/g,"$1")},t.number=function(e){return e.replace(/[^-\.e\d]/gi,"").replace(/(e[^e]*)e/gi,"$1").replace(/([e.][^.]*)\./gi,"$1").replace(/([^e])-/gi,"$1").replace(/(e-?\d\d\d)\d/gi,"$1")}},function(e,t,r){"use strict";var n=r(12),s=r(3);t.string=function(e){return n.string(e)},t.integer=function(e){return s.isNil(e)?null:parseInt(n.integer(e))},t.number=function(e){return s.isNil(e)?null:parseFloat(n.number(e))}},function(e,t,r){"use strict";var n=r(2),s=r(12),i=r(13),a=n.createClass({displayName:"UserDefinedField",normalize:function(e){var t=s[this.props.type];return t?t(e):e},parse:function(e){var t=i[this.props.type];return t?t(e):e},handleChange:function(e){var t=this.normalize(e);this.props.update(this.props.path,t,this.parse(t))},handleKeyPress:function(e){13===e.keyCode&&e.preventDefault()},render:function(){return n.createElement(this.props.component,{schema:this.props.schema,value:this.props.value||"",onKeyPress:this.handleKeyPress,onChange:this.handleChange})}});e.exports=a},function(e,t,r){"use strict";var n=r(2),s=n.DOM,i=r(12),a=r(13),o=n.createClass({displayName:"Selection",normalize:function(e){var t=this.props.type||"string";return i[t](e)},parse:function(e){var t=this.props.type||"string";return a[t](e)},handleChange:function(e){var t=this.normalize(e.target.value);this.props.update(this.props.path,t,this.parse(t))},render:function(){var e=this.props.names;return s.select({name:this.props.label,value:this.props.value||this.props.values[0],onChange:this.handleChange},this.props.values.map(function(t,r){return s.option({key:t,value:t},e[r]||t)}))}});e.exports=o},function(e,t,r){"use strict";function n(e){return e.join("_")}var s=r(2),i=r(3),a=r(9),o=r(7),u=r(10);e.exports=function(e,t){var r=a(t.schema,t.context),p=r["x-hints"]||{},l=i.getIn(p,["form","inputComponent"]),c=n(t.path);if(t=i.merge(t,{schema:r,key:c,label:c,value:t.getValue(t.path),errors:t.getErrors(t.path),type:r.type}),void 0!==t.moveUp&&(t.isArrayItem?(delete t.isArrayItem,delete t.canMoveUp,delete t.canMoveDown,delete t.move,delete t.moveUp,delete t.moveDown):t.isArrayItem=!0),l)return t=i.merge(t,{component:t.handlers[l]}),u.field(t,s.createElement(e.UserDefinedField,t));if(p.fileUpload)return console.warn("DEPRECATION WARNING: built-in file upload will be removed"),t=i.merge(t,{fields:e}),s.createElement(e.FileField,i.merge(t,{mode:p.fileUpload.mode}));if(r.oneOf)return u.section(t,o.alternative(e,t));if(r["enum"])return t=i.merge(t,{values:r["enum"],names:r.enumNames||r["enum"]}),u.field(t,s.createElement(e.Selection,t));switch(r.type){case"boolean":return u.field(t,s.createElement(e.CheckBox,t));case"object":return u.section(t,o.object(e,t));case"array":return u.section(t,o.array(e,t));case"number":case"integer":case"string":default:return u.field(t,s.createElement(e.InputField,t))}}},function(e,t,r){"use strict";function n(e,t,r){var o,u,p=a(t,r);if(p.oneOf&&(p=i.schema(e,p,r)),p["enum"])o=e||p["enum"][0];else if("object"===p.type){o=s.merge(e);for(u in p.properties)o[u]=n((e||{})[u],p.properties[u],r)}else if("array"===p.type)for(o=[],u=0;u<(e||[]).length;++u)o[u]=n((e||[])[u],p.items,r);else o=e;return o}var s=r(3),i=r(8),a=r(9);e.exports=function(e,t,r){return s.prune(n(e,t,r))}},function(e,t,r){"use strict";var n=r(3),s=function(e,t){var r=[];return null!==e.maximum&&(t>e.maximum?r.push("may be at most "+e.maximum):e.exclusiveMaximum&&t>=e.maximum&&r.push("must be less than "+e.maximum)),null!==e.minimum&&(t0?[{path:[],errors:e}]:[]},a={};a["boolean"]=function(e,t){var r=[];return"boolean"!=typeof t&&r.push("must be boolean"),i(r)},a["enum"]=function(e,t){var r=[];return e["enum"].indexOf(t)<0&&r.push("value not in list"),i(r)},a.number=function(e,t){var r=[];return"number"!=typeof t?r.push("must be a number"):r=s(e,t),i(r)},a.integer=function(e,t){var r=[];return"number"!=typeof t?r.push("must be a number"):(r=s(e,t),t%1>0&&r.unshift("must be an integer")),i(r)},a.string=function(e,t){var r=[];return"string"!=typeof t?r.push("must be a string"):(null!=e.maxLength&&t.length>e.maxLength&&r.push("may have at most "+e.maxLength+" characters"),null!=e.minLength&&t.lengthe.maxItems&&o.push("may have at most "+e.maxItems+" items"),null!=e.minItems&&t.length=0?"must be present":(r=e.properties[t],"array"==r.type&&r.minItems>0?"must have at least "+r.minItems+" items":null)};a.object=function(e,t,r){var n,s,i,a=[];if(null==t&&(t={}),t.constructor!==Object)a.push({path:[],errors:["must be a plain object"]});else for(n in e.properties)if(t.hasOwnProperty(n))for(s=l(e.properties[n],t[n],r),i=0;i= 0 && x % 1 == 0; }; +var isNil = function(x) { + return (typeof x === 'undefined' || x === null); +}; + var object = function() { var args = Array.prototype.slice.call(arguments); var result = []; @@ -158,5 +162,6 @@ module.exports = { prune : prune, split : split, map : map, - mapKeys: mapKeys + mapKeys: mapKeys, + isNil : isNil }; diff --git a/lib/validate.js b/lib/validate.js index 1d80ce8..1406b8a 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,6 @@ SOFTWARE. 'use strict'; var ou = require('./objectUtils'); -var alternative = require('./alternative'); var checkNumber = function(schema, instance) { var errors = []; @@ -174,9 +173,6 @@ validator.object = function(schema, instance, context) { if (instance == null) instance = {}; - var alternativeSchema = alternative.schema(instance, schema, context); - schema = alternativeSchema || schema; - if (instance.constructor !== Object) result.push({ path: [], errors: ['must be a plain object'] }); else {