Skip to content

Looks for a valid value in an object, iterating over a priority ordered array of keys.

License

Notifications You must be signed in to change notification settings

nahuef/property-waterfall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub package.json version GitHub code size in bytes dependencies

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.

About

Looks for a valid value in an object, iterating over a priority ordered array of keys.

Resources

License

Stars

Watchers

Forks

Packages

No packages published