# fairmont-multimethods

> Multi-argument dispatch for JavaScript functions

Latest version **2.0.2** (published 2017-12-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install fairmont-multimethods
pnpm add fairmont-multimethods
yarn add fairmont-multimethods
bun add fairmont-multimethods
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2017-12-10 |
| First published | 2015-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 49 |
| Maintainers | dyoder, f1337, pandanick, pandastrike |

## Links

- npm: https://www.npmjs.com/package/fairmont-multimethods
- Repository: https://github.com/dyoder/fairmont
- Homepage: https://github.com/dyoder/fairmont#readme
- Issues: https://github.com/dyoder/fairmont/issues
- npm.io page: https://npm.io/package/fairmont-multimethods

## Recent versions

- 2.0.2 (latest) — 2017-12-10
- 2.0.1 — 2017-12-10
- 2.0.0 — 2017-12-10
- 1.0.1 — 2016-04-15
- 1.0.0 — 2016-04-15
- 1.0.0-beta-21 — 2015-10-09
- 1.0.0-beta-20 — 2015-10-05
- 1.0.0-beta-19 — 2015-08-10
- 1.0.0-beta-18 — 2015-07-20

## README

# Fairmont-Multimethods

Fairmont-Multimethods is a JavaScript library providing support for multimethods in JavaScript.

## Installation

`npm i -S fairmont-multimethods`

## Usage

```coffee

equal = Method.create
  description: "'Deep' equality operator"
  default: (a, b) -> a == b # fallback to shallow equality

# when comparing objects, recursively check the values
# corresponding to the union of their properties—
# return false on the first inequality
Method.define equal, isObject, isObject, (a, b) ->
  (a == b) || do ->
    keys = new Set (Object.keys a)..., (Object.keys b)...
    for key from keys
      if ! equal a[key], b[key]
        return false
    true

# when comparing arrays, recursively check values
# after making sure they're the same length
# return false on the first inequality
Method.define equal, isArray, isArray, (ax, bx) ->
  (ax == bx) || do ->
    return false if ax.length != bx.length
    for i in [0..ax.length]
      if !equal ax[i], bx[i]
        return false
    true

equal "this", "this"  # => true, shallow equality works here
equal { x: 1, y: 2 }, { x: 1, y: 2 } # => true, deep equality
equal [1..5], [1..5] # true, deep equality
equal { x: 1, y: 2}, [1..5] # false
```

[API documentation](https://github.com/pandastrike/fairmont/wiki/API-Reference#method).

---
_Source: https://npm.io/package/fairmont-multimethods · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
