UNPKG

947 BJavaScriptView Raw
1/**
2 * Module dependencies.
3 */
4
5var _ = require('lodash'),
6 SchemaType = require('../schematype');
7
8/**
9 * Creates a new SchemaObject instance.
10 *
11 * @param {Object} [options]
12 * @api public
13 */
14
15var SchemaObject = module.exports = function(options){
16 options = options || {};
17
18 SchemaType.call(this, options);
19
20 if (options.hasOwnProperty('default')){
21 var defaults = options.default,
22 fn = typeof defaults === 'function';
23 }
24
25 this.default = function(){
26 return fn ? defaults() : defaults || {};
27 };
28};
29
30SchemaObject.__proto__ = SchemaType;
31SchemaObject.type = SchemaObject.prototype.type = Object;
32
33/**
34 * Inherits from SchemaType.
35 */
36
37SchemaObject.prototype.__proto__ = SchemaType.prototype;
38
39/**
40 * Compares data.
41 *
42 * @param {Object} data
43 * @param {Object} value
44 * @return {Boolean}
45 * @api public
46 */
47
48SchemaObject.prototype.compare = function(data, value){
49 return JSON.stringify(data) === JSON.stringify(value);
50};
\No newline at end of file