https://github.com/samouri/arity
a tiny library for reliably determining arity
https://github.com/samouri/arity
Last synced: about 2 months ago
JSON representation
a tiny library for reliably determining arity
- Host: GitHub
- URL: https://github.com/samouri/arity
- Owner: samouri
- Created: 2017-11-28T00:01:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-28T21:19:51.000Z (over 8 years ago)
- Last Synced: 2025-10-23T04:37:41.796Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 26.4 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
arity
=====
[](https://circleci.com/gh/samouri/arity)
> In logic, mathematics, and computer science, the arity /ˈærɪti/ of a function is the number of arguments or operands that the function takes.
Sometimes you want to be able to tell how many arguments a function takes.
99% of the time you can do something as simple as calling `fn.length` -- but this will not work if a function accesses the [arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments) object directly.
This module will even return the correct number of arguments to expect for those tricky cases.
### Install
```bash
npm install --save-dev arity
```
### To use
```javascript
const arity = require('arity');
function doSomething(arg1, arg2) { ... }
const arityOfDoSomething = arity(doSomething); // value will be 2
```