argsmap
v0.1.3
Published
Map function arguments to their parameter names
Downloads
3
Readme
argsmap
A small helper to map function arguments to their parameter names
Install
yarn add argsmap
Example
import argsMap from 'argsmap';
function basic(foo, bar) {
const map = argsMap(basic, arguments);
console.log(map);
// {
// foo: 'hello',
// bar: 'world'
// }
}
basic('hello', 'world');
Limitations
There is no support for default parameters. This library uses simple, naive regex parsing to extract parameter information which will break when provided with defaults. An implementation using Acorn to tokenize the function before parameter extraction would provide a more robust implementation at the expense of performance.