argsmap

0.1.3 • Public • Published

argsmap

Build Status Code Coverage

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.

Licence

MIT

Readme

Keywords

Package Sidebar

Install

npm i argsmap

Weekly Downloads

2

Version

0.1.3

License

MIT

Last publish

Collaborators

  • andy-shea