# compare-at

> construct a compare function given an array of paths into a js object.

Latest version **1.1.2** (published 2018-11-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install compare-at
pnpm add compare-at
yarn add compare-at
bun add compare-at
```

## 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 | 1.1.2 |
| Published | 2018-11-26 |
| First published | 2018-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 20.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Dominic Tarr |
| Maintainers | dominictarr |

## Links

- npm: https://www.npmjs.com/package/compare-at
- Repository: https://github.com/dominictarr/compare-at
- Issues: https://github.com/dominictarr/compare-at/issues
- npm.io page: https://npm.io/package/compare-at

## Dependencies (2)

- [libnested](https://npm.io/package/libnested.md) ^1.4.1
- [typewiselite](https://npm.io/package/typewiselite.md) ^1.0.0

## Recent versions

- 1.1.2 (latest) — 2018-11-26
- 1.1.0 — 2018-11-22
- 1.0.0 — 2018-11-08

## README

# compare-at

construct a compare function given an array of paths into a js object.

```
var CompareAt = require('compare-at')

var compare = CompareAt([["x"], ["y"]])
var has = CompareAt.hasPath([["x"],["y"])
//outputs the same as
function compareXY (a, b) {
  return (
    a.x > b.x ? 1
  : a.x < b.x ? -1
  : a.y > b.y ? 1
  : a.y < b.y ? -1
  :             0
  )
}

compare({x:0, y:2}, {x:1,y:1}) //returns -1 because a.x < b.x
compare({x:1, y:2}, {x:1,y:1}) //returns 1 because a.y < b.y and a.x == b.x
has({x:0, y:1}) //returns true, because input has x,y
has({x:0, z:1}) //returns false, because input is missing y.

```

## api

### CompareAt(paths, cmp)

return a `function(a, b)` that compares the value at the end of each
path in `a` and `b` using `cmp`.

### CompareAt.hasPath (paths)

returns a function that returns true if it's argument has defined values the `paths` provided.

## License

MIT

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