Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aigis

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aigis

Simple and Powerful module for strict validation

  • 0.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28
increased by460%
Maintainers
1
Weekly downloads
 
Created
Source

npm install aigis -g

require("aigis");

var schema  = {
        "name":     {"use": "string", "max": 2, "trim": true},
        "status":   "?string",
        "pts":      {"use": "integer", "max": 30, "abs": true}
    },
    data    = {"name": "  XX+ ", "pts": "-60", "delThisField": "data"};

$sanitize(schema, data);
$validate(schema, data);
  • Tests: +
  • Examples: +
  • Browser: +

?name - Check an input only when the input exists (not undefined).

Module
NameDescArgs
-
globalSet $sanitize, $validate as Global Var (NodeJS)(v [default: true])
typeSet/Get/Delete custom Type (Sanitize)(name, [func]) ~ func(input, options)
ruleSet/Get/Delete custom Rule (Validate)(name, [func]) ~ func(input, options)
-
sanitize-(schema (String/HashTable), data, [options])
validate-(schema (String/HashTable), data, [options])
Sanitize
NameDescVal
-
booleantrue: "true", "on", "yes", "1"-
string-default, max, trim, escape, lowercase, uppercase, onlyDigits, onlyAlphanumeric
integer-default, min, max, enum, abs
float-default, min, max, enum, abs
date--
hashTable--
array-max
json--
Validate
OptionsDescVal
-
errorsValidate method returns null or an array of errorstrue/false (def: false)
//_ Error: structure 
{
    "field":    field,
    "use":      nameFunc,

    "input":    fieldData
}
NameDescParams/Options
-
null--
nan--
finiteIf number and not: NaN, INFINITY-
-
boolean--
string-min, max, enum, pattern
integer-min, max, enum
float-min, max, enum
date--
hashTable--
array-min, max
json--
-
requiredNot: null, undefined, length==0, NaN, Invalid Date-
notEmptyIf string not empty-
lowercaseIf string is lowercase-
uppercaseIf string is uppercase-
-
alphanumericIf string is only letters and numbers-
alphaIf string is only letters-
numericIf string is only numbers-
hexadecimal--
email--
urlMailto, http, https, ftp, ssh, ws, gopher, news, telnet, ldap-
mongoId--
-
hexColor-strict (def: false)
creditcardVisa, MasterCard, American Express, Discover, Diners Club, and JCB card-
phoneru-RU, zh-CN, en-ZA, en-AU, en-HK, fr-FR, pt-PT, el-GRlocale (def: "ru-RU")
uuid-version (def: 3,4,5)
ip-version (def: 4,6)
ascii--
base64--
Browser

Include: //raw.githack.com/Daeren/Aigis/master/index.js

Global var: $aigis

Examples
require("aigis");

//-----------------------------------------------------

console.log("+-------------------------+");
console.log("| V: Custom");
console.log("+-------------------------+");

$sanitize.type("testTypeDateEasy", function(input, options) {
    return new Date(input);
});

console.log("0#", $sanitize("testTypeDateEasy", "Thu, 01 Jan 1970 00:00:00 GMT-0400"));
console.log("1#", $sanitize("testTypeDateEasy", "---"));


console.log("+-------------------------+");
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", "max": 2, "trim": true},
        "status":   "?string",
        "pts":      {"use": "integer", "max": 30}
    },
    data    = {"name": "   DT+  ", "pts": "60", "delThisField": "data"};

console.log("0#", $sanitize(schema, data));



console.log("+-------------------------+");
console.log("| V: Custom");
console.log("+-------------------------+");

$validate.rule("testRuleMax10", function(input, options) {
    return input < 10;
});

console.log("0#", $validate("testRuleMax10", 50));
console.log("1#", $validate("testRuleMax10", 8));


console.log("+-------------------------+");
console.log("| V: String");
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"),
    "T4":   $validate("?email", undefined)
}, null, "\t"));

console.log("+-------------------------+");
console.log("| V: HashTable");
console.log("+-------------------------+");

var schema  = {"name": "string", "status": "?string", "pts": "integer"},
    data    = {"name": "DT", "pts": "32"};

console.log("1#", $validate(schema, data));
console.log("2#", $validate(schema, data, {"errors": true}));


var schema  = {
        "name":     "string",
        "status":   "?string",
        "pts":      {"use": "integer", "max": 32}
    },
    data    = {"name": "DT", "pts": 32};

console.log("3#", $validate(schema, data));
3# of the fundamental modules

2# Fire-Inject

License

MIT


@ Daeren Torn

Keywords

FAQs

Package last updated on 26 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc