1.0.4 • Published 6 years ago

node-def v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

#node-def

Keyword functions in node

Simple wrapper to allow functions to accept mixes of positonal and keyword argments.

Features

  • Keywoard Arguments
  • Argument Defaults
  • Positonal Arguments

Installation

npm install node-def

Usage

const def = require('node-def');
const foo = def('a1', 'a2', {o:false, server:null, timeout: 1000}, function(args){
    console.log(args)
})

foo({a1: 'yeah', server:'github'})
{  
   a1:'yeah',
   a2:undefined,
   o:false,
   server:'github',
   timeout:1000
}

Usage

ArgumentDetails
Postional ArgumentsPositonal arguments can be passeed before your keyword definition.
Keyword DefinitionsThe keyword argument object definnes the keywords and also set a defualt value for any unset arguments.
FunctionYou function to be called with the args object
OptionsCustomize the def behavior and output

Options

compact: Boolean Default: false

Usage: removes empty and negative values from the arguments objects.

strict: Boolean Default: false

Usage: only return keys that were defined in the def creation.

Methods

compact: func.compact(a,b,c)

Usage: removes empty and negative values from the arguments objects.

strict: func.strict({unknown:true})

Usage: only return keys that were defined in the def creation.

modifier: func.modifier(strict|compact|func)

Usage: modifiers can be passes along with the function arguments.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago