1.0.2 • Published 2 years ago

is-options v1.0.2

Weekly downloads
1,043
License
MIT
Repository
github
Last release
2 years ago

is-options

Easily check if input is an options map

npm install is-options

Build Status

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