is-options

Easily check if input is an options map

MIT License

Downloads
24.4K
Stars
13
Committers
3

is-options

Easily check if input is an options map

npm install is-options

Usage

var isOptions = require('is-options')

thing('', {foo: true}) // key='', opts={foo: true}
thing({foo: true}) // key=undefined, opts={foo: true}
thing(Buffer.from('buf'), {foo: true}) // key=Buffer('buf'), opts={foo: true}

function thing (optionalKey, opts) {
  if (isOptions(optionalKey)) {
    opts = optionalKey
    optionalKey = undefined
  }

  console.log('key', optionalKey)
  console.log('options', opts)
}

API

bool = isOptions(obj)

Returns true is obj is an object and not a buffer

License

MIT

Package Rankings
Top 34.05% on Repo1.maven.org
Top 3.7% on Npmjs.org
Badges
Extracted from project README
Build Status