Comparing version 0.0.1 to 0.0.2
83
index.js
@@ -5,7 +5,7 @@ //----------------------------------------------------- | ||
// Site: 666.io | ||
// Version: 0.00.001 | ||
// Version: 0.00.002 | ||
// | ||
//----------------------------------------------------- | ||
var $validate = (function createInstance() { | ||
var $aigis = (function createInstance() { | ||
"use strict"; | ||
@@ -111,34 +111,16 @@ | ||
if(typeof(input) !== "string") | ||
return false; | ||
try { | ||
input = JSON.parse(input); | ||
return !!(input && typeof(input) === "object" && !Array.isArray(input)); | ||
} catch(e) { | ||
return false; | ||
} | ||
return false; | ||
}, | ||
"array": function(input, options) { | ||
if(Array.isArray(input)) | ||
return true; | ||
if(!input || typeof(input) !== "string") | ||
if(!Array.isArray(input)) | ||
return false; | ||
try { | ||
input = JSON.parse(input); | ||
options = options || {}; | ||
options = options || {}; | ||
if( | ||
(!Array.isArray(input)) || | ||
(typeof(options.min) !== "undefined" && input.length < options.min) || | ||
(typeof(options.max) !== "undefined" && input.length > options.max) | ||
) | ||
return false; | ||
} catch(e) { | ||
if( | ||
(typeof(options.min) !== "undefined" && input.length < options.min) || | ||
(typeof(options.max) !== "undefined" && input.length > options.max) | ||
) | ||
return false; | ||
} | ||
@@ -149,10 +131,4 @@ return true; | ||
"json": function(input) { | ||
if(typeof(input) === "object") | ||
return true; | ||
try { | ||
JSON.parse(input); | ||
} catch(e) { | ||
if(typeof(input) !== "object") | ||
return false; | ||
} | ||
@@ -221,4 +197,8 @@ return true; | ||
"hexColor": function(input, options) { | ||
if(typeof(input) !== "string") | ||
return false; | ||
options = options || {}; | ||
return typeof(input) === "string" && !!input.match(options.strict ? /^#[0-9A-F]{6}$/i : /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i); | ||
return !!input.match(options.strict ? /^#[0-9A-F]{6}$/i : /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i); | ||
}, | ||
@@ -331,2 +311,11 @@ | ||
//-------[HELPERS]-------}> | ||
function wFuncStore(name, func, store) { | ||
if(func === null) delete store[name]; | ||
else if(typeof(func) == "function") store[name] = func; | ||
else return store[name]; | ||
} | ||
//-----------------------------]> | ||
@@ -340,3 +329,9 @@ | ||
if(v) { | ||
global.$validate = result.validate; | ||
var gObj = result.validate; | ||
for(var i in result) { | ||
if(result.hasOwnProperty(i)) gObj[i] = result[i]; | ||
} | ||
global.$validate = gObj; | ||
} else | ||
@@ -348,2 +343,6 @@ delete global.$validate; | ||
"rule": function(name, func) { | ||
return wFuncStore(name, func, gVMethods); | ||
}, | ||
//--------]> | ||
@@ -471,10 +470,2 @@ | ||
{ | ||
var obj = result.validate; | ||
for(var i in gVMethods) { | ||
if(gVMethods.hasOwnProperty(i)) obj[i] = gVMethods[i]; | ||
} | ||
} | ||
return result; | ||
@@ -486,6 +477,6 @@ })(); | ||
if(typeof(module) == "object") { | ||
module.exports = $validate; | ||
module.exports = $aigis; | ||
if(typeof(global) == "object") | ||
$validate.global(true); | ||
$aigis.global(true); | ||
} |
{ | ||
"name": "aigis", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Simple and Powerful module for strict validation", | ||
@@ -38,4 +38,4 @@ | ||
"_id": "aigis@0.0.1", | ||
"_id": "aigis@0.0.2", | ||
"_from": "aigis@" | ||
} |
@@ -14,3 +14,3 @@ `npm install aigis -g` | ||
$validate(schema, data); | ||
$aigis(schema, data); | ||
``` | ||
@@ -22,5 +22,5 @@ | ||
`?name` - Check an input only when the input exists (not `undefined`). | ||
`?name` - Check an input only when the input exists (not undefined). | ||
#### Module (NodeJS) | ||
#### Module | ||
@@ -30,6 +30,9 @@ | Name | Desc | Args | | ||
| | - || | ||
| global | Set `$validate` as Global Var | (v [default: true]) | | ||
| global | Set `$validate` as Global Var (NodeJS) | (v [default: true]) | | ||
| rule | Add/Remove/Get custom Rule | (name, [func]) ~ func(input, options) | | ||
| | - || | ||
| validate | - | (schema (String/Array/HashTable), data, [options]) | | ||
#### Validate | ||
@@ -42,2 +45,3 @@ | ||
```js | ||
@@ -96,3 +100,3 @@ //_ Error: structure | ||
Global var: `$validate` | ||
Global var: `$aigis` | ||
@@ -108,12 +112,13 @@ | ||
console.log("+-------------------------+"); | ||
console.log("| Function"); | ||
console.log("| Custom"); | ||
console.log("+-------------------------+"); | ||
console.log(JSON.stringify({ | ||
"T0": $validate.string(10), | ||
"T1": $validate.integer("10"), | ||
"T2": $validate.email("0d@root.pop"), | ||
"T3": $validate.email("0d-root.pop") | ||
}, null, "\t")); | ||
$validate.rule("testRuleMax10", function(input, options) { | ||
return input < 10; | ||
}); | ||
console.log("1#", $validate("testRuleMax10", 50)); | ||
console.log("1#", $validate("testRuleMax10", 8)); | ||
console.log("+-------------------------+"); | ||
@@ -120,0 +125,0 @@ console.log("| String"); |
@@ -17,12 +17,13 @@ //----------------------------------------------------- | ||
console.log("+-------------------------+"); | ||
console.log("| Function"); | ||
console.log("| Custom"); | ||
console.log("+-------------------------+"); | ||
console.log(JSON.stringify({ | ||
"T0": $validate.string(10), | ||
"T1": $validate.integer("10"), | ||
"T2": $validate.email("0d@root.pop"), | ||
"T3": $validate.email("0d-root.pop") | ||
}, null, "\t")); | ||
$validate.rule("testRuleMax10", function(input, options) { | ||
return input < 10; | ||
}); | ||
console.log("1#", $validate("testRuleMax10", 50)); | ||
console.log("1#", $validate("testRuleMax10", 8)); | ||
console.log("+-------------------------+"); | ||
@@ -29,0 +30,0 @@ console.log("| String"); |
@@ -26,6 +26,7 @@ //----------------------------------------------------- | ||
try { | ||
rA.deepEqual($validate.apply(null, args), exp, args); | ||
rA.deepEqual($validate.apply(null, args), exp); | ||
} catch(e) { | ||
result = false; | ||
console.log(args); | ||
console.log(e); | ||
@@ -103,20 +104,20 @@ console.log("\n"); | ||
test(false, "hashTable", "[1,2]"); | ||
test(true, "hashTable", JSON.stringify({'x': 1})); | ||
test(false, "hashTable", JSON.stringify({'x': 1})); | ||
test(true, "array", [1,2]); | ||
test(false, "array", "[1,2"); | ||
test(true, "array", "[1,2]"); | ||
test(true, "array", [1,2]); | ||
test(false, "array", "[1,2]"); | ||
test(false, "array", {x:1}); | ||
test(false, "array", "{'x': 1}"); | ||
test(true, "json", null); | ||
test(true, "json", {'x': 1}); | ||
test(true, "json", [1,2]); | ||
test(false, "json", undefined); | ||
test(true, "json", null); | ||
test(false, "json", NaN); | ||
test(false, "json", "{'x': 1"); | ||
test(false, "json", "{'x': 1}"); | ||
test(true, "json", JSON.stringify({'x': 1})); | ||
test(true, "json", "[1,2]"); | ||
test(false, "json", JSON.stringify({'x': 1})); | ||
test(false, "json", "[1,2]"); | ||
test(false, "json", "[1,2"); | ||
test(true, "hashTable", {'x': 1}); | ||
test(true, "array", [1,2]); | ||
@@ -123,0 +124,0 @@ test(false, "required", ""); |
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
177
32126
571