property-handlers

Utility for mapping object properties to handler functions

property-handlers

Installation

npm install property-handlers --save

Usage

var propertyHandlers = require('property-handlers');
propertyHandlers(object, handlers, path);
  • object: An object with properties
  • handlers: An object with properties that correspond to allowed properties. The value of each property should be a handler function
  • path: Used for error reporting
var object = {
    foo: 'foo',
    bar: 'bar'
};
 
propertyHandlers(
    object,
    {
        foofunction(value) {
            // value === 'foo' 
        },
 
        barfunction(value) {
            // bar === 'bar' 
        }
    },
    'some path');