Comparing version 0.0.3 to 0.0.4
23
index.js
@@ -5,3 +5,3 @@ //----------------------------------------------------- | ||
// Site: 666.io | ||
// Version: 0.00.003 | ||
// Version: 0.00.004 | ||
// | ||
@@ -397,2 +397,9 @@ //----------------------------------------------------- | ||
case "string": | ||
if(!input) { | ||
if(typeof(options.default) === "string") | ||
input = options.default; | ||
break; | ||
} | ||
if(options.trim) | ||
@@ -407,2 +414,9 @@ input = input.trim(); | ||
case "integer": | ||
if(isNaN(input)) { | ||
if(typeof(options.default) === "number") | ||
input = parseInt(options.default, 10); | ||
break; | ||
} | ||
if(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) === -1) | ||
@@ -420,2 +434,9 @@ return NaN; | ||
case "float": | ||
if(isNaN(input)) { | ||
if(typeof(options.default) === "number") | ||
input = options.default; | ||
break; | ||
} | ||
if(typeof(options.enum) !== "undefined" && options.enum.indexOf(input) === -1) | ||
@@ -422,0 +443,0 @@ return NaN; |
{ | ||
"name": "aigis", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Simple and Powerful module for strict validation", | ||
@@ -38,4 +38,4 @@ | ||
"_id": "aigis@0.0.3", | ||
"_id": "aigis@0.0.4", | ||
"_from": "aigis@" | ||
} |
@@ -8,7 +8,7 @@ `npm install aigis -g` | ||
var schema = { | ||
"name": "string", | ||
"name": {"use": "string", "length": 2, "trim": true}, | ||
"status": "?string", | ||
"pts": {"use": "integer", "max": 30} | ||
}, | ||
data = {"name": "X", "pts": "60"}; | ||
data = {"name": " XX+ ", "pts": "60", "delThisField": "data"}; | ||
@@ -44,5 +44,5 @@ $sanitize(schema, data); | ||
| boolean | true: "true", "on", "yes", "1" | - | | ||
| string | - | length, trim | | ||
| integer | - | min, max, enum | | ||
| float | - | min, max, enum | | ||
| string | - | default, length, trim | | ||
| integer | - | default, min, max, enum | | ||
| float | - | default, min, max, enum | | ||
| date | - | - | | ||
@@ -49,0 +49,0 @@ | hashTable | - | - | |
@@ -36,3 +36,3 @@ //----------------------------------------------------- | ||
}, | ||
data = {"name": " DT+ ", "pts": "60"}; | ||
data = {"name": " DT+ ", "pts": "60", "delThisField": "data"}; | ||
@@ -39,0 +39,0 @@ console.log("1#", $sanitize(schema, data)); |
@@ -69,3 +69,4 @@ //----------------------------------------------------- | ||
console.log("|%s|> T%s ", result ? "+" : "-", count.s); | ||
if(!result) | ||
console.log("|%s|> T%s ", result ? "+" : "-", count.s); | ||
} | ||
@@ -89,3 +90,4 @@ | ||
console.log("|%s|> T%s ", result ? "+" : "-", count.v); | ||
if(!result) | ||
console.log("|%s|> T%s ", result ? "+" : "-", count.v); | ||
} | ||
@@ -104,2 +106,5 @@ | ||
testS(false, "boolean", undefined); | ||
testS(false, "boolean", null); | ||
testS(false, "boolean", NaN); | ||
testS(true, "boolean", true); | ||
@@ -114,2 +119,5 @@ testS(false, "boolean", false); | ||
testS("", "string", undefined); | ||
testS("", "string", null); | ||
testS("NaN", "string", NaN); | ||
testS("10", "string", 10); | ||
@@ -120,2 +128,5 @@ testS("10", "string", "10"); | ||
testS(NaN, "integer", undefined); | ||
testS(NaN, "integer", null); | ||
testS(NaN, "integer", NaN); | ||
testS(10, "integer", 10); | ||
@@ -126,2 +137,5 @@ testS(10, "integer", 10.5); | ||
testS(NaN, "float", undefined); | ||
testS(NaN, "float", null); | ||
testS(NaN, "float", NaN); | ||
testS(10, "float", 10); | ||
@@ -132,2 +146,5 @@ testS(10.5, "float", 10.5); | ||
testS(new Date(NaN), "date", undefined); | ||
testS(new Date(NaN), "date", null); | ||
testS(new Date(NaN), "date", NaN); | ||
testS(new Date(10), "date", 10); | ||
@@ -142,2 +159,5 @@ testS(new Date(NaN), "date", new Date(NaN)); | ||
testS({}, "hashTable", undefined); | ||
testS({}, "hashTable", null); | ||
testS({}, "hashTable", NaN); | ||
testS({'x': 1}, "hashTable", {'x': 1}); | ||
@@ -148,2 +168,5 @@ testS({}, "hashTable", "{'x': 1"); | ||
testS([], "array", undefined); | ||
testS([], "array", null); | ||
testS([], "array", NaN); | ||
testS([1,2], "array", [1,2]); | ||
@@ -155,3 +178,6 @@ testS([], "array", "[1,2"); | ||
testS(null, "json", undefined); | ||
testS(null, "json", null); | ||
testS(null, "json", NaN); | ||
testS(null, "json", null); | ||
testS({'x': 1}, "json", {'x': 1}); | ||
@@ -158,0 +184,0 @@ testS([1,2], "json", [1,2]); |
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
44019
845