Comparing version 0.0.2 to 0.0.3
279
index.js
@@ -5,3 +5,3 @@ //----------------------------------------------------- | ||
// Site: 666.io | ||
// Version: 0.00.002 | ||
// Version: 0.00.003 | ||
// | ||
@@ -51,6 +51,4 @@ //----------------------------------------------------- | ||
options = options || {}; | ||
if( | ||
(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) == -1) || | ||
(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) === -1) || | ||
(typeof(options.pattern) !== "undefined" && !options.pattern.test(input)) || | ||
@@ -69,7 +67,5 @@ (typeof(options.min) !== "undefined" && input.length < options.min) || | ||
options = options || {}; | ||
if( | ||
(input !== parseInt(input, options.radix || 10)) || | ||
(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) == -1) || | ||
(input !== parseInt(input, 10)) || | ||
(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) === -1) || | ||
(typeof(options.min) !== "undefined" && input < options.min) || | ||
@@ -87,6 +83,4 @@ (typeof(options.max) !== "undefined" && input > options.max) | ||
options = options || {}; | ||
if( | ||
(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) == -1) || | ||
(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) === -1) || | ||
(typeof(options.min) !== "undefined" && input < options.min) || | ||
@@ -101,6 +95,6 @@ (typeof(options.max) !== "undefined" && input > options.max) | ||
"date": function(input) { | ||
if(!input || input instanceof(Date) && !input.getTime()) | ||
if(!input || !(input instanceof(Date)) || !input.getTime()) | ||
return false; | ||
return !isNaN(Date.parse(input)); | ||
return true; | ||
}, | ||
@@ -122,4 +116,2 @@ | ||
options = options || {}; | ||
if( | ||
@@ -203,4 +195,2 @@ (typeof(options.min) !== "undefined" && input.length < options.min) || | ||
options = options || {}; | ||
return !!input.match(options.strict ? /^#[0-9A-F]{6}$/i : /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i); | ||
@@ -243,4 +233,2 @@ }, | ||
options = options || {}; | ||
var rgPhone = gVPhones[options.locale || "ru-RU"]; | ||
@@ -257,4 +245,2 @@ | ||
options = options || {}; | ||
var version = options.version, | ||
@@ -279,4 +265,2 @@ pattern; | ||
options = options || {}; | ||
///---)> | ||
@@ -317,2 +301,149 @@ | ||
//-----------------------------]> | ||
function normalize(type, input, options) { | ||
if(type === "custom") | ||
return input; | ||
//------------------]> | ||
switch(type) { | ||
case "boolean": | ||
if(typeof(input) === "boolean") | ||
return input; | ||
if(typeof(input) === "string") | ||
return input === "true" || input === "on" || input === "yes" || input === "1"; | ||
return false; | ||
case "string": | ||
if(typeof(input) === "string") | ||
return input; | ||
if(input === null || typeof(input) === "undefined") | ||
return ""; | ||
if(typeof(input.toString) === "function") | ||
return input.toString(); | ||
if(typeof(input) === "object") | ||
return Object.prototype.toString.call(input); | ||
return input + ""; | ||
case "integer": | ||
return parseInt(input, options.radix || 10); | ||
case "float": | ||
if(typeof(input) === "number") | ||
return input; | ||
return parseFloat(input); | ||
case "date": | ||
if(input instanceof(Date)) | ||
return input; | ||
return new Date(input); | ||
case "hashTable": | ||
if(!input || Array.isArray(input)) | ||
return {}; | ||
if(typeof(input) === "object") | ||
return input; | ||
if(typeof(input) !== "string") | ||
return {}; | ||
try { | ||
input = JSON.parse(input); | ||
return Array.isArray(input) ? {} : input; | ||
} catch(e) { | ||
} | ||
return {}; | ||
case "array": | ||
if(Array.isArray(input)) | ||
return input; | ||
if(!input || typeof(input) !== "string") | ||
return []; | ||
try { | ||
input = JSON.parse(input); | ||
return Array.isArray(input) ? input : []; | ||
} catch(e) { | ||
} | ||
return []; | ||
case "json": | ||
if(typeof(input) === "object") | ||
return input; | ||
if(!input || typeof(input) !== "string") | ||
return null; | ||
try { | ||
return JSON.parse(input); | ||
} catch(e) { | ||
} | ||
return null; | ||
//------------------------]> | ||
default: | ||
throw "[!] Sanitizer | Unknown Type.\n" + type + " : " + JSON.stringify(options); | ||
} | ||
} | ||
function postNormilize(type, input, options) { | ||
switch(type) { | ||
case "string": | ||
if(options.trim) | ||
input = input.trim(); | ||
if(typeof(options.length) !== "undefined" && input.length > options.length) | ||
input = input.substring(0, options.length); | ||
break; | ||
case "integer": | ||
if(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) === -1) | ||
return NaN; | ||
if(typeof(options.min) !== "undefined" && input < options.min) | ||
return parseInt(options.min, 10); | ||
if(typeof(options.max) !== "undefined" && input > options.max) | ||
return parseInt(options.max, 10); | ||
break; | ||
case "float": | ||
if(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) === -1) | ||
return NaN; | ||
if(typeof(options.min) !== "undefined" && input < options.min) | ||
return parseFloat(options.min); | ||
if(typeof(options.max) !== "undefined" && input > options.max) | ||
return parseFloat(options.max); | ||
break; | ||
case "array": | ||
if(typeof(options.max) !== "undefined" && input.length > options.max) | ||
input.length = options.max; | ||
break; | ||
} | ||
return input; | ||
} | ||
//-------[HELPERS]-------}> | ||
@@ -326,6 +457,5 @@ | ||
//-----------------------------]> | ||
var result = { | ||
var gExport = { | ||
"global": function(v) { | ||
@@ -336,11 +466,16 @@ if(!typeof(global) == "object" || typeof(v) == "undefined" || typeof(global.$validate) != "undefined") | ||
if(v) { | ||
var gObj = result.validate; | ||
var gSObj = gExport.sanitize, | ||
gVObj = gExport.validate; | ||
for(var i in result) { | ||
if(result.hasOwnProperty(i)) gObj[i] = result[i]; | ||
for(var i in gExport) { | ||
if(gExport.hasOwnProperty(i)) | ||
gSObj[i] = gVObj[i] = gExport[i]; | ||
} | ||
global.$validate = gObj; | ||
} else | ||
global.$sanitize = gSObj; | ||
global.$validate = gVObj; | ||
} else { | ||
delete global.$sanitize; | ||
delete global.$validate; | ||
} | ||
@@ -356,18 +491,47 @@ return this; | ||
"validate": function(schema, data, options) { | ||
"sanitize": function(schema, data, options) { | ||
if(!schema) | ||
throw "[!] Validation | not found method: " + schema; | ||
throw "[!] Sanitizer | schema: " + schema; | ||
options = options || {}; | ||
//----------------]> | ||
if(Array.isArray(schema)) { | ||
var args, nameFunc, func, | ||
i = arguments.length; | ||
if(typeof(schema) === "string") { | ||
if(schema[0] == "?") { | ||
if(typeof(data) == "undefined") | ||
return undefined; | ||
while(i--) { | ||
args = arguments[i]; | ||
nameFunc = args[0]; | ||
schema = schema.substring(1); | ||
} | ||
if(nameFunc[0] == "?") { | ||
if(typeof(args[1]) == "undefined") | ||
return postNormilize(schema, normalize(schema, data, options), options); | ||
} | ||
if(typeof(schema) === "object") { | ||
if(!data || typeof(data) !== "object") | ||
return null; | ||
//----------------)> | ||
var result = {}; | ||
for(var field in schema) { | ||
if(!schema.hasOwnProperty(field)) continue; | ||
var nameFunc, | ||
schemaData = schema[field], | ||
fieldData = data[field]; | ||
//-----------------)> | ||
if(typeof(schemaData) === "string") { | ||
nameFunc = schemaData; | ||
schemaData = {}; | ||
} else if(typeof(schemaData) === "object") { | ||
nameFunc = schemaData.use; | ||
} | ||
if(nameFunc[0] === "?") { | ||
if(typeof(fieldData) === "undefined") | ||
continue; | ||
@@ -378,16 +542,23 @@ | ||
func = gVMethods[nameFunc]; | ||
//-----------------)> | ||
if(!func) | ||
throw "[!] Validation | not found method: " + nameFunc; | ||
if(!func(args[1], args[2])) | ||
return false; | ||
result[field] = postNormilize(nameFunc, normalize(nameFunc, fieldData, schemaData), schemaData); | ||
} | ||
return true; | ||
return result; | ||
} | ||
//-------]> | ||
//----------------]> | ||
throw "[!] Sanitizer | schema: " + schema; | ||
}, | ||
"validate": function(schema, data, options) { | ||
if(!schema) | ||
throw "[!] Validation | schema: " + schema; | ||
options = options || {}; | ||
//----------------]> | ||
if(typeof(schema) === "string") { | ||
@@ -401,3 +572,2 @@ if(schema[0] == "?") { | ||
var func = gVMethods[schema]; | ||
@@ -419,3 +589,3 @@ | ||
var optErrors = options && options.errors; | ||
var optErrors = options.errors; | ||
var result = optErrors ? null : true; | ||
@@ -434,2 +604,3 @@ | ||
nameFunc = schemaData; | ||
schemaData = {}; | ||
} else if(typeof(schemaData) === "object") { | ||
@@ -439,4 +610,4 @@ nameFunc = schemaData.use; | ||
if(nameFunc[0] == "?") { | ||
if(typeof(fieldData) == "undefined") | ||
if(nameFunc[0] === "?") { | ||
if(typeof(fieldData) === "undefined") | ||
continue; | ||
@@ -478,7 +649,7 @@ | ||
throw "[!] Validation | not found method: " + schema; | ||
throw "[!] Validation | schema: " + schema; | ||
} | ||
}; | ||
return result; | ||
return gExport; | ||
})(); | ||
@@ -485,0 +656,0 @@ |
{ | ||
"name": "aigis", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Simple and Powerful module for strict validation", | ||
@@ -38,4 +38,4 @@ | ||
"_id": "aigis@0.0.2", | ||
"_id": "aigis@0.0.3", | ||
"_from": "aigis@" | ||
} |
@@ -10,7 +10,8 @@ `npm install aigis -g` | ||
"status": "?string", | ||
"pts": {"use": "integer", "max": 60} | ||
"pts": {"use": "integer", "max": 30} | ||
}, | ||
data = {"name": "X", "pts": 32}; | ||
data = {"name": "X", "pts": "60"}; | ||
$aigis(schema, data); | ||
$sanitize(schema, data); | ||
$validate(schema, data); | ||
``` | ||
@@ -29,6 +30,23 @@ | ||
| | - || | ||
| global | Set `$validate` as Global Var (NodeJS) | (v [default: true]) | | ||
| rule | Add/Remove/Get custom Rule | (name, [func]) ~ func(input, options) | | ||
| global | Set `$sanitize, $validate` as Global Var (NodeJS) | (v [default: true]) | | ||
| rule | Add/Remove/Get custom Rule | (name, [func]) ~ func(input, options) | | ||
| | - || | ||
| sanitize | - | (schema (String/HashTable), data, [options]) | | ||
| validate | - | (schema (String/HashTable), data, [options]) | | ||
#### Sanitize | ||
| Name | Desc | Val | | ||
|-------------|-------------|-------------| | ||
| | - || | ||
| validate | - | (schema (String/Array/HashTable), data, [options]) | | ||
| boolean | true: "true", "on", "yes", "1" | - | | ||
| string | - | length, trim | | ||
| integer | - | min, max, enum | | ||
| float | - | min, max, enum | | ||
| date | - | - | | ||
| hashTable | - | - | | ||
| array | - | max | | ||
| json | - | - | | ||
@@ -65,3 +83,3 @@ | ||
| string | - | min, max, enum, pattern | | ||
| integer | - | min, max, enum, radix | | ||
| integer | - | min, max, enum | | ||
| float | - | min, max, enum | | ||
@@ -110,5 +128,31 @@ | date | - | - | | ||
console.log("+-------------------------+"); | ||
console.log("| Custom"); | ||
console.log("| S: String"); | ||
console.log("+-------------------------+"); | ||
console.log(JSON.stringify({ | ||
"T0": $sanitize("string", 10), | ||
"T1": $sanitize("integer", "80", {"max": 50}), | ||
"T2": $sanitize("array", "[1,2,3]", {"max": 2}) | ||
}, null, "\t")); | ||
console.log("+-------------------------+"); | ||
console.log("| S: HashTable"); | ||
console.log("+-------------------------+"); | ||
var schema = { | ||
"name": {"use": "string", "length": 2, "trim": true}, | ||
"status": "?string", | ||
"pts": {"use": "integer", "max": 30} | ||
}, | ||
data = {"name": " DT+ ", "pts": "60"}; | ||
console.log("1#", $sanitize(schema, data)); | ||
console.log("+-------------------------+"); | ||
console.log("| V: Custom"); | ||
console.log("+-------------------------+"); | ||
$validate.rule("testRuleMax10", function(input, options) { | ||
@@ -123,3 +167,3 @@ return input < 10; | ||
console.log("+-------------------------+"); | ||
console.log("| String"); | ||
console.log("| V: String"); | ||
console.log("+-------------------------+"); | ||
@@ -135,20 +179,6 @@ | ||
console.log("+-------------------------+"); | ||
console.log("| Array"); | ||
console.log("| V: HashTable"); | ||
console.log("+-------------------------+"); | ||
console.log(JSON.stringify({ | ||
"T0": $validate(["integer", 10], ["email", "0d@root.pop"]), | ||
"T1": $validate(["string", 10], ["email", "0d@root.pop"]), | ||
"T2": $validate(["string", 10], ["email", "0d-root.pop"]), | ||
"T3": $validate(["?string", undefined], ["email", "0d@root.pop"]), | ||
"T4": $validate(["?string", undefined], ["email", "0d-root.pop"]) | ||
}, null, "\t")); | ||
console.log("+-------------------------+"); | ||
console.log("| HashTable"); | ||
console.log("+-------------------------+"); | ||
var schema = {"name": "string", "status": "?string", "pts": "integer"}, | ||
@@ -155,0 +185,0 @@ data = {"name": "DT", "pts": "32"}; |
@@ -17,5 +17,31 @@ //----------------------------------------------------- | ||
console.log("+-------------------------+"); | ||
console.log("| Custom"); | ||
console.log("| S: String"); | ||
console.log("+-------------------------+"); | ||
console.log(JSON.stringify({ | ||
"T0": $sanitize("string", 10), | ||
"T1": $sanitize("integer", "80", {"max": 50}), | ||
"T2": $sanitize("array", "[1,2,3]", {"max": 2}) | ||
}, null, "\t")); | ||
console.log("+-------------------------+"); | ||
console.log("| S: HashTable"); | ||
console.log("+-------------------------+"); | ||
var schema = { | ||
"name": {"use": "string", "length": 2, "trim": true}, | ||
"status": "?string", | ||
"pts": {"use": "integer", "max": 30} | ||
}, | ||
data = {"name": " DT+ ", "pts": "60"}; | ||
console.log("1#", $sanitize(schema, data)); | ||
console.log("+-------------------------+"); | ||
console.log("| V: Custom"); | ||
console.log("+-------------------------+"); | ||
$validate.rule("testRuleMax10", function(input, options) { | ||
@@ -30,3 +56,3 @@ return input < 10; | ||
console.log("+-------------------------+"); | ||
console.log("| String"); | ||
console.log("| V: String"); | ||
console.log("+-------------------------+"); | ||
@@ -42,20 +68,6 @@ | ||
console.log("+-------------------------+"); | ||
console.log("| Array"); | ||
console.log("| V: HashTable"); | ||
console.log("+-------------------------+"); | ||
console.log(JSON.stringify({ | ||
"T0": $validate(["integer", 10], ["email", "0d@root.pop"]), | ||
"T1": $validate(["string", 10], ["email", "0d@root.pop"]), | ||
"T2": $validate(["string", 10], ["email", "0d-root.pop"]), | ||
"T3": $validate(["?string", undefined], ["email", "0d@root.pop"]), | ||
"T4": $validate(["?string", undefined], ["email", "0d-root.pop"]) | ||
}, null, "\t")); | ||
console.log("+-------------------------+"); | ||
console.log("| HashTable"); | ||
console.log("+-------------------------+"); | ||
var schema = {"name": "string", "status": "?string", "pts": "integer"}, | ||
@@ -62,0 +74,0 @@ data = {"name": "DT", "pts": "32"}; |
412
test/test.js
@@ -17,7 +17,34 @@ //----------------------------------------------------- | ||
var count = 0; | ||
rA.strictEqualNumber = function(actual, expected, message) { | ||
if(typeof(actual) != "undefined" && isNaN(expected)) { | ||
if(!isNaN(actual)) | ||
throw (message || ""); | ||
} else if(actual !== expected) | ||
throw (message || ""); | ||
}; | ||
function test(exp, data) { | ||
count++; | ||
rA.strictEqualDate = function(actual, expected, message) { | ||
if(actual === expected || isNaN(actual) == isNaN(expected)) | ||
return; | ||
if(typeof(actual) != "object" || typeof(expected) != "object") | ||
throw (message || ""); | ||
var at = actual.getTime(); | ||
var et = expected.getTime(); | ||
if((at !== et && !isNaN(at) && !isNaN(et)) || isNaN(at) != isNaN(at)) | ||
throw (message || ""); | ||
}; | ||
//-------------------]> | ||
var count = { | ||
"v": 0, | ||
"s": 0 | ||
}; | ||
function testS(exp, data) { | ||
count.s++; | ||
var result = true, | ||
@@ -27,2 +54,28 @@ args = Array.prototype.slice.call(arguments, 1); | ||
try { | ||
if(typeof(exp) === "number") | ||
rA.strictEqualNumber($sanitize.apply(null, args), exp); | ||
else if(exp instanceof Date) | ||
rA.strictEqualDate($sanitize.apply(null, args), exp); | ||
else if(typeof(exp) === "object" || exp !== null) | ||
rA.deepEqual($sanitize.apply(null, args), exp); | ||
else | ||
rA.strictEqual($sanitize.apply(null, args), exp); | ||
} catch(e) { | ||
result = false; | ||
console.log(args); | ||
console.log(e); | ||
console.log("\n"); | ||
} | ||
console.log("|%s|> T%s ", result ? "+" : "-", count.s); | ||
} | ||
function testV(exp, data) { | ||
count.v++; | ||
var result = true, | ||
args = Array.prototype.slice.call(arguments, 1); | ||
try { | ||
rA.deepEqual($validate.apply(null, args), exp); | ||
@@ -37,3 +90,3 @@ } catch(e) { | ||
console.log("|%s|> T%s ", result ? "+" : "-", count); | ||
console.log("|%s|> T%s ", result ? "+" : "-", count.v); | ||
} | ||
@@ -45,4 +98,74 @@ | ||
console.log("|"); | ||
console.log("| Sanitize"); | ||
{ | ||
var date = new Date(), | ||
dateNow = Date.now(), | ||
regex = /\s+/g; | ||
testS(true, "boolean", true); | ||
testS(false, "boolean", false); | ||
testS(true, "boolean", "true"); | ||
testS(false, "boolean", "false"); | ||
testS(false, "boolean", "on1"); | ||
testS(true, "boolean", "on"); | ||
testS(true, "boolean", "yes"); | ||
testS(true, "boolean", "1"); | ||
testS("10", "string", 10); | ||
testS("10", "string", "10"); | ||
testS(date.toString(), "string", date); | ||
testS(regex.toString(), "string", regex); | ||
testS(10, "integer", 10); | ||
testS(10, "integer", 10.5); | ||
testS(10, "integer", "10"); | ||
testS(NaN, "integer", ""); | ||
testS(10, "float", 10); | ||
testS(10.5, "float", 10.5); | ||
testS(10, "float", "10"); | ||
testS(NaN, "float", ""); | ||
testS(new Date(10), "date", 10); | ||
testS(new Date(NaN), "date", new Date(NaN)); | ||
testS(date, "date", date); | ||
testS(new Date(dateNow), "date", Date.now()); | ||
testS(new Date("23/25/2014"), "date", "23/25/2014"); | ||
testS(new Date("2014-25-23"), "date", "2014-25-23"); | ||
testS(new Date(""), "date", ""); | ||
testS(new Date("Thu, 01 Jan 1970 00:00:00 GMT-0400"), "date", "Thu, 01 Jan 1970 00:00:00 GMT-0400"); | ||
testS({'x': 1}, "hashTable", {'x': 1}); | ||
testS({}, "hashTable", "{'x': 1"); | ||
testS({}, "hashTable", "[1,2]"); | ||
testS({'x': 1}, "hashTable", JSON.stringify({'x': 1})); | ||
testS([1,2], "array", [1,2]); | ||
testS([], "array", "[1,2"); | ||
testS([1,2], "array", "[1,2]"); | ||
testS([], "array", {x:1}); | ||
testS([], "array", "{'x': 1}"); | ||
testS(null, "json", null); | ||
testS({'x': 1}, "json", {'x': 1}); | ||
testS([1,2], "json", [1,2]); | ||
testS(null, "json", undefined); | ||
testS(null, "json", NaN); | ||
testS(null, "json", "{'x': 1"); | ||
testS(null, "json", "{'x': 1}"); | ||
testS({'x': 1}, "json", JSON.stringify({'x': 1})); | ||
testS([1,2], "json", "[1,2]"); | ||
testS(null, "json", "[1,2"); | ||
} | ||
console.log("+-------------------------+"); | ||
//-------------------------]> | ||
console.log("+-------------------------+"); | ||
console.log("|"); | ||
console.log("| Validate"); | ||
{ | ||
[ | ||
@@ -56,175 +179,176 @@ "finite", | ||
.forEach(function(e) { | ||
test(false, e, undefined); | ||
test(false, e, null); | ||
test(false, e, NaN); | ||
testV(false, e, undefined); | ||
testV(false, e, null); | ||
testV(false, e, NaN); | ||
}); | ||
test(true, "null", null); | ||
test(false, "null", undefined); | ||
test(false, "null", 10); | ||
test(false, "null", ""); | ||
test(false, "null", NaN); | ||
testV(true, "null", null); | ||
testV(false, "null", undefined); | ||
testV(false, "null", 10); | ||
testV(false, "null", ""); | ||
testV(false, "null", NaN); | ||
test(true, "nan", NaN); | ||
test(false, "nan", undefined); | ||
test(false, "nan", ""); | ||
test(false, "nan", null); | ||
testV(true, "nan", NaN); | ||
testV(false, "nan", undefined); | ||
testV(false, "nan", ""); | ||
testV(false, "nan", null); | ||
test(true, "finite", 10); | ||
test(false, "finite", ""); | ||
test(false, "finite", "10"); | ||
test(false, "finite", +1 / 0); | ||
test(false, "finite", -1 / 0); | ||
testV(true, "finite", 10); | ||
testV(false, "finite", ""); | ||
testV(false, "finite", "10"); | ||
testV(false, "finite", +1 / 0); | ||
testV(false, "finite", -1 / 0); | ||
test(true, "boolean", true); | ||
test(true, "boolean", false); | ||
test(false, "boolean", "true"); | ||
testV(true, "boolean", true); | ||
testV(true, "boolean", false); | ||
testV(false, "boolean", "true"); | ||
test(false, "string", 10); | ||
test(true, "string", "10"); | ||
testV(false, "string", 10); | ||
testV(true, "string", "10"); | ||
test(true, "integer", 10); | ||
test(false, "integer", 10.5); | ||
test(false, "integer", "10"); | ||
test(false, "integer", ""); | ||
testV(true, "integer", 10); | ||
testV(false, "integer", 10.5); | ||
testV(false, "integer", "10"); | ||
testV(false, "integer", ""); | ||
test(true, "float", 10); | ||
test(true, "float", 10.5); | ||
test(false, "float", "10"); | ||
test(false, "float", ""); | ||
testV(true, "float", 10); | ||
testV(true, "float", 10.5); | ||
testV(false, "float", "10"); | ||
testV(false, "float", ""); | ||
test(true, "date", 10); | ||
test(false, "date", new Date(NaN)); | ||
test(true, "date", new Date()); | ||
test(false, "date", Date.now()); | ||
test(false, "date", "23/25/2014"); | ||
test(false, "date", "2014-25-23"); | ||
test(false, "date", ""); | ||
test(true, "date", "Thu, 01 Jan 1970 00:00:00 GMT-0400"); | ||
testV(false, "date", 10); | ||
testV(false, "date", new Date(NaN)); | ||
testV(true, "date", new Date()); | ||
testV(false, "date", Date.now()); | ||
testV(false, "date", "23/25/2014"); | ||
testV(false, "date", "2014-25-23"); | ||
testV(false, "date", ""); | ||
testV(false, "date", "Thu, 01 Jan 1970 00:00:00 GMT-0400"); | ||
test(true, "hashTable", {'x': 1}); | ||
test(false, "hashTable", "{'x': 1"); | ||
test(false, "hashTable", "[1,2]"); | ||
test(false, "hashTable", JSON.stringify({'x': 1})); | ||
testV(true, "hashTable", {'x': 1}); | ||
testV(false, "hashTable", "{'x': 1"); | ||
testV(false, "hashTable", "{'x': 1}"); | ||
testV(false, "hashTable", "[1,2]"); | ||
testV(false, "hashTable", JSON.stringify({'x': 1})); | ||
test(true, "array", [1,2]); | ||
test(false, "array", "[1,2"); | ||
test(false, "array", "[1,2]"); | ||
test(false, "array", {x:1}); | ||
test(false, "array", "{'x': 1}"); | ||
testV(true, "array", [1,2]); | ||
testV(false, "array", "[1,2"); | ||
testV(false, "array", "[1,2]"); | ||
testV(false, "array", {x:1}); | ||
testV(false, "array", "{'x': 1}"); | ||
test(true, "json", null); | ||
test(true, "json", {'x': 1}); | ||
test(true, "json", [1,2]); | ||
test(false, "json", undefined); | ||
test(false, "json", NaN); | ||
test(false, "json", "{'x': 1"); | ||
test(false, "json", "{'x': 1}"); | ||
test(false, "json", JSON.stringify({'x': 1})); | ||
test(false, "json", "[1,2]"); | ||
test(false, "json", "[1,2"); | ||
testV(true, "json", null); | ||
testV(true, "json", {'x': 1}); | ||
testV(true, "json", [1,2]); | ||
testV(false, "json", undefined); | ||
testV(false, "json", NaN); | ||
testV(false, "json", "{'x': 1"); | ||
testV(false, "json", "{'x': 1}"); | ||
testV(false, "json", JSON.stringify({'x': 1})); | ||
testV(false, "json", "[1,2]"); | ||
testV(false, "json", "[1,2"); | ||
test(false, "required", ""); | ||
test(false, "required", new Date(NaN)); | ||
testV(false, "required", ""); | ||
testV(false, "required", new Date(NaN)); | ||
test(false, "notEmpty", " "); | ||
test(false, "notEmpty", "\n\n"); | ||
test(true, "notEmpty", " 1 "); | ||
test(true, "notEmpty", "\n2\n"); | ||
test(false, "notEmpty", "\t\t"); | ||
test(true, "notEmpty", "\t3\t"); | ||
testV(false, "notEmpty", " "); | ||
testV(false, "notEmpty", "\n\n"); | ||
testV(true, "notEmpty", " 1 "); | ||
testV(true, "notEmpty", "\n2\n"); | ||
testV(false, "notEmpty", "\t\t"); | ||
testV(true, "notEmpty", "\t3\t"); | ||
test(true, "lowercase", "0drootpop"); | ||
test(false, "lowercase", "0DROOTPOP"); | ||
testV(true, "lowercase", "0drootpop"); | ||
testV(false, "lowercase", "0DROOTPOP"); | ||
test(true, "uppercase", "0DROOTPOP"); | ||
test(false, "uppercase", "0drootpop"); | ||
testV(true, "uppercase", "0DROOTPOP"); | ||
testV(false, "uppercase", "0drootpop"); | ||
test(false, "alphanumeric", 10); | ||
test(true, "alphanumeric", "0drootpop"); | ||
test(false, "alphanumeric", "0d@root.pop"); | ||
testV(false, "alphanumeric", 10); | ||
testV(true, "alphanumeric", "0drootpop"); | ||
testV(false, "alphanumeric", "0d@root.pop"); | ||
test(true, "alpha", "rootpop"); | ||
test(false, "alpha", "d@root.pop"); | ||
test(false, "alpha", "0"); | ||
test(false, "alpha", "0d@root.pop"); | ||
testV(true, "alpha", "rootpop"); | ||
testV(false, "alpha", "d@root.pop"); | ||
testV(false, "alpha", "0"); | ||
testV(false, "alpha", "0d@root.pop"); | ||
test(false, "numeric", 10); | ||
test(false, "numeric", "0drootpop"); | ||
test(false, "numeric", "0d@root.pop"); | ||
test(false, "numeric", "drootpop"); | ||
test(true, "numeric", "10"); | ||
testV(false, "numeric", 10); | ||
testV(false, "numeric", "0drootpop"); | ||
testV(false, "numeric", "0d@root.pop"); | ||
testV(false, "numeric", "drootpop"); | ||
testV(true, "numeric", "10"); | ||
test(false, "hexadecimal", "XA"); | ||
test(true, "hexadecimal", "FA"); | ||
test(true, "hexadecimal", "fA"); | ||
test(true, "hexadecimal", "fa0"); | ||
testV(false, "hexadecimal", "XA"); | ||
testV(true, "hexadecimal", "FA"); | ||
testV(true, "hexadecimal", "fA"); | ||
testV(true, "hexadecimal", "fa0"); | ||
test(true, "email", "0d@root.pop"); | ||
test(false, "email", "0d-root.pop"); | ||
test(false, "email", 10); | ||
testV(true, "email", "0d@root.pop"); | ||
testV(false, "email", "0d-root.pop"); | ||
testV(false, "email", 10); | ||
test(false, "url", ""); | ||
test(true, "url", "666.io"); | ||
test(false, "url", "httpsx://666.io"); | ||
test(false, "url", "http://666"); | ||
test(false, "url", "ht://666"); | ||
test(true, "url", "http://666.io"); | ||
test(true, "url", "ssh://666.io"); | ||
test(true, "url", "ws://666.io"); | ||
test(true, "url", "https://666.io"); | ||
test(true, "url", "ftp://666.io"); | ||
testV(false, "url", ""); | ||
testV(true, "url", "666.io"); | ||
testV(false, "url", "httpsx://666.io"); | ||
testV(false, "url", "http://666"); | ||
testV(false, "url", "ht://666"); | ||
testV(true, "url", "http://666.io"); | ||
testV(true, "url", "ssh://666.io"); | ||
testV(true, "url", "ws://666.io"); | ||
testV(true, "url", "https://666.io"); | ||
testV(true, "url", "ftp://666.io"); | ||
test(true, "mongoId", "507f191e810c19729de860ea"); | ||
test(false, "mongoId", ""); | ||
test(false, "mongoId", "507f191e810c19729de860ex"); | ||
test(false, "mongoId", "507f191e810c19729de860eax"); | ||
test(false, "mongoId", "507f191e810c19729de860e"); | ||
testV(true, "mongoId", "507f191e810c19729de860ea"); | ||
testV(false, "mongoId", ""); | ||
testV(false, "mongoId", "507f191e810c19729de860ex"); | ||
testV(false, "mongoId", "507f191e810c19729de860eax"); | ||
testV(false, "mongoId", "507f191e810c19729de860e"); | ||
test(true, "hexColor", "#FFF"); | ||
test(false, "hexColor", "#FFFF"); | ||
test(true, "hexColor", "#FFFFFF"); | ||
test(false, "hexColor", "#XFFFFF"); | ||
test(false, "hexColor", "#XFF"); | ||
testV(true, "hexColor", "#FFF"); | ||
testV(false, "hexColor", "#FFFF"); | ||
testV(true, "hexColor", "#FFFFFF"); | ||
testV(false, "hexColor", "#XFFFFF"); | ||
testV(false, "hexColor", "#XFF"); | ||
test(false, "creditcard", ""); | ||
test(true, "creditcard", "4539705911256127"); | ||
test(true, "creditcard", "5112136511738516"); | ||
test(true, "creditcard", "6011875460215667"); | ||
test(true, "creditcard", "374931102531716"); | ||
test(false, "creditcard", "453970591125612"); | ||
test(false, "creditcard", "511213651173851"); | ||
test(false, "creditcard", "601187546021566"); | ||
test(false, "creditcard", "37493110253171"); | ||
testV(false, "creditcard", ""); | ||
testV(true, "creditcard", "4539705911256127"); | ||
testV(true, "creditcard", "5112136511738516"); | ||
testV(true, "creditcard", "6011875460215667"); | ||
testV(true, "creditcard", "374931102531716"); | ||
testV(false, "creditcard", "453970591125612"); | ||
testV(false, "creditcard", "511213651173851"); | ||
testV(false, "creditcard", "601187546021566"); | ||
testV(false, "creditcard", "37493110253171"); | ||
test(false, "phone", ""); | ||
test(false, "phone", "95885"); | ||
test(true, "phone", "+7 888 788 99"); | ||
test(true, "phone", "8 888 788 99"); | ||
test(true, "phone", "888 788 99"); | ||
testV(false, "phone", ""); | ||
testV(false, "phone", "95885"); | ||
testV(true, "phone", "+7 888 788 99"); | ||
testV(true, "phone", "8 888 788 99"); | ||
testV(true, "phone", "888 788 99"); | ||
test(false, "uuid", ""); | ||
test(true, "uuid", "550e8400-e29b-41d4-a716-446655440000"); | ||
test(false, "uuid", "550e8400-e29b-41d4-a716-4466554400000"); | ||
test(false, "uuid", "550e8400-e29b-41d4-a716-446655440000x"); | ||
testV(false, "uuid", ""); | ||
testV(true, "uuid", "550e8400-e29b-41d4-a716-446655440000"); | ||
testV(false, "uuid", "550e8400-e29b-41d4-a716-4466554400000"); | ||
testV(false, "uuid", "550e8400-e29b-41d4-a716-446655440000x"); | ||
test(false, "ip", ""); | ||
test(false, "ip", "100.005.055."); | ||
test(false, "ip", "100.005.055.x"); | ||
test(false, "ip", "100.005.055.x88"); | ||
test(true, "ip", "100.005.055.88"); | ||
test(true, "ip", "3FFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); | ||
test(true, "ip", "2001:db8::7"); | ||
test(false, "ip", "2001:xb8::7"); | ||
testV(false, "ip", ""); | ||
testV(false, "ip", "100.005.055."); | ||
testV(false, "ip", "100.005.055.x"); | ||
testV(false, "ip", "100.005.055.x88"); | ||
testV(true, "ip", "100.005.055.88"); | ||
testV(true, "ip", "3FFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); | ||
testV(true, "ip", "2001:db8::7"); | ||
testV(false, "ip", "2001:xb8::7"); | ||
test(false, "ascii", ""); | ||
test(true, "ascii", "test 99"); | ||
test(false, "ascii", "тест 99"); | ||
testV(false, "ascii", ""); | ||
testV(true, "ascii", "testV 99"); | ||
testV(false, "ascii", "тест 99"); | ||
test(false, "base64", ""); | ||
test(false, "base64", "994"); | ||
test(true, "base64", "RFQ="); | ||
testV(false, "base64", ""); | ||
testV(false, "base64", "994"); | ||
testV(true, "base64", "RFQ="); | ||
} | ||
console.log("+-------------------------+"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42394
804
207