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

mongoose-auto-api.validation

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-auto-api.validation - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

22

js/tests/test.js

@@ -122,2 +122,24 @@ var assert, should, v;

// JSON Validation
describe('JSON Validation', function() {
var val;
val = v.jsonVal('', 'jsonField');
it('Returns object', function() {
return val.should.be.a('object');
});
it('Messages and Codes Length', function() {
return assert(val.messages.length === val.codes.length);
});
it('Required Check', function() {
return assert(val.codes.includes('JSON_FIELD_REQUIRED'));
});
it('Invalid JSON Check', function() {
return assert(val.codes.includes('JSON_FIELD_INVALID_JSON'));
});
return it('Valid JSON', function() {
val = v.jsonVal('{"a":1,"b":"2","c":[1]}', 'jsonField');
return assert(val.codes.length === 0 && val.messages.length === 0 && val.valid);
});
});
// Join Validations

@@ -124,0 +146,0 @@ describe('Join Validations', function() {

32

js/utils/validation.js

@@ -1,2 +0,2 @@

var camelCase, confirmPassVal, confirmValidation, joinValidations, lenValidation, lengthVal, mailValidation, multiValidations, passVal, passValidation, reqValidation, requiredVal, snakeCase, startCase, titleCase, upperSnakeCase, userVal, validationObject;
var camelCase, confirmPassVal, confirmValidation, joinValidations, jsonVal, jsonValidation, lenValidation, lengthVal, mailValidation, multiValidations, passVal, passValidation, reqValidation, requiredVal, snakeCase, startCase, titleCase, upperSnakeCase, userVal, validationObject;

@@ -85,2 +85,14 @@ startCase = require('lodash.startcase');

//: JSON Validation
jsonVal = function(text, field) {
return multiValidations(text, field, [
{
func: reqValidation
},
{
func: jsonValidation
}
]);
};
//: Required Validation

@@ -133,2 +145,18 @@ reqValidation = function(text, args) {

//: JSON Validation
jsonValidation = function(text, args) {
var isValid;
isValid = true;
try {
JSON.parse(text);
} catch (error1) {
isValid = false;
}
if (!isValid) {
return ['must be a valid JSON object', 'INVALID_JSON'];
} else {
return true;
}
};
//: Validation Object

@@ -180,2 +208,2 @@ validationObject = function(text, field, check, args) {

module.exports = {userVal, passVal, confirmPassVal, requiredVal, lengthVal, joinValidations};
module.exports = {userVal, passVal, confirmPassVal, jsonVal, requiredVal, lengthVal, joinValidations};

4

package.json
{
"name": "mongoose-auto-api.validation",
"version": "1.0.0",
"version": "1.0.1",
"description": "Automatic Mongoose REST API - Validations module",

@@ -47,2 +47,2 @@ "main": "./js/index.js",

}
}
}
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