# reed-richards

> Utilities for metrics processing

Latest version **2.1.3** (published 2020-10-10) · (Apache-2.0 AND MIT) license · 0 weekly downloads

## Install

```sh
npm install reed-richards
pnpm add reed-richards
yarn add reed-richards
bun add reed-richards
```

## 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.1.3 |
| Published | 2020-10-10 |
| First published | 2019-02-19 |
| Weekly downloads | 0 |
| License | (Apache-2.0 AND MIT) |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mikeal Rogers |
| Maintainers | mikeal |

## Links

- npm: https://www.npmjs.com/package/reed-richards
- npm.io page: https://npm.io/package/reed-richards

## Recent versions

- 2.1.3 (latest) — 2020-10-10
- 2.1.2 — 2020-08-18
- 2.1.1 — 2020-06-16
- 2.1.0 — 2019-10-06
- 2.0.4 — 2019-10-06
- 2.0.3 — 2019-10-05
- 2.0.2 — 2019-08-14
- 2.0.1 — 2019-03-15
- 2.0.0 — 2019-03-13
- 1.4.0 — 2019-02-25
- 1.3.2 — 2019-02-20
- 1.3.1 — 2019-02-20
- 1.3.0 — 2019-02-20
- 1.2.0 — 2019-02-19
- 1.1.0 — 2019-02-19
- … 2 more at https://npm.io/package/reed-richards/versions

## README

# Counters

You initialize a counter with the ordered column keys of your data.

If you try to count data that is missing any of these values the counter
will throw.

## counter(...columns)

Function accepts a order list of column names. If you attempt
to `set()` a row w/o one of the required columns it will throw.

```javascript
const { collection, counter, quarter } = require('./')

const c = counter('first', 'second', 'third')
const data = { first: 'one', second: 'two', third: 3 }
c.count(data)
const rows = Array.from(c.rows())
rows === [['one', 'two', 3, 1]])
```

### counter.rows()

Returns a generator that yields an array for every line
in the counter.

```javascript
const c = counter('first', 'second', 'third')
const data = { first: 'one', second: 'two', third: 3 }
c.count(data)
c.count(data)
c.count(data)
data.second = 'test'
c.count(data)
const row = Array.from(c.rows())
row === [['one', 'two', 3, 3], ['one', 'test', 3, 1]])
```

### counter.unique()

Returns a generator of objects the gives the counts of
unique keys rather than the counter values.

```javascript
const c = counter('first', 'second', 'third')
const data = { first: 'one', second: 'two', third: 3 }
c.count(data)
c.count(data)
data.third = 'test'
c.count(data)
data.second = 'foo'
c.count(data)
const row = Array.from(c.unique())
row === [
  { first: 'one', second: 'two', third: 2 },
  { first: 'one', second: 'foo', third: 1 }
]
```

### counter.objects()

A generator that yields objects for every row in
the counter.

```javascript
const c = counter('first', 'second', 'third')
const data = { first: 'one', second: 'two', third: 3 }
c.count(data)
c.count(data)
data.third = 'test'
c.count(data)
data.second = 'foo'
c.count(data)
const rows = Array.from(c.objects())
rows === [
  { first: 'one', second: 'two', third: 3, count: 2 },
  { first: 'one', second: 'two', third: 'test', count: 1 },
  { first: 'one', second: 'foo', third: 'test', count: 1 }
]
```

## collection(...columns)

Function accepts a order list of column names. If you attempt
to `set()` a row w/o one of the required columns it will throw.

### collection.reduce()

```javascript
const c = collection('quarter', 'lang', 'count')
c.set({ quarter: 'q1', lang: 'ruby', count: 1000 })
c.set({ quarter: 'q1', lang: 'ruby', count: 2000 })
c.set({ quarter: 'q1', lang: 'js', count: 1000 })
c.set({ quarter: 'q2', lang: 'ruby', count: 3000 })
c.set({ quarter: 'q2', lang: 'js', count: 2000 })

const red = (prev, data) => {
  if (prev) t.ok(data.count - prev === 1000)
  t.ok(data)
  return data.count
}
const rows = Array.from(c.reduce(red))
t.same(rows, [2000, 1000, 3000, 2000])
```

# quarter()

Accepts a datetime object and returns a string for the
year and quarter the time falls under.

```javascript
assert.equal(quarter(new Date('2018-01-02')), '2018 Q1')
assert.equal(quarter(new Date('2018-04-02')), '2018 Q2')
assert.equal(quarter(new Date('2018-08-02')), '2018 Q3')
assert.equal(quarter(new Date('2018-12-02')), '2018 Q4')
```

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