property-waterfall
v1.0.0
Published
Looks for a valid value in an object, iterating over a priority ordered array of keys.
Downloads
2
Maintainers
Readme
property-waterfall
Looks for a valid value in an object, iterating over a priority ordered array of keys.
Installation
npm i --save property-waterfall
Usage
const propertyWaterfall = require('property-waterfall')
// Look for IP in the following keys, in order.
const order = ['ip', 'x-forwarded-for', 'x-real-ip']
// IP could be in any of this objects, containing `order` keys.
const object = {
...req.headers,
...req.query
}
const ip = propertyWaterfall(object, order)
// If object['ip'] has a valid value, it will be returned,
// else look for object['x-forwarded-for'],
// else object['x-real-ip'].
// According to order array priorities.