omv

object-map-validator

Object Map Validator

Showing:

Popularity

Downloads/wk

6

GitHub Stars

0

Maintenance

Last Commit

4yrs ago

Contributors

1

Package

Dependencies

1

Size (min+gzip)

0.5KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Object Map Validator

Build Status

This object-map validator supports validating event.body against a list of expected parameters, and return default values for required fields if they are missing from the request. Under the hood it use validator module.

Installation

npm install object-map-validator

Usage

let objectMapValidator = require('object-map-validator')
let validator = require('validator')

let resp = objectMapValidator.evaluateParameters(
    {
        'id': '100', 'username': 'johndoe'
    }, [{
        name: 'id',
        mappedName: 'customerNo',
        required: true,
        validator: validator.isInt
    },
    {
        name: 'username',
        mappedName: 'customerName',
        required: true,
        validator: validator.isAlpha,
    },
    {
        name: 'phone',
        mappedName: 'phoneNo',
        required: true,
        default: '0441122334'
    }
])

// resp = { 
//     error: '',
//     object: { 
//         customerNo: '100',
//         customerName: 'johndoe',
//         phoneNo: '0441122334' 
//     },
//     string: 'customerNo=100&customerName=johndoe&phoneNo=0441122334' 
// }

Validation with options

let objectMapValidator = require('object-map-validator')
let validator = require('validator')

let resp = objectMapValidator.evaluateParameters(
    {
        'age': 17
    }, [{
        name: 'age',
        mappedName: 'iAge',
        required: true,
        validator: validator.isInt
        options: {min: 18}
    }
])

// resp = { 
//   error: 'Parameter age failed validation. Expected validator: isInt with options: {"min":18}',
//   object: {},
//   string: '' 
// }

Development

Test

npm test

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial