1.0.0 • Published 6 years ago

validator_task v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

validator task is a library for optimize and make a order to the validations action in any siscurtance.

validator argument

{
    "validator":reqired_string|string_regexp|function: return false|true,
    "message":"show this message with the validator will be false"
 }

Examples

use validate_elem

const validator_task = require('validator_task');

let flags = [
    {
        "validator": "\\w",
        "message": "regex with validator string"
    },
    {
        "validator": /\d/,
        "message": "regex false"
    },
    {
        "validator": (params) => {
            return false
        },
        "message": "when the funtion returned false"
    },
];

console.log(validator_task.validate_elem(flags));

out

[ 'regex false', 'when the funtion returned false' ]

use validate_payload

const validator_task = require('validator_task');

let payload = {
    "some key": {
        "value": "string",
        "flags": [
            {
                "validator": "required",
                "message": "value required"
            },
            {
                "validator": /\w/,
                "message": "regex"
            },
            {
                "validator": /\d/,
                "message": "regex false"
            },
            {
                "validator": (params) => {
                    return false
                },
                "message": "when the funtion returned false"
            },
        ]
    }
};

console.log(valid.validate_payload(payload));

out

{ 'some key': [ 'regex false', 'when the funtion returned false' ] }

use validate_body

const validator_task = require('validator_task');

payload = {
    "some key": [
        {
            "validator": "required",
            "message": "value required"
        },
        {
            "validator": /\w/,
            "message": "regex"
        },
        {
            "validator": (params) => {
                return false
            },
            "message": "when the funtion returned false"
        }
    ]
};

let body = {
    "some key": "some string"
}

console.log(valid.validate_body(body, payload));

out

{ 'some key': [ 'when the funtion returned false' ] }