Magic Params
🐇 magically pass function parameters in any order
Magic-Params is a small Node modules that lets you re-order of the params in your functions, without chaging their value. Magic-Params was designed to support a simplified plugin architecure.
For example: the following function...
const fn = {}
... will work exactly the same if you re-order the arguments:
const fn = {}
Just pass your params object and function to Magic-Params:
const magicParams = const fn = { return a + b} const params = a: 2 b: 2 const result = magicParms// Result = 4
Passing Arguments
const magicParams = const params = a: 'Hello,' b: ' world!' // You can switch the order of the arguments const display1 = a b console const display2 = b a console // The values stay mapped to param names magicParams// 'Hello, world!' magicParams// 'Hello, world!'
Passing Context
You can pass context with magic params by using the magicParams.apply()
method:
const magicParams = const params = a: 'Hello,' const context = b: ' world!' // The context is available on `this` const display = { console} magicParams// 'Hello, world!'
Listing Params
You can also list params with the magicParams.list()
method:
const magicParams = const display = { ...} magicParams// Returns array: ['a', 'b']
Installation
yarn add magic-params
Testing
yarn test
Credits
Thanks to Ben Iconator and Anbileru Adaleru from NounProject for the rabbit and magic wand vectors used in the magic params logo.