guess-function-max-arity

Guess the maximum number of arguments the given function will consume.

Usage no npm install needed!

<script type="module">
  import guessFunctionMaxArity from 'https://cdn.skypack.dev/guess-function-max-arity';
</script>

README

guess-function-max-arity

Node.js CI

SEnD HelP

About

Guess the maximum number of arguments the given function will consume.

Determines, with a small amount of analysis, whether the function is variadic. Suspected variadic functions will produce Infinity.

Intended use case: sane defaults for optimization flags in developer-oriented tooling.

Please don't use this in your production code.

Install

$ npm i guess-function-max-arity

Usage

import { guessMaxArity } from 'guess-function-max-arity';

guessArity(() => {}); // 0
guessArity((...args) => args); // Infinity
guessArity(function () {
  return arguments;
}); // Infinity

guessArity({
  async *async() {
    return 'arguments';
  },
}); // 0

guessArity(
  () =>
    function () {
      return arguments;
    }
); // 0

guessArity(function (arguments) {
  return arguments;
}); // 1