boptions

0.6.0 • Public • Published

Status

This module is under development. Check back later.

Example

MyFunc.options = boptions( {
  '#inline': [ 'hostname', 'port' ],
  'hostname': '127.0.0.1',
  'port': {
    'type': 'int',
    'min': 1024,
    'max': 65535,
    'value': 31337
  },
  'encoding': 'ascii'
})

function MyFunc () {
  const options = MyFunc.options( arguments )
  // options now contains safe, validated options!
}

deepEqual( )
  MyFunc.options(),
  { hostname: '127.0.0.1', port: 31337, encoding: 'ascii' }
)

deepEqual(
  MyFunc.options( 'example.com', 2222 ),
  { hostname: 'example.com', port: 2222, encoding: 'ascii' }
)

deepEqual(
  MyFunc.options( { hostname: '10.10.10.10' }, { encoding: 'utf8' } ),
  { hostname: '10.10.10.10', port: 2222, encoding: 'utf8' }
)

MyFunc.options( 0 )
// throws ArgumentError -> 'Option port must be in range 1024-65535'

Performance

boptions is designed to be flexible, easy to use and thorough. Unfortunately, this comes at the cost of speed. I would NOT recommend using it for functions that are being called frequently.

/boptions/

    Package Sidebar

    Install

    npm i boptions

    Weekly Downloads

    0

    Version

    0.6.0

    License

    ISC

    Unpacked Size

    16.9 kB

    Total Files

    22

    Last publish

    Collaborators

    • koopero