Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blakeembrey/nary
Force a functions arity in JavaScript
https://github.com/blakeembrey/nary
arity function typescript
Last synced: 4 days ago
JSON representation
Force a functions arity in JavaScript
- Host: GitHub
- URL: https://github.com/blakeembrey/nary
- Owner: blakeembrey
- License: other
- Created: 2014-01-22T12:48:24.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-03-15T02:44:12.000Z (almost 7 years ago)
- Last Synced: 2025-01-10T11:20:41.664Z (8 days ago)
- Topics: arity, function, typescript
- Language: TypeScript
- Size: 58.6 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nary
[![NPM version](https://img.shields.io/npm/v/nary.svg?style=flat)](https://npmjs.org/package/nary)
[![NPM downloads](https://img.shields.io/npm/dm/nary.svg?style=flat)](https://npmjs.org/package/nary)
[![Build status](https://img.shields.io/travis/blakeembrey/nary.svg?style=flat)](https://travis-ci.org/blakeembrey/nary)
[![Test coverage](https://img.shields.io/coveralls/blakeembrey/nary.svg?style=flat)](https://coveralls.io/r/blakeembrey/nary?branch=master)> Enforce function arity in JavaScript.
## Installation
```
npm install nary --save
```## Usage
```ts
import { nary, nullary, unary, binary, ternary, quaternary } from 'nary'nullary(fn).length; //=> 0
unary(fn).length; //=> 1
binary(fn).length; //=> 2
ternary(fn).length; //=> 3
quaternary(fn).length; //=> 4
nary(5, fn).length; //=> 5// This example fails because `parseInt` accepts an optional second argument as
// the radix. This can wreak havoc in unexpected situations.
[1, 2, 3, 4, 5].map(parseInt); //=> [1, NaN, NaN, NaN, NaN]// Using `unary`, the function will only accept a single argument.
[1, 2, 3, 4, 5].map(unary(parseInt)); //=> [1, 2, 3, 4, 5]
```## TypeScript
This project is written using [TypeScript](https://github.com/Microsoft/TypeScript) and publishes the definitions directly to NPM.
## License
Apache 2.0