fast-args

1.0.0 • Public • Published

fast-args NPM version Build Status

Very fast way to turn a function's arguments into an array.

var fargs = require('fast-args');
 
function foo() {
  return fargs(arguments);
}
 
foo(1, 2, 3);
// => [1, 2, 3]

Most functions don't get called with more than 6 params, so this module uses a switch for manually making an array when arguments.length is 1 through 6. It can fall back on a fast slice for any number of params higher than 6.

Note: This module is best for ES5 and below. Use rest parameters for the fastest method (by far) in ES6+.

Installation

$ npm install --save fast-args

API

fargs(args, [offset])

Turn the arguments object of a function into an array.

  • args (arguments): The arguments object of a function.
  • offset (Number): The index to start on arguments.
var fargs = require('fast-args');
 
function foo() {
  var args = fargs(arguments, 1);
  // ...
}

This is the only export of the module.

Meta

  • npm test: Run tests.
  • npm run bench: Run benchmarks.

License

MIT © Jamen Marz

Package Sidebar

Install

npm i fast-args

Weekly Downloads

19

Version

1.0.0

License

MIT

Last publish

Collaborators

  • npm