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

mongo-schema

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-schema - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

bower.json
{
"name": "tiny-webrtc",
"version": "1.0.1",
"version": "0.1.1",
"homepage": "https://github.com/paul-em/tiny-webrtc",

@@ -5,0 +5,0 @@ "authors": [

var has_require = typeof require !== 'undefined';
if (typeof _ === 'undefined') {
if (has_require) {
_ = require('underscore')._;
}
else throw new Error('mymodule requires underscore, see http://underscorejs.org');
}
var MongoSchema = function () {

@@ -23,15 +15,17 @@ var self = this;

var errors = [];
_.each(schema, function (properties, key) {
for (var key in schema) {
if (!schema.hasOwnProperty(key)) continue;
var value = data[key];
if (_.isArray(properties)) {
if (!_.isArray(value)) {
var properties = schema[key];
if (isArray(properties)) {
if (!isArray(value)) {
delete data[key];
return;
continue;
} else {
_.each(value, function (value) {
errors = errors.concat(self.check(value, properties[0]));
});
for(var i in value){
if(!value.hasOwnProperty(i)) continue;
errors = errors.concat(self.check(value[i], properties[0]));
}
}
} else if (_.isObject(properties) && !_.isNull(properties) && !isDefObject(properties) && !normalizeType(properties)) {
} else if (isObject(properties) && !isNull(properties) && !isDefObject(properties) && !normalizeType(properties)) {
var errs = self.check(value, properties);

@@ -47,6 +41,5 @@ errors = errors.concat(errs);

}
if (_.isNull(value) && update && !properties.required) {
if (isNull(value) && update && !properties.required) {
data[key] = undefined;
return;
continue;
}

@@ -58,6 +51,5 @@

}
switch (normType) {
case 'string':
if ((!_.isString(value) && !_.isNumber(value)) || _.isNaN(value)) {
if ((!isString(value) && !isNumber(value)) || isNaN(value)) {
value = undefined;

@@ -70,9 +62,9 @@ if (properties.required) {

if (!_.isUndefined(properties.minLength) && value.length < properties.minLength) {
if (!isUndefined(properties.minLength) && value.length < properties.minLength) {
errors.push(key + " - minLength " + properties.minLength + " not fulfilled on '" + value + "'");
delete data[key];
return;
continue;
}
if (!_.isUndefined(properties.maxLength) && value.length > properties.maxLength) {
if (!isUndefined(properties.maxLength) && value.length > properties.maxLength) {
errors.push(key + " - maxLength " + properties.regex + " not fulfilled on '" + value + "'");

@@ -82,6 +74,6 @@ value = value.substr(0, properties.maxLength);

if (!_.isUndefined(properties.regex) && !properties.regex.test(value)) {
if (!isUndefined(properties.regex) && !properties.regex.test(value)) {
errors.push(key + " - regex " + properties.regex + " not fulfilled '" + value + "'");
delete data[key];
return;
continue;
}

@@ -95,5 +87,5 @@ }

}
break;
continue;
case 'number':
if (_.isArray(value) || _.isNull(value)) {
if (isArray(value) || isNull(value)) {
value = undefined;

@@ -103,21 +95,21 @@ }

value = value * 1;
if (_.isNaN(value)) {
if (isNaN(value)) {
value = undefined;
}
if (properties.required && _.isUndefined(value)) {
if (properties.required && isUndefined(value)) {
errors.push(key + " - required not set on '" + value + "'");
delete data[key];
return;
continue;
}
if (!_.isUndefined(value) && !_.isUndefined(properties.min) && value < properties.min) {
if (!isUndefined(value) && !isUndefined(properties.min) && value < properties.min) {
errors.push(key + " - min " + properties.min + " not fulfilled '" + value + "'");
delete data[key];
return;
continue;
}
if (!_.isUndefined(value) && !_.isUndefined(properties.max) && value > properties.max) {
if (!isUndefined(value) && !isUndefined(properties.max) && value > properties.max) {
errors.push(key + " - max " + properties.max + " not fulfilled on '" + value + "'");
delete data[key];
return;
continue;
}

@@ -129,14 +121,14 @@ if (value === undefined) {

}
break;
continue;
case 'boolean':
if (properties.required && _.isUndefined(value)) {
if (properties.required && isUndefined(value)) {
errors.push(key + " - required not set '" + value + "'");
delete data[key];
return;
} else if (_.isUndefined(value)) {
continue;
} else if (isUndefined(value)) {
delete data[key];
return;
continue;
}
data[key] = !!value;
break;
continue;
case 'date':

@@ -147,3 +139,3 @@ if (value instanceof Date) {

value = value * 1;
if (_.isNaN(value)) {
if (isNaN(value)) {
value = undefined;

@@ -159,6 +151,6 @@ } else {

if (properties.required && _.isUndefined(value)) {
if (properties.required && isUndefined(value)) {
errors.push(key + " - required not set on '" + value + "'");
delete data[key];
return;
continue;
}

@@ -171,3 +163,3 @@

}
break;
continue;
case 'objectid':

@@ -179,6 +171,6 @@ if (typeof value !== "string" || (typeof value == "string" && value.length !== 24)) {

if (properties.required && _.isUndefined(value)) {
if (properties.required && isUndefined(value)) {
errors.push(key + " - required not set '" + value + "'");
delete data[key];
return;
continue;
}

@@ -191,12 +183,16 @@

}
break;
continue;
}
}
});
}
return errors;
};
this.getDefaults = function (schema) {
};
function normalizeType(type) {
if (_.isObject(type) && type.name) {
if (isObject(type) && type.name) {
type = type.name.toLowerCase();

@@ -209,3 +205,3 @@ if (types.indexOf(type) !== -1) {

}
if (_.isString(type)) {
if (isString(type)) {
type = type.toLowerCase();

@@ -222,4 +218,39 @@ if (types.indexOf(type) !== -1) {

function isDefObject(obj) {
return _.isObject(obj) && !_.isNull(obj) && !_.isArray(obj) && !_.isUndefined(obj.type);
return isObject(obj) && !isNull(obj) && !isArray(obj) && !isUndefined(obj.type);
}
function isArray(value) {
return Object.prototype.toString.call(value) === '[object Array]'
}
function isObject(value) {
return value === Object(value);
}
function isNumber(value) {
return typeof value == 'number' || Object.prototype.toString.call(value) === '[object Number]'
}
function isNaN(value) {
return isNumber(value) && value != +value;
}
// Is a given value a boolean?
function isBoolean(value) {
return value === true || value === false || Object.prototype.toString.call(value) == '[object Boolean]';
}
// Is a given value equal to null?
function isNull(value) {
return value === null;
}
// Is a given variable undefined?
function isUndefined(value) {
return value === void 0;
}
function isString(value) {
return typeof value == 'string' || Object.prototype.toString.call(value) == '[object String]';
}
};

@@ -226,0 +257,0 @@

{
"name": "mongo-schema",
"version": "0.1.0",
"version": "0.1.1",
"main": "lib/mongo-schema.js",

@@ -33,7 +33,6 @@ "description": "Basic schema for mongodb",

"mocha": "~1.17.1",
"gulp-mocha": "~0.4.1"
"gulp-mocha": "~0.4.1",
"underscore": "~1.5.2"
},
"dependencies": {
"underscore": "~1.5.2"
}
"dependencies": {}
}
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