Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blakeembrey/arity
Set the length of a function in JavaScript
https://github.com/blakeembrey/arity
Last synced: about 2 months ago
JSON representation
Set the length of a function in JavaScript
- Host: GitHub
- URL: https://github.com/blakeembrey/arity
- Owner: blakeembrey
- License: mit
- Created: 2014-01-23T11:36:44.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-12-12T07:10:55.000Z (9 months ago)
- Last Synced: 2024-07-26T17:55:20.587Z (about 2 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 18
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# Arity
[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]> Set a functions arity (the argument count) by proxying function calls.
**P.S.** If you don't care about `this` and want to receive the exact arity of function arguments, use [`nary`](https://github.com/blakeembrey/nary). It uses function invocation (faster!) over `.apply` to proxy arguments.
## Why would I use this?
You probably won't. The reason it needs to exist is for functional utilities and backward compatibility with user expectations. Many modules use function arity to decide how the function should behave (e.g. middleware in `express` or callbacks in `mocha`).
## Installation
```
npm install util-arity --save
```## Usage
```javascript
var fn = function () {};
var arity = require('util-arity');var oneArg = arity(1, fn);
var twoArgs = arity(2, fn);
var threeArgs = arity(3, fn);oneArgs.length; //=> 1
twoArgs.length; //=> 2
threeArgs.length; //=> 3
```## TypeScript
The typings for this project are available for node module resolution with TypeScript.
## License
MIT
[npm-image]: https://img.shields.io/npm/v/util-arity.svg?style=flat
[npm-url]: https://npmjs.org/package/util-arity
[downloads-image]: https://img.shields.io/npm/dm/util-arity.svg?style=flat
[downloads-url]: https://npmjs.org/package/util-arity
[travis-image]: https://img.shields.io/travis/blakeembrey/arity.svg?style=flat
[travis-url]: https://travis-ci.org/blakeembrey/arity
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/arity.svg?style=flat
[coveralls-url]: https://coveralls.io/r/blakeembrey/arity?branch=master