1. util-arity
Set the length of a function.
util-arity
Package: util-arity
Created by: blakeembrey
Last modified: Tue, 28 Jun 2022 07:10:06 GMT
Version: 1.1.0
License: MIT
Downloads: 4,579,900
Repository: https://github.com/blakeembrey/arity

Install

npm install util-arity
yarn add util-arity

Arity

NPM version
NPM downloads
Build status
Test coverage

Set a functions arity (the argument count) by proxying function calls.

P.S. If you need need to enforce arity and don't care about argument length or this, use nary. It's magnitudes faster than using .apply to proxy arguments.

When would I use this?

It's unlikely you'll need to use this utility in everyday development. The reason I wrote it was for functional utilities and backward compatibility with user expectations. For example, many modules use function arity to decide how the function behaves (e.g. error middleware in express, callbacks in mocha).

Installation

npm install util-arity --save

Usage

 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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code