0.1.0 • Published 5 years ago
mergeopt-mustpop-decorator-pmb v0.1.0
mergeopt-mustpop-decorator-pmb
Wrap a function to modify its options object argument to be merged with default options and wrapped in an objPop instance with type checking.
API
This module exports one function:
decorate(origFunc, dfOpt, metaOpt)
Returns the wrapper function, based on your function origFunc
and default options dfOpt.
metaOpt is an optional options object that supports these keys:
optArgIdx: Which argument toorigFuncwill be the options object. Defaults to0, i.e. first argument.mergeOpt: The options merging function to be used. If false-y, the default (merge-options) will be used.validate: The validator function to be used. If false-y, the default (typechecks-pmb/must-be) will be used.leftoversMsg: Error message in case some keys from the (copy of the) options object have not been popped. Set tofalseto skip this check. Defaults to something like'Unsupported leftover option(s)'.popOpt: Custom options to pass along toobjpop.promising: Boolean, whetherorigFuncis expected to return a Promise or then-able. Can also be (and defaults to)null, in which case the function result is treated as a promise if it has a.thenmethod. This determines whether the
Usage
:TODO:
Known issues
- Needs more/better tests and docs.
License
ISC
0.1.0
5 years ago