Socket
Socket
Sign inDemoInstall

joi

Package Overview
Dependencies
2
Maintainers
2
Versions
238
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

.travis.yml

49

lib/joi.js

@@ -21,39 +21,35 @@ // Load modules

var errorMsg = null;
var finalizeFns = [];
var placeholder = {};
placeholder.add = Types.Base.prototype.RequestErrorFactory(placeholder);
placeholder._renamed = {};
for (var i in elementKeys) {
var finalizeFns = [];
if (elementKeys.hasOwnProperty(i)) {
var key = elementKeys[i];
var value = object[key];
var validators = config[key].__validators;
for (var j in validators) {
if (validators.hasOwnProperty(j)) {
var validatorName = config[key].__checks[j];
var T = Types[config[key].type];
var converter = T().convert || null;
if (typeof converter == "function") {
if (validatorName in Types.mutatorMethods) {
finalizeFns.push(j);
continue;
}
var result = Types.validate(key, config[key].type, object, validators[j], placeholder);
if (result === false) {
isInvalid = true;
errorMsg = key + ' = ' + object[key];
break;
}
delete submitted[key];
}
value = converter(value);
}
for (var l in finalizeFns) {
var result = Types.validate(key, config[key].type, object, validators[j], placeholder);
if (result === false) {
isInvalid = true;
errorMsg = 'error on renaming ' + key + ' = ' + object[key];
break;
}
// console.log('whereami', i, key)
// console.log(config[key].__checks)
var result = config[key].validate(value, key, object, placeholder);
// console.log("validating", key, object[key], value, config[key].type, result, placeholder)
if (result === false) {
isInvalid = true;
errorMsg = key + ' = ' + value;
// console.log(key, "failed to validate", value)
}
else {
delete submitted[key];
}
}

@@ -67,2 +63,3 @@ }

var processed = Object.keys(submitted);
// console.log(object, submitted, processed)
if (processed.length > 0) {

@@ -69,0 +66,0 @@

var sys = require("sys");
var util = require('util');
var BaseType = require('./base');
var Utils = require("../utils");

@@ -8,2 +9,4 @@ function ArrayType() {

ArrayType.super_.call(this);
Utils.mixin(this, BaseType);
}

@@ -17,28 +20,25 @@

if (!BaseType.prototype.exists(value)) {
return [];
}
if (typeof value === 'string') {
// No need to try/catch, `Invalid JSON Body` exception already handled elsehwere
var converted = JSON.parse(value);
if (converted instanceof Array) {
try {
var converted = JSON.parse(value);
if (converted instanceof Array) {
return converted;
}
else {
return converted;
}
else {
return [converted];
return [converted];
}
}
catch (e){
// console.log(e, value)
}
}
else if (value instanceof Array) {
return value;
}
else {
// Defensive programming
throw "Invalid data type passed to Types.Array (" + value + ", " + typeof value + " is not supported)";
// throw "Invalid data type passed to Types.Array (" + value + ", " + typeof value + " is not supported)";
return value;
}

@@ -49,5 +49,6 @@ }

return function(value) {
return (value == null || value instanceof Array);
return function(value, qs, key, errors) {
// console.log('value in Array.base', value)
return value instanceof Array;
};

@@ -64,2 +65,3 @@ }

var self = this;
var subElement = (new ArrayType.super_()).getDataKey();

@@ -74,7 +76,12 @@ var args = Array.prototype.slice.call(arguments);

req = req || {}
req.add = req.add || function(){}
// For each allowed Type
var valueIsValid = true;
var intermediateInvalidValues = [];
// var intermediateInvalidValues = [];
var invalidValues = [];
var failedArg = null;
var failedIndex = null;
var failedValue = null;
var validatedValuesTable = {};

@@ -85,2 +92,3 @@

// For each validator specified
var currentType = args[i].type;
var validators = allowedTypes[i];

@@ -98,7 +106,10 @@ var validatorIsValid = true;

validatorIsValid = false;
intermediateInvalidValues.push(value);
failedIndex = i;
// intermediateInvalidValues.push(value);
failedArg = i
failedIndex = j;
failedValue = value;
}
else {
// console.log(value, "is valid", currentType)
validatedValuesTable[m] = true;

@@ -120,7 +131,12 @@ }

// Only append error if the included types' validators return errors
if (valueIsValid === false && failedIndex >= 0 && args[0]._checks.indexOf("includes") < 0) {
// if (valueIsValid === false && failedIndex >= 0 && args[0].__checks.indexOf("includes") < 0) {
if (valueIsValid === false) {
// if(self.options.debug === true) console.log("***", validatedValuesTable, values)
var validTypes = args.map(function(d){ return d.type; });
req.addValidationError("the value(s) `" + sys.inspect(invalidValues) + "` in array `" + key + "` must be of the following type(s) " + sys.inspect(validTypes));
var vals = invalidValues.map(function(d){ return JSON.stringify(d)}).join(", ").replace(/[\"]/g, "'")
var msg = "the value(s) `" + vals + "` in array `" + key + "` must be of the following type(s) " + sys.inspect(validTypes);
req.add(msg);
// console.log(msg)
// console.log(args[failedIndex].type, args[failedArg].__checks[failedIndex], failedValue, values)
}

@@ -133,3 +149,3 @@ return valueIsValid;

this.add('includes', this._includes.apply(this._includes, arguments), arguments);
this.add('includes', this._includes.apply(this, arguments), arguments);
return this;

@@ -145,3 +161,4 @@ }

// var result = !self._includes.apply(self._includes, args)(value, qs, key, req);
// var result = self._includes.apply(self._includes, args)(value, qs, key, req);
// console.log(value, "excludes", Array.prototype.slice.call(args).map(function(d){return d.type}), result)
// if (result === false) {

@@ -148,0 +165,0 @@

@@ -22,4 +22,8 @@ /**

this[INTERNAL_ARGS_LIST] = [];
this.__modifiers = new Utils.Set([]);
this.__valids = new Utils.Set(this.__defaultValids || []);
this.__invalids = new Utils.Set(this.__defaultInvalids || []);
this.options = {
shortCircuit: true
};

@@ -35,4 +39,23 @@ if (typeof this.base !== 'undefined' && this.base !== null) {

BaseType.prototype.__defaultValids = [undefined];
BaseType.prototype.__defaultInvalids = [null];
BaseType.prototype.mutatorMethods = {
rename: 1
};
BaseType.prototype.valueOf = function() {
return this[INTERNAL_DATA_KEY];
// return this[INTERNAL_DATA_KEY];
var value = {
"__valids": this.__valids,
"__invalids": this.__invalids,
"__modifiers": this.__modifiers._values,
"options": this.options
}
value[INTERNAL_DATA_KEY] = this[INTERNAL_DATA_KEY]
value[INTERNAL_KEY_LIST] = this[INTERNAL_KEY_LIST]
value[INTERNAL_ARGS_LIST] = this[INTERNAL_ARGS_LIST]
return value;
}

@@ -71,34 +94,28 @@

// BaseType.prototype._required = function() {
// }
BaseType.prototype.allow = function(value) {
BaseType.prototype._required = function(allowNull) {
this.__invalids.remove(value);
this.__valids.add(value);
return this;
}
allowNull = allowNull || false;
return function(value) {
BaseType.prototype.deny = function(value) {
if (allowNull === true) {
return exists(value) || value === null;
}
else {
return exists(value);
}
}
this.__valids.remove(value);
this.__invalids.add(value);
return this;
}
BaseType.prototype.required = function(allowNull) {
BaseType.prototype.required = function() {
this.add('required', this._required(allowNull), arguments);
this.deny(undefined);
this.__modifiers.add("required");
return this;
}
BaseType.prototype._empty = function(){
BaseType.prototype.nullOk = function() {
return function(value){
return (value === null);
}
this.allow(null);
this.__modifiers.add("nullOk");
return this;
}

@@ -108,58 +125,26 @@

this.add('empty', this._empty(), arguments);
this.allow(null);
this.__modifiers.add("empty");
return this;
}
BaseType.prototype._valid = function(acceptable) {
BaseType.prototype.valid = function() {
for(var i = acceptable.length; i >= 0; i--) {
var acceptable = Array.prototype.slice.call(arguments);
for(var i = acceptable.length - 1; i >= 0; i--) {
this._valids.add(acceptable[i]);
this._invalids.remove(acceptable[i]);
Utils.assert(this.validate(acceptable[i]) == true, "input to .valid() must be valid " + this.__name + "(" + acceptable[i] + ")");
this.allow(acceptable[i]);
}
}
BaseType.prototype._validOld = function(acceptable) {
return function(value) {
var isValid = false;
for(var i in acceptable){
if (value === acceptable[i]) {
isValid = true;
}
}
return isValid;
}
}
BaseType.prototype.valid = function() {
// this.add('valid', this._valid(Array.prototype.slice.call(arguments)), arguments);
return this;
}
BaseType.prototype._invalid = function(unacceptable) {
BaseType.prototype.invalid = function() {
for(var i = unacceptable.length; i >= 0; i--) {
var unacceptable = Array.prototype.slice.call(arguments);
for(var i = unacceptable.length - 1; i >= 0; i--) {
this._invalids.add(unacceptable[i]);
this._valids.remove(unacceptable[i]);
Utils.assert(this.validate(unacceptable[i]) == true, "input to .invalid() must be valid " + this.__name + "(" + unacceptable[i] + ")");
this.deny(unacceptable[i]);
}
}
// BaseType.prototype._xinvalid = function(unacceptable) {
// var self = this;
// return function(value) {
// return !self._valid(unacceptable)(value);
// }
// }
BaseType.prototype.invalid = function() {
// this.add('invalid', this._invalid(Array.prototype.slice.call(arguments)), arguments);
return this;

@@ -222,2 +207,3 @@ }

req = req || {};
req.add = req.add || function(){};
var renamed = req._renamed || {};

@@ -227,2 +213,3 @@

req.add("allowMult false and already renamed");
return false;

@@ -233,2 +220,4 @@ }

// console.log(key, to, qstr)
req.add("allowOverwrite false and target exists: " + key + ", " + to);
return false;

@@ -292,2 +281,64 @@ }

BaseType.prototype.validate = function(value, key, obj, errors) {
var status = true;
var finalizeFns = [];
key = key || "0";
obj = obj || {"0": value};
errors = errors || {};
errors.add = errors.add || function(){};
// console.log(this.valueOf())
// Check vs valid/invalid values
if (this.__invalids._values.indexOf(value) >= 0) {
status = false;
errors.add("the value of `" + key + "` is not allowed to be " + this.__invalids._values[this.__invalids._values.indexOf(value)]);
if (this.options.shortCircuit === true) {
return status;
}
}
if (this.__valids._values.indexOf(value) >= 0) {
status = true;
if (this.options.shortCircuit === true) {
return status;
}
}
// Evaluate validators
for(var j in this.__validators) {
// TODO: handle finalizeFns aka mutators (need to run after all other validators)
var validatorName = this.__checks[j];
if (validatorName in this.mutatorMethods) {
// console.log("mutatorMethod found", this.__checks[j])
finalizeFns.push(j);
continue;
}
var result = this.__validators[j](value, obj || {"0": value}, key || "0", errors)
// console.log("validating", this.type, this.__checks[j], value, typeof value, result)
if (result === false) {
// console.log(this.__checks[j], "failed with ", value)
status = false;
if (this.options.shortCircuit === true) {
return status;
}
}
}
for(var l in finalizeFns) {
var result = this.__validators[finalizeFns[l]](value, obj || {"0": value}, key || "0", errors)
if (result === false) {
// console.log("finalize:", this.__checks[l], "failed with ", value)
status = false;
if (this.options.shortCircuit === true) {
return status;
}
}
}
return status;
}
module.exports = BaseType;

@@ -15,3 +15,3 @@ var util = require("util");

if (typeof value !== "undefined" && value !== null) {
if (typeof value == "string") {

@@ -32,3 +32,3 @@ switch (value.toLowerCase()) {

return false;
return value;
}

@@ -35,0 +35,0 @@ }

@@ -0,0 +0,0 @@ /*

@@ -25,3 +25,3 @@ /**

this.Array = ArrayType;
this.Object = ObjectType;
// this.Object = ObjectType;
}

@@ -56,3 +56,3 @@

placeholder.addValidationError = this.Base.prototype.RequestErrorFactory(placeholder);
placeholder.add = this.Base.prototype.RequestErrorFactory(placeholder);
}

@@ -66,3 +66,3 @@

// Remove from request object when finished
delete placeholder.addValidationError;
delete placeholder.add;
}

@@ -69,0 +69,0 @@

@@ -8,2 +8,4 @@ var util = require("util");

NumberType.super_.call(this);
Utils.mixin(this, BaseType);
}

@@ -17,3 +19,10 @@

return Number(value);
if (typeof value == "string") {
return Number(value);
}
else {
return value;
}
}

@@ -52,2 +61,5 @@

return function(value, qs, key, req) {
req = req || {};
req.add = req.add || function(){};

@@ -57,4 +69,3 @@ var result = (isNaN(value) || value >= n);

req = req || {addValidationError: function(){}};
req.addValidationError("the value of `" + key + "` must be larger than (or equal to) " + n);
req.add("the value of `" + key + "` must be larger than (or equal to) " + n);
}

@@ -76,2 +87,5 @@ return result;

return function(value, qs, key, req) {
req = req || {};
req.add = req.add || function(){};

@@ -81,4 +95,3 @@ var result = (value <= n);

req = req || {addValidationError: function(){}};
req.addValidationError("the value of `" + key + "` must be less than (or equal to) " + n);
req.add("the value of `" + key + "` must be less than (or equal to) " + n);
}

@@ -98,7 +111,10 @@ return result;

return function(value, qs, key, req) {
req = req || {};
req.add = req.add || function(){};
var result = (!isNaN(value) && ((value|0) == parseFloat(value)));
if (result === false) {
req = req || {addValidationError: function(){}};
req.addValidationError("the value of `" + key + "` must be an integer");
req.add("the value of `" + key + "` must be an integer");
}

@@ -119,2 +135,5 @@ return result;

return function(value, qs, key, req) {
req = req || {};
req.add = req.add || function(){};

@@ -124,4 +143,3 @@ var result = (!isInt(value));

req = req || {addValidationError: function(){}};
req.addValidationError("the value of `" + key + "` must be a float or double");
req.add("the value of `" + key + "` must be a float or double");
}

@@ -128,0 +146,0 @@ return result;

@@ -0,0 +0,0 @@ var util = require("util");

@@ -39,23 +39,24 @@ var util = require("util");

StringType.prototype.__defaultValids = [undefined];
StringType.prototype.__defaultInvalids = [null, ""];
StringType.prototype._ibase = function() {
// StringType.prototype.base = function() {
var self = this;
return function(value, qs, key, req) {
// var self = this;
// return function(value, qs, key, req) {
// var valid = self.__valids.map(function(d){
// return qs[key] == d;
// }).indexOf(true) >= 0;
// // var valid = self.__valids.map(function(d){
// // return qs[key] == d;
// // }).indexOf(true) >= 0;
// var invalid = self.__invalids.map(function(d){
// return qs[key] == d;
// }).indexOf(true) >= 0;
// // var invalid = self.__invalids.map(function(d){
// // return qs[key] == d;
// // }).indexOf(true) >= 0;
// return valid && !invalid;
// // return valid && !invalid;
// console.log(self.__invalids.map(function(d){return qs[key] == d;}));
// // console.log(self.__invalids.map(function(d){return qs[key] == d;}));
return false;
}
}
// return true;
// }
// }

@@ -66,29 +67,39 @@ StringType.prototype._base = function() {

var keyDoesNotExist = !qs.hasOwnProperty(key);
var valueIsMinLength = (qs[key] !== undefined && qs[key].length >= 1);
var valueIsNotNumber = isNaN(+value) || !isNaN((new Date(+value)).getTime());
var valueIsNotArray = true;
try {
return typeof value == "string";
var v = JSON.parse(value);
valueIsNotArray = v instanceof Array;
}
catch (e) {
// Deprecated code below should be moved to Array
// ignore
}
// var keyDoesNotExist = !qs.hasOwnProperty(key);
// var valueIsMinLength = (qs[key] !== undefined && qs[key].length >= 1);
// var valueIsNotNumber = isNaN(+value) || isNaN((new Date(+value)).getTime());
// // req = req || {};
// // req.add = req.add || function(){};
var valueIsDefined = (keyDoesNotExist || valueIsMinLength);
if (valueIsDefined === false) {
// // var valueIsNotArray = !(value instanceof Array);
// var valueIsNotObject = true;
// if (typeof value !== "string") {
// valueIsNotObject = typeof value !== "object";
// }
// else {
// try {
// var v = JSON.parse(value);
// valueIsNotObject = (typeof v !== "object" && !(v instanceof Array))
// }
// catch (e) {
req = req || {addValidationError: function(){}};
req.addValidationError("the value of `" + key + "` is not allowed to be the empty string ('')");
}
// // console.log(e)
// }
// }
var result = (valueIsDefined &&
valueIsNotNumber &&
valueIsNotArray);
// var valueIsDefined = (keyDoesNotExist || valueIsMinLength);
// if (valueIsDefined === false) {
// req.add("the value of `" + key + "` is not allowed to be the empty string ('')");
// }
return result;
// var result = (valueIsDefined &&
// valueIsNotNumber &&
// valueIsNotObject);
// return result;
};

@@ -103,2 +114,10 @@ }

StringType.prototype.emptyOk = function() {
this.allow("");
this.__modifiers.add("required");
return this;
}
StringType.prototype._min = function(n) {

@@ -110,7 +129,14 @@ Utils.assert((!isNaN(n) && ((n|0) == parseFloat(n))), "In Types.String.min(n), the n must be an integer.");

req = req || {};
req.add = req.add || function(){};
if (value === null || typeof value === "undefined") {
return false;
}
var result = (value.length >= n);
if (result === false) {
req = req || {addValidationError: function(){}};
req.addValidationError("the value of `" + key + "` must be at least " + n + " characters long");
req.add("the value of `" + key + "` must be at least " + n + " characters long");
}

@@ -133,7 +159,9 @@ return result;

req = req || {};
req.add = req.add || function(){};
var result = (value.length <= n);
if (result === false) {
req = req || {addValidationError: function(){}};
req.addValidationError("the value of `" + key +"` must be less than (or equal to) " + n + " characters long");
req.add("the value of `" + key +"` must be less than (or equal to) " + n + " characters long");
}

@@ -154,2 +182,5 @@ return result;

return function(value, qs, key, req) {
req = req || {};
req.add = req.add || function(){};

@@ -159,4 +190,3 @@ var result = (value.match(n) !== null);

req = req || {addValidationError: function(){}};
req.addValidationError("the value of `" + key + "` must match the RegExp `" + n.toString() + "`");
req.add("the value of `" + key + "` must match the RegExp `" + n.toString() + "`");
}

@@ -175,14 +205,16 @@ return result;

return function(value, qs, key, req){
return function(value, qs, key, req){
value = (isNaN(Number(value)) === false) ? +value : value;
var converted = new Date(value);
var result = (!isNaN(converted.getTime()));
if (result === false) {
req = req || {};
req.add = req.add || function(){};
value = (isNaN(Number(value)) === false) ? +value : value;
var converted = new Date(value);
var result = (!isNaN(converted.getTime()));
if (result === false) {
req = req || {addValidationError: function(){}};
req.addValidationError("the value of `" + key + "` must be a valid JavaScript Date format");
req.add("the value of `" + key + "` must be a valid JavaScript Date format");
}
return result;
}
return result;
}
}

@@ -189,0 +221,0 @@

@@ -29,3 +29,5 @@ // Load modules

if (parent.prototype.hasOwnProperty(i)) {
self[i] = parent.prototype[i];
if (!self.hasOwnProperty(i)) {
self[i] = parent.prototype[i];
}
}

@@ -37,6 +39,22 @@ }

var Set = exports.Set = function () {
var Set = exports.Set = function (initialValue) {
this.inspect = require('sys').inspect;
this._values = [];
this._exists = {};
if (initialValue !== null && typeof initialValue !== "undefined") {
if (initialValue instanceof Array) {
for(var i = initialValue.length - 1; i >= 0; i--) {
this.add(initialValue[i]);
}
}
else {
// Error
console.log("given improper input to Set")
}
}
};

@@ -48,6 +66,6 @@

var key = this.inspect(value);
if (!(key in this._exists)) {
if (!(this._exists.hasOwnProperty(key))) {
this._values.push(value);
this._exists[key] = this._values.length;
this._exists[key] = this._values.length - 1;
}

@@ -60,3 +78,3 @@ };

var key = this.inspect(value);
if (key in this._exists) {
if (this._exists.hasOwnProperty(key)) {

@@ -68,3 +86,20 @@ this._values.splice(this._exists[key], 1);

Set.prototype.get = function(){
return this._values;
}
Set.prototype.has = function(value) {
return this._exists.hasOwnProperty(this.inspect(value));
}
Set.prototype.valueOf = function(){
return this._values;
}
Set.prototype.toJSON =
Set.prototype.toString = function(){
return JSON.inspect(this.valueOf());
}
Set.prototype.map = function (fn) {

@@ -71,0 +106,0 @@

{
"name": "joi",
"description": "Object schema validation",
"version": "0.0.2",
"version": "0.0.3",
"author": "Van Nguyen <the.gol.effect@gmail.com>",

@@ -6,0 +6,0 @@ "contributors":[

joi
===
Object schema validation
Object schema validation
[![Build Status](https://secure.travis-ci.org/walmartlabs/joi.png)](http://travis-ci.org/walmartlabs/joi)

@@ -0,95 +1,144 @@

var Types = require("../../lib/types/");
var should = require("should");
var verifyBehavior = require("../support/meta").verifyValidatorBehavior;
var Types = require("../../lib/types/");
describe("Types.Array", function(){
var A = Types.Array;
var N = Types.Number;
describe("tests/types/array.js", function(){
it('should instantiate separate copies on invocation', function(done){
var result1 = A().required();
var result2 = A();
describe("Types.Array", function(){
var A = Types.Array,
N = Types.Number,
S = Types.String;
Object.keys(result1).should.not.equal(Object.keys(result2));
done();
describe("#validate", function(){
it('should work', function(done){
(function(){
var arr = A();
var result = arr.validate([1]);
}).should.not.throw();
done();
})
it('should, by default, allow undefined, allow empty array', function(done){
verifyBehavior(A(), [
[undefined, true],
[[], true]
], done);
})
it("should, when .required(), deny undefined", function(done){
verifyBehavior(A().required(), [
[undefined, false]
], done);
})
it("should validate array of Numbers", function(done){
verifyBehavior(A().includes(N()), [
[[1,2,3], true],
[[50, 100, 1000], true],
[["a", 1, 2], false]
], done);
})
it("should validate array of mixed Numbers & Strings", function(done){
verifyBehavior(A().includes(N(), S()), [
[[1,2,3], true],
[[50, 100, 1000], true],
[[1, "a", 5, 10], true],
[["walmart", "everydaylowprices", 5000], true]
], done);
})
})
})
})
// describe("Types.Array", function(){
// var A = Types.Array;
// var N = Types.Number;
it("should inherit functions from BaseType", function(done){
var fns = ["required", "add"];
// // it('should instantiate separate copies on invocation', function(done){
// // var result1 = A().required();
// // var result2 = A();
for(var i in fns){
should.exist(A()[fns[i]]);
}
done();
})
// // Object.keys(result1).should.not.equal(Object.keys(result2));
// // done();
// // })
it("should show resulting object with #valueOf", function(done){
var result = A();
should.exist(result.valueOf());
done();
})
// it("should inherit functions from BaseType", function(done){
// var fns = ["required", "add"];
// for(var i in fns){
// should.exist(A()[fns[i]]);
// }
// done();
// })
describe("#includes", function(done){
it('should exist', function(done){
should.exist(A().includes);
done();
})
})
// it("should show resulting object with #valueOf", function(done){
// var result = A();
// should.exist(result.valueOf());
// done();
// })
describe("#_includes", function(done){
it('should validate on known good input', function(done){
var input = [10, 20];
var validators = A()._includes(N().min(5));
// describe("#includes", function(done){
// it('should exist', function(done){
// should.exist(A().includes);
// done();
// })
// })
// describe("#_includes", function(done){
// it('should validate on known good input', function(done){
// var input = [10, 20];
// var validators = A()._includes(N().min(5));
for(var j in validators) {
var result = validators[j](input);
should.exist(result);
result.should.be(true);
}
done();
})
// for(var j in validators) {
// var result = validators[j](input);
// should.exist(result);
// result.should.be(true);
// }
// done();
// })
it('should invalidate on known bad input', function(done){
var input = [3, 1];
var len = input.length;
var validators = A()._includes(N().min(5));
var isValid = true;
// it('should invalidate on known bad input', function(done){
// var input = [3, 1];
// var len = input.length;
// var validators = A()._includes(N().min(5));
// var isValid = true;
for(var j in validators) {
var result = validators[j](input);
should.exist(result);
result.should.be(false);
}
done();
})
})
// for(var j in validators) {
// var result = validators[j](input);
// should.exist(result);
// result.should.be(false);
// }
// done();
// })
// })
// describe("#_excludes", function(done){
// it('should validate on known good input', function(done){
// var input = [3, 1];
// var validators = A()._excludes(N().min(5));
// // describe("#_excludes", function(done){
// // it('should validate on known good input', function(done){
// // var input = [3, 1];
// // var validators = A()._excludes(N().min(5));
// for(var j in validators) {
// var result = validators[j](input);
// should.exist(result);
// result.should.be(true);
// }
// done();
// })
// // for(var j in validators) {
// // var result = validators[j](input);
// // should.exist(result);
// // result.should.be(true);
// // }
// // done();
// // })
// it('should invalidate on known bad input', function(done){
// var input = [10, 20];
// var len = input.length;
// var validators = A()._excludes(N().min(5));
// var isValid = true;
// // it('should invalidate on known bad input', function(done){
// // var input = [10, 20];
// // var len = input.length;
// // var validators = A()._excludes(N().min(5));
// // var isValid = true;
// for(var j in validators) {
// var result = validators[j](input);
// should.exist(result);
// result.should.be(false);
// }
// done();
// })
// })
// // for(var j in validators) {
// // var result = validators[j](input);
// // should.exist(result);
// // result.should.be(false);
// // }
// // done();
// // })
// // })
});
// });
var should = require("should");
var BaseType = require("../../lib/types/base");
var Types = require("../../lib/types");
var BaseType = Types.Base;
var Utils = require("../../lib/utils");
var sys = require("sys");
describe("BaseType", function(){
describe("#_required", function(){
it('should return true if non-null input is given and required', function(done){
var base = new BaseType();
var result = base._required()("walmart");
should.exist(result);
result.should.equal(true);
describe("types/base.js", function(){
describe("BaseType", function(){
it('should', function(done){
var B = new BaseType();
var r = B.allow(undefined);
// console.log("after allow", r);
done();
})
})
})
// describe("BaseType", function(){
// describe("#_required", function(){
// it('should return true if non-null input is given and required', function(done){
// var base = new BaseType();
// var result = base._required()("walmart");
// should.exist(result);
// result.should.equal(true);
// done();
// })
it('should return true if null input is given and allowNull is true', function(done){
var base = new BaseType();
var result = base._required(true)(null);
should.exist(result);
result.should.equal(true);
done();
})
// it('should return true if null input is given and allowNull is true', function(done){
// var base = new BaseType();
// var result = base._required(true)(null);
// should.exist(result);
// result.should.equal(true);
// done();
// })
it('should return false if null input is given and allowNull is false', function(done){
var base = new BaseType();
var result = base._required(false)(null);
should.exist(result);
result.should.equal(false);
done();
})
// it('should return false if null input is given and allowNull is false', function(done){
// var base = new BaseType();
// var result = base._required(false)(null);
// should.exist(result);
// result.should.equal(false);
// done();
// })
it('should return false if no input is given and allowNull is false', function(done){
var base = new BaseType();
var result = base._required(false)();
should.exist(result);
result.should.equal(false);
done();
})
})
// it('should return false if no input is given and allowNull is false', function(done){
// var base = new BaseType();
// var result = base._required(false)();
// should.exist(result);
// result.should.equal(false);
// done();
// })
// })
describe("#_rename", function(){
var key = "name";
var key2 = "note";
var key3 = "username";
var qstr = {name: "van", note: "author"};
var value = qstr[key];
var value2 = qstr[key2];
// describe("#_rename", function(){
// var key = "name";
// var key2 = "note";
// var key3 = "username";
// var qstr = {name: "van", note: "author"};
// var value = qstr[key];
// var value2 = qstr[key2];
it("should alias a variable with default options", function(done){
var base = new BaseType();
var validator = base._rename(key3);
var q = Utils.clone(qstr);
var result = validator(value, q, key);
// it("should alias a variable with default options", function(done){
// var base = new BaseType();
// var validator = base._rename(key3);
// var q = Utils.clone(qstr);
// var result = validator(value, q, key);
should.exist(q[key3]);
q[key3].should.equal(value);
done();
})
// should.exist(q[key3]);
// q[key3].should.equal(value);
// done();
// })
it("should move variable if deleteOrig set", function(done){
var base = new BaseType();
var validator = base._rename(key3, {deleteOrig: true});
var q = Utils.clone(qstr);
var result = validator(value, q, key);
// it("should move variable if deleteOrig set", function(done){
// var base = new BaseType();
// var validator = base._rename(key3, {deleteOrig: true});
// var q = Utils.clone(qstr);
// var result = validator(value, q, key);
should.exist(q[key3]);
should.not.exist(q[key]);
q[key3].should.equal(value);
done();
})
// should.exist(q[key3]);
// should.not.exist(q[key]);
// q[key3].should.equal(value);
// done();
// })
it("should overwrite existing variable if allowOverwrite set", function(done){
var base = new BaseType();
var key2 = "note";
var validator = base._rename(key2, {allowOverwrite: true});
var q = Utils.clone(qstr);
var result = validator(value, q, key)
// it("should overwrite existing variable if allowOverwrite set", function(done){
// var base = new BaseType();
// var key2 = "note";
// var validator = base._rename(key2, {allowOverwrite: true});
// var q = Utils.clone(qstr);
// var result = validator(value, q, key)
should.exist(q[key2]);
q[key2].should.equal(value);
q[key].should.equal(value);
done();
})
// should.exist(q[key2]);
// q[key2].should.equal(value);
// q[key].should.equal(value);
// done();
// })
it("should not overwrite existing variable if allowOverwrite not set", function(done){
var base = new BaseType();
var validator = base._rename(key2, {allowOverwrite: false});
var q = Utils.clone(qstr);
var result = validator(value, q, key);
// it("should not overwrite existing variable if allowOverwrite not set", function(done){
// var base = new BaseType();
// var validator = base._rename(key2, {allowOverwrite: false});
// var q = Utils.clone(qstr);
// var result = validator(value, q, key);
should.exist(result);
result.should.equal(false);
// should.exist(result);
// result.should.equal(false);
should.exist(q[key2]);
q[key2].should.equal(value2);
q[key].should.equal(value); // Original value not deleted
done();
})
// should.exist(q[key2]);
// q[key2].should.equal(value2);
// q[key].should.equal(value); // Original value not deleted
// done();
// })
it("should not allow two renames to set the same key if allowMult not set", function(done){
var base = new BaseType();
var q = Utils.clone(qstr);
var validator = base._rename(key3, {allowMult: false})
var result = validator(value, q, key);
// it("should not allow two renames to set the same key if allowMult not set", function(done){
// var base = new BaseType();
// var q = Utils.clone(qstr);
// var validator = base._rename(key3, {allowMult: false})
// var result = validator(value, q, key);
var validator = base._rename(key3, {allowMult: false})
var result = validator(value2, q, key2);
// var validator = base._rename(key3, {allowMult: false})
// var result = validator(value2, q, key2);
result.should.equal(false);
// result.should.equal(false);
// first _rename will not be rolled back
should.exist(q[key3]);
q[key3].should.equal(value);
done();
})
})
// // first _rename will not be rolled back
// should.exist(q[key3]);
// q[key3].should.equal(value);
// done();
// })
// })
describe("#description", function(){
it('should set description', function(done){
var value = "walmart";
var base = new BaseType();
var result;
(function(){
result = base.description(value);
}).should.not.throw();
should.exist(result);
result.description.should.equal(value);
done();
})
// describe("#description", function(){
// it('should set description', function(done){
// var value = "walmart";
// var base = new BaseType();
// var result;
// (function(){
// result = base.description(value);
// }).should.not.throw();
// should.exist(result);
// result.description.should.equal(value);
// done();
// })
it('should return error if description is not a string', function(done){
var value = 1;
var base = new BaseType();
var result;
(function(){
result = base.description(value);
}).should.throw();
// should.exist(result);
// result.description.should.equal(value);
done();
})
})
// it('should return error if description is not a string', function(done){
// var value = 1;
// var base = new BaseType();
// var result;
// (function(){
// result = base.description(value);
// }).should.throw();
// // should.exist(result);
// // result.description.should.equal(value);
// done();
// })
// })
describe("#notes", function(){
it('should set notes if given as string', function(done){
var value = "walmart";
var base = new BaseType();
var result;
(function(){
result = base.notes(value);
}).should.not.throw();
should.exist(result);
result.notes.should.equal(value);
done();
})
// describe("#notes", function(){
// it('should set notes if given as string', function(done){
// var value = "walmart";
// var base = new BaseType();
// var result;
// (function(){
// result = base.notes(value);
// }).should.not.throw();
// should.exist(result);
// result.notes.should.equal(value);
// done();
// })
it('should set notes if given as array', function(done){
var value = ["walmart", "@walmartlabs"];
var base = new BaseType();
var result;
(function(){
result = base.notes(value);
}).should.not.throw();
should.exist(result);
result.notes.should.equal(value);
done();
})
// it('should set notes if given as array', function(done){
// var value = ["walmart", "@walmartlabs"];
// var base = new BaseType();
// var result;
// (function(){
// result = base.notes(value);
// }).should.not.throw();
// should.exist(result);
// result.notes.should.equal(value);
// done();
// })
it('should return error if not given as string or array', function(done){
var value = 1;
var base = new BaseType();
var result;
(function(){
result = base.notes(value);
}).should.throw();
done();
})
})
// it('should return error if not given as string or array', function(done){
// var value = 1;
// var base = new BaseType();
// var result;
// (function(){
// result = base.notes(value);
// }).should.throw();
// done();
// })
// })
describe("#tags", function(){
it('should set tags if given as array', function(done){
var value = ["walmart", "@walmartlabs"];
var base = new BaseType();
var result;
(function(){
result = base.tags(value);
}).should.not.throw();
should.exist(result);
result.tags.should.equal(value);
done();
})
// describe("#tags", function(){
// it('should set tags if given as array', function(done){
// var value = ["walmart", "@walmartlabs"];
// var base = new BaseType();
// var result;
// (function(){
// result = base.tags(value);
// }).should.not.throw();
// should.exist(result);
// result.tags.should.equal(value);
// done();
// })
it('should return error if not given as array', function(done){
var value = 1;
var base = new BaseType();
var result;
(function(){
result = base.notes(value);
}).should.throw();
done();
})
})
})
// it('should return error if not given as array', function(done){
// var value = 1;
// var base = new BaseType();
// var result;
// (function(){
// result = base.notes(value);
// }).should.throw();
// done();
// })
// })
// })

@@ -0,0 +0,0 @@ var Types = require("../../lib/types");

var Types = require("../../lib/types/");
var should = require("should");
var verifyBehavior = require("../support/meta").verifyValidatorBehavior;
describe("Types.Number", function(){
var N = Types.Number;
it('should instantiate separate copies on invocation', function(done){
var result1 = N().min(5);
var result2 = N().max(5);
describe("test/types/number.js", function(){
describe("Types.Number", function(){
var N = Types.Number;
Object.keys(result1).should.not.equal(Object.keys(result2));
done();
describe("#validate", function(){
it('should work', function(done){
(function(){
var num = N();
var result = num.validate(100);
}).should.not.throw();
done();
})
it('should, by default, allow undefined', function(done){
verifyBehavior(N(), [
[undefined, true]
], done);
})
it("should, when .required(), deny undefined", function(done){
verifyBehavior(N().required(), [
[undefined, false]
], done);
})
it("should return false for denied value", function(done){
var text = N().deny(50);
var result = text.validate(50);
should.exist(result);
result.should.equal(false);
done();
})
})
})
})
// describe("Types.Number", function(){
// var N = Types.Number;
it("should inherit functions from BaseType", function(done){
var fns = ["required", "add"];
// it('should instantiate separate copies on invocation', function(done){
// var result1 = N().min(5);
// var result2 = N().max(5);
for(var i in fns){
should.exist(N()[fns[i]]);
}
done();
})
// Object.keys(result1).should.not.equal(Object.keys(result2));
// done();
// })
it("should show resulting object with #valueOf", function(done){
var result = N().min(5);
should.exist(result.valueOf());
done();
})
// it("should inherit functions from BaseType", function(done){
// var fns = ["required", "add"];
// for(var i in fns){
// should.exist(N()[fns[i]]);
// }
// done();
// })
describe("#min", function(done){
it('should exist', function(done){
should.exist(N().min);
done();
})
// it("should show resulting object with #valueOf", function(done){
// var result = N().min(5);
// should.exist(result.valueOf());
// done();
// })
// describe("#min", function(done){
// it('should exist', function(done){
// should.exist(N().min);
// done();
// })
it("should have corresponding validator function", function(done){
should.exist(N()._min);
done();
})
// it("should have corresponding validator function", function(done){
// should.exist(N()._min);
// done();
// })
it('should have value on #valueOf', function(done){
var result = N().min(5).valueOf();
should.exist(result);
(result.length).should.equal(2)
done();
})
})
// it('should have value on #valueOf', function(done){
// var result = N().min(5).valueOf();
// should.exist(result);
// (result.length).should.equal(2)
// done();
// })
// })
describe("#_min", function(done){
it('should validate on known valid input', function(done){
// var inputs = ["abcde", "fghij", "klmnopqrstuv"];
var inputs = [5, 6, 7, 8, 9];
var validator = N()._min(5);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(true);
}
done();
})
// describe("#_min", function(done){
// it('should validate on known valid input', function(done){
// // var inputs = ["abcde", "fghij", "klmnopqrstuv"];
// var inputs = [5, 6, 7, 8, 9];
// var validator = N()._min(5);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(true);
// }
// done();
// })
it('should invalidate on known invalid inputs', function(done){
// var inputs = ["abc", "de", ""];
var inputs = [0, 1, 2, 3, 4];
var validator = N()._min(5);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(false);
}
done();
})
})
// it('should invalidate on known invalid inputs', function(done){
// // var inputs = ["abc", "de", ""];
// var inputs = [0, 1, 2, 3, 4];
// var validator = N()._min(5);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(false);
// }
// done();
// })
// })
describe("#max", function(done){
it('should exist', function(done){
should.exist(N().max);
done();
})
// describe("#max", function(done){
// it('should exist', function(done){
// should.exist(N().max);
// done();
// })
it("should have corresponding validator function", function(done){
should.exist(N()._max);
done();
})
// it("should have corresponding validator function", function(done){
// should.exist(N()._max);
// done();
// })
it('should have correct length on #valueOf', function(done){
var result = N().max(5).valueOf();
should.exist(result);
(result.length).should.equal(2)
done();
})
})
// it('should have correct length on #valueOf', function(done){
// var result = N().max(5).valueOf();
// should.exist(result);
// (result.length).should.equal(2)
// done();
// })
// })
describe("#_max", function(done){
it('should validate on known valid input', function(done){
// var inputs = ["abc", "de", ""];
var inputs = [0, 1, 2, 3, 4];
var validator = N()._max(4);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(true);
}
done();
})
// describe("#_max", function(done){
// it('should validate on known valid input', function(done){
// // var inputs = ["abc", "de", ""];
// var inputs = [0, 1, 2, 3, 4];
// var validator = N()._max(4);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(true);
// }
// done();
// })
it('should invalidate on known invalid inputs', function(done){
// var inputs = ["abcde", "fghij", "klmnopqrstuv"];
var inputs = [5, 6, 7, 8];
var validator = N()._max(4);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(false);
}
done();
})
})
})
// it('should invalidate on known invalid inputs', function(done){
// // var inputs = ["abcde", "fghij", "klmnopqrstuv"];
// var inputs = [5, 6, 7, 8];
// var validator = N()._max(4);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(false);
// }
// done();
// })
// })
// })
var Types = require("../../lib/types/");
var should = require("should");
var verifyBehavior = require("../support/meta").verifyValidatorBehavior;
describe("Types.String", function(){
var S = Types.String;
it('should instantiate separate copies on invocation', function(done){
var result1 = S().min(5);
var result2 = S().max(5);
describe("test/types/string.js", function(){
describe("Types.String", function(){
var S = Types.String;
Object.keys(result1).should.not.equal(Object.keys(result2));
done();
it("should instantiate separate copies on invocation", function(done){
var result1 = S().min(5);
var result2 = S().max(5);
Object.keys(result1).should.not.equal(Object.keys(result2));
done();
})
describe("#valid", function(){
it("should throw error on input not matching type", function(done){
(function(){
S().valid(1);
}).should.throw();
done()
})
it("should not throw on input matching type", function(done){
(function(){
S().valid("walmart");
}).should.not.throw();
done()
})
})
describe("#invalid", function(){
it("should throw error on input not matching type", function(done){
(function(){
S().invalid(1);
}).should.throw();
done()
})
it("should not throw on input matching type", function(done){
(function(){
S().invalid("walmart");
}).should.not.throw();
done()
})
})
describe("#validate", function(){
it('should work', function(done){
(function(){
var text = S();
var result = text.validate("joi");
}).should.not.throw();
done();
})
it('should, by default, allow undefined, deny empty string', function(done){
var conditions = [
[undefined, true],
["", false]
];
verifyBehavior(S(), conditions, done);
})
it("should, when .required(), deny undefined, deny empty string", function(done){
var t = S().required();
verifyBehavior(t, [
[undefined, false],
["", false]
], done);
})
it("should return false for denied value", function(done){
var text = S().deny("joi");
var result = text.validate("joi");
should.exist(result);
result.should.equal(false);
done();
})
it("should return true for allowed value", function(done){
var text = S().allow("hapi");
var result = text.validate("result");
should.exist(result);
result.should.equal(true);
done();
})
it("should validate with one validator (min)", function(done){
var text = S().min(3);
var result = text.validate("walmart");
should.exist(result);
result.should.equal(true);
done();
})
it("should validate with two validators (min, required)", function(done){
var text = S().min(3).required();
var result = text.validate("walmart")
should.exist(result);
result.should.equal(true);
var result2 = text.validate();
should.exist(result2);
result2.should.equal(false);
done();
})
it("should validate null with nullOk()", function(done){
verifyBehavior(S().nullOk(), [
[null, true]
], done);
})
it("should validate '' (empty string) with emptyOk()", function(done){
verifyBehavior(S().emptyOk(), [
['', true],
["", true]
], done);
})
})
})
})
// describe("Types.String", function(){
// var S = Types.String;
it("should inherit functions from BaseType", function(done){
var fns = ["required", "add"];
// it('should instantiate separate copies on invocation', function(done){
// var result1 = S().min(5);
// var result2 = S().max(5);
for(var i in fns){
should.exist(S()[fns[i]]);
}
done();
})
// Object.keys(result1).should.not.equal(Object.keys(result2));
// done();
// })
it("should show resulting object with #valueOf", function(done){
var result = S().min(5);
should.exist(result.valueOf());
done();
})
// it("should inherit functions from BaseType", function(done){
// var fns = ["required", "add"];
// for(var i in fns){
// should.exist(S()[fns[i]]);
// }
// done();
// })
// describe("#_base", function(){
// it("should work", function(done){
// var fn = S()._base();
// fn._valids = []
// var result = fn()
// done();
// })
// })
// it("should show resulting object with #valueOf", function(done){
// var result = S().min(5);
// should.exist(result.valueOf());
// done();
// })
describe("#min", function(done){
it('should exist', function(done){
should.exist(S().min);
done();
})
// // describe("#_base", function(){
// // it("should work", function(done){
// // var fn = S()._base();
// // fn._valids = []
// // var result = fn()
// // done();
// // })
// // })
// describe("#min", function(done){
// it('should exist', function(done){
// should.exist(S().min);
// done();
// })
it("should have corresponding validator function", function(done){
should.exist(S()._min);
done();
})
// it("should have corresponding validator function", function(done){
// should.exist(S()._min);
// done();
// })
it('should have value on #valueOf', function(done){
var result = S().min(5).valueOf();
should.exist(result);
(result.length).should.equal(2)
done();
})
})
// it('should have value on #valueOf', function(done){
// var result = S().min(5).valueOf();
// should.exist(result);
// (result.length).should.equal(2)
// done();
// })
// })
describe("#_min", function(done){
it('should validate on known valid input', function(done){
var inputs = ["abcde", "fghij", "klmnopqrstuv"];
var validator = S()._min(5);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(true);
}
done();
})
// describe("#_min", function(done){
// it('should validate on known valid input', function(done){
// var inputs = ["abcde", "fghij", "klmnopqrstuv"];
// var validator = S()._min(5);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(true);
// }
// done();
// })
it('should invalidate on known invalid inputs', function(done){
var inputs = ["abc", "de", ""];
var validator = S()._min(5);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(false);
}
done();
})
})
// it('should invalidate on known invalid inputs', function(done){
// var inputs = ["abc", "de", ""];
// var validator = S()._min(5);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(false);
// }
// done();
// })
// })
describe("#max", function(done){
it('should exist', function(done){
should.exist(S().max);
done();
})
// describe("#max", function(done){
// it('should exist', function(done){
// should.exist(S().max);
// done();
// })
it("should have corresponding validator function", function(done){
should.exist(S()._max);
done();
})
// it("should have corresponding validator function", function(done){
// should.exist(S()._max);
// done();
// })
it('should have correct length on #valueOf', function(done){
var result = S().max(5).valueOf();
should.exist(result);
(result.length).should.equal(2)
done();
})
})
// it('should have correct length on #valueOf', function(done){
// var result = S().max(5).valueOf();
// should.exist(result);
// (result.length).should.equal(2)
// done();
// })
// })
describe("#_max", function(done){
it('should validate on known valid input', function(done){
var inputs = ["abc", "de", ""];
var validator = S()._max(4);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(true);
}
done();
})
// describe("#_max", function(done){
// it('should validate on known valid input', function(done){
// var inputs = ["abc", "de", ""];
// var validator = S()._max(4);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(true);
// }
// done();
// })
it('should invalidate on known invalid inputs', function(done){
var inputs = ["abcde", "fghij", "klmnopqrstuv"];
var validator = S()._max(4);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(false);
}
done();
})
})
// it('should invalidate on known invalid inputs', function(done){
// var inputs = ["abcde", "fghij", "klmnopqrstuv"];
// var validator = S()._max(4);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(false);
// }
// done();
// })
// })
describe("#regex", function(done){
it('should exist', function(done){
should.exist(S().regex);
done();
})
// describe("#regex", function(done){
// it('should exist', function(done){
// should.exist(S().regex);
// done();
// })
it("should have corresponding validator function", function(done){
should.exist(S()._regex);
done();
})
// it("should have corresponding validator function", function(done){
// should.exist(S()._regex);
// done();
// })
it('should have correct length on #valueOf', function(done){
var result = S().regex(/^[a-z]+$/).valueOf();
should.exist(result);
(result.length).should.equal(2)
done();
})
})
// it('should have correct length on #valueOf', function(done){
// var result = S().regex(/^[a-z]+$/).valueOf();
// should.exist(result);
// (result.length).should.equal(2)
// done();
// })
// })
describe("#_regex", function(done){
it('should validate on known valid input', function(done){
var inputs = ["aaaaa", "abcdefghijklmnopqrstuvwxyz", "walmartlabs"];
var validator = S()._regex(/^[a-z]+$/);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(true);
}
done();
})
// describe("#_regex", function(done){
// it('should validate on known valid input', function(done){
// var inputs = ["aaaaa", "abcdefghijklmnopqrstuvwxyz", "walmartlabs"];
// var validator = S()._regex(/^[a-z]+$/);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(true);
// }
// done();
// })
it('should invalidate on known invalid inputs', function(done){
var inputs = ["abcd#f?h1j", "m3ch4", "m3g4"];
var validator = S()._regex(/^[a-z]+$/);
for(var i in inputs){
var currentResult = validator(inputs[i]);
should.exist(currentResult);
currentResult.should.equal(false);
}
done();
})
})
})
// it('should invalidate on known invalid inputs', function(done){
// var inputs = ["abcd#f?h1j", "m3ch4", "m3g4"];
// var validator = S()._regex(/^[a-z]+$/);
// for(var i in inputs){
// var currentResult = validator(inputs[i]);
// should.exist(currentResult);
// currentResult.should.equal(false);
// }
// done();
// })
// })
// })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc