Comparing version 0.0.23 to 0.0.24
86
index.js
@@ -5,3 +5,3 @@ //----------------------------------------------------- | ||
// Site: 666.io | ||
// Version: 0.00.023 | ||
// Version: 0.00.024 | ||
// | ||
@@ -13,3 +13,3 @@ //----------------------------------------------------- | ||
//----------------------------------------------------- | ||
//-----------------------------------------------]> | ||
@@ -20,8 +20,8 @@ var C_MODE_TYPENIZE = 1, | ||
var customTypesStore = {}, | ||
customRulesStore = {}; | ||
var gCustomTypesStore = {}, | ||
gCustomRulesStore = {}; | ||
var typenizeSchemaStore = {}, | ||
sanitizeSchemaStore = {}, | ||
validateSchemaStore = {}; | ||
var gTypenizeSchemaStore = {}, | ||
gSanitizeSchemaStore = {}, | ||
gValidateSchemaStore = {}; | ||
@@ -101,3 +101,3 @@ var gVPhones = { | ||
"type": function(name, func) { | ||
wFuncStore(name, func, customTypesStore); | ||
wFuncStore(name, func, gCustomTypesStore); | ||
return this; | ||
@@ -107,3 +107,3 @@ }, | ||
"rule": function(name, func) { | ||
wFuncStore(name, func, customRulesStore); | ||
wFuncStore(name, func, gCustomRulesStore); | ||
return this; | ||
@@ -115,7 +115,9 @@ }, | ||
"typenize": function(schema, data, options) { | ||
return runSchema(C_MODE_TYPENIZE, schema, data, options, $typenize, $typenizeHashTable); | ||
return arguments.length === 1 ? | ||
createModel(schema, gExport.typenize) : runSchema(C_MODE_TYPENIZE, schema, data, options, $typenize, $typenizeHashTable); | ||
}, | ||
"sanitize": function(schema, data, options) { | ||
return runSchema(C_MODE_SANITIZE, schema, data, options, $sanitizeString, $sanitizeHashTable); | ||
return arguments.length === 1 ? | ||
createModel(schema, gExport.sanitize) : runSchema(C_MODE_SANITIZE, schema, data, options, $sanitizeString, $sanitizeHashTable); | ||
}, | ||
@@ -128,9 +130,9 @@ | ||
//---------[Storage]----------}> | ||
//---------[Storage]---------}> | ||
["set", "get", "run"] | ||
.forEach(function(name) { | ||
gExport.typenize[name] = buildFunc(gExport.typenize, typenizeSchemaStore); | ||
gExport.sanitize[name] = buildFunc(gExport.sanitize, sanitizeSchemaStore); | ||
gExport.validate[name] = buildFunc(gExport.validate, validateSchemaStore); | ||
gExport.typenize[name] = buildFunc(gExport.typenize, gTypenizeSchemaStore); | ||
gExport.sanitize[name] = buildFunc(gExport.sanitize, gSanitizeSchemaStore); | ||
gExport.validate[name] = buildFunc(gExport.validate, gValidateSchemaStore); | ||
@@ -162,3 +164,3 @@ function buildFunc(obj, store) { | ||
//-----------------------------]> | ||
//-----------------------------------------------]> | ||
@@ -489,3 +491,3 @@ function $typenizeHashTable(schema, data, options) { | ||
default: | ||
var func = customTypesStore[type]; | ||
var func = gCustomTypesStore[type]; | ||
@@ -877,3 +879,3 @@ if(func) | ||
default: | ||
var func = customRulesStore[use]; | ||
var func = gCustomRulesStore[use]; | ||
@@ -887,4 +889,52 @@ if(func) | ||
function $format(data, str, fnc) { | ||
if(data === null) | ||
return str; | ||
var d; | ||
//------[Array]------}> | ||
if(Array.isArray(data)) { | ||
for(var i = 0, len = data.length; i < len; i++) { | ||
str = str.replace("{" + i + "}", data[i]); | ||
} | ||
return str; | ||
} | ||
//------[~]------}> | ||
switch(typeof(data)) { | ||
case "undefined": | ||
return str; | ||
case "object": | ||
for(var field in data) { | ||
if(!Object.prototype.hasOwnProperty.call(data, field)) continue; | ||
d = data[field]; | ||
str = fnc ? fnc(field, d, str) : str.replace("{" + field + "}", d); | ||
} | ||
return str; | ||
} | ||
return str.replace("{}", data); | ||
} | ||
//-------[HELPERS]-------}> | ||
function createModel(schema, func) { | ||
var result = function(data, options) { | ||
return func(schema, data, options); | ||
}; | ||
result.format = function(str, data, options) { | ||
return $format(func(schema, data, options), str); | ||
}; | ||
return result; | ||
} | ||
function runSchema(mode, schema, data, options, cbString, cbHashTable) { | ||
@@ -891,0 +941,0 @@ if(!schema) |
{ | ||
"name": "aigis", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"description": "Simple and Powerful module for strict data control", | ||
@@ -13,2 +13,3 @@ | ||
"data", | ||
"format", | ||
"fundamental", | ||
@@ -41,4 +42,4 @@ "justdoit" | ||
"_id": "aigis@0.0.23", | ||
"_id": "aigis@0.0.24", | ||
"_from": "aigis@" | ||
} |
@@ -7,2 +7,9 @@ `npm install aigis -g` | ||
//----------------------------- | ||
$typenize("hashTable").format("INFO | {video}: {views}", '{"video": "cats", "views": 100500}'); | ||
$typenize("string").format("Date: {}", new Date()); | ||
$sanitize("array").format("Array: {2}, {1}, {0}", "[11, 12, 13]", {"max": 2}) | ||
$typenize({name: "string"}, {name: 13, skipThisField: "data"}); | ||
@@ -22,2 +29,18 @@ $sanitize({name: {type: "string", max: 2}}, {name: "Omnomnus", delThisField: "data"}); | ||
$validate("testRuleMax10", 50, {k: 2}); | ||
//---------]> | ||
var schUser = {"name": "string", "score": "integer"}; | ||
var tpzUser = $typenize(schUser), | ||
snzUser = $sanitize(schUser); | ||
var data = {"name": "DT", "score": 13.7, "someData": 9}; | ||
tpzUser(data); | ||
tpzUser.format("My name: {name};\nMy score: {score};", data); | ||
snzUser(data); | ||
snzUser.format("My name: {name};\nMy score: {score};", data); | ||
``` | ||
@@ -47,4 +70,4 @@ | ||
| | - || | ||
| typenize | - | (schema (String/HashTable), data, [options]) | | ||
| sanitize | - | (schema (String/HashTable), data, [options]) | | ||
| typenize | - | (schema (String/HashTable), [data], [options]) | | ||
| sanitize | - | (schema (String/HashTable), [data], [options]) | | ||
| validate | - | (schema (String/HashTable), data, [options]) | | ||
@@ -51,0 +74,0 @@ |
@@ -16,2 +16,58 @@ //----------------------------------------------------- | ||
var schUser = {"name": "string", "score": "integer"}; | ||
var tpzUser = $typenize(schUser), | ||
snzUser = $sanitize(schUser); | ||
var data = {"name": "DT", "score": 13.7, "someData": 999}; | ||
console.log( | ||
tpzUser(data) | ||
); | ||
console.log( | ||
tpzUser.format("My name: {name};\nMy score: {score};", data) | ||
); | ||
console.log("\n"); | ||
console.log( | ||
snzUser(data) | ||
); | ||
console.log( | ||
snzUser.format("My name: {name};\nMy score: {score};", data) | ||
); | ||
console.log("\n"); | ||
console.log( | ||
$typenize("hashTable").format("INFO | {video}: {views}", '{"video": "cats", "views": 100500}') | ||
); | ||
console.log( | ||
$sanitize("array").format("Array: {2}, {1}, {0}", "[11, 12, 13]", {"max": 2}) | ||
); | ||
console.log( | ||
$typenize("string").format("Date: {}", new Date()) | ||
); | ||
return; // <--------------- ! | ||
console.log( | ||
$typenize.format({"name": "DT", "score": 12.2}, "My name: {name};\nMy score: {score};") | ||
); | ||
console.log( | ||
$typenize.format("My name: {0};\nMy score: {1};", "DT", 11.1) | ||
); | ||
return; // <--------------- ! | ||
//----------------------------------------------------- | ||
var data = { | ||
@@ -53,3 +109,2 @@ "data": [2.2, "name", "[skip/del]ThisElem"] | ||
var schema = { | ||
@@ -56,0 +111,0 @@ "data": { |
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
73339
1470
314