# @jadesrochers/datapulse

> Store data, flushing it periodically

Latest version **0.1.3** (published 2023-04-16) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @jadesrochers/datapulse
pnpm add @jadesrochers/datapulse
yarn add @jadesrochers/datapulse
bun add @jadesrochers/datapulse
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2023-04-16 |
| First published | 2019-03-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jared Desrochers |
| Maintainers | jadesrochers |

## Links

- npm: https://www.npmjs.com/package/@jadesrochers/datapulse
- Repository: https://github.com/jadesrochers/datapulse
- Homepage: https://github.com/jadesrochers/datapulse#readme
- Issues: https://github.com/jadesrochers/datapulse/issues
- npm.io page: https://npm.io/package/@jadesrochers/datapulse

## Dependencies (1)

- [ramda](https://npm.io/package/ramda.md) ^0.29.0

## Recent versions

- 0.1.3 (latest) — 2023-04-16
- 0.1.2 — 2023-04-16
- 0.1.1 — 2019-09-18
- 0.1.0 — 2019-03-16

## README

# Data Pulse
Accumulates data inputs and writes them at the configured interval  
using a write function.

It also has a counter function that writes a given log statement  
at the configured number of repetitions.

## Whats the Use?
If data writes are expensive computationally this allows a larger  
number to happen at once. 
Could be useful for db/disk writes to reduce IO frequency even though  
the total size of the data will not change.

## installation 
npm install @jadesrochers/datapulse

const acc = require('@jadesrochers/datapulse')

## Data Accumulator/Writer Usage
This example uses a write function that just writes all the data  
to a file with naming based on the first element.

#### sample write function
This is just a simple file write, but you can build a function  
to do anything with the passed storage array that you want.
```javascript
let writefcn3 = storedArray => require('fs').writeFile(
    'testfile' + storedArray[0] + '.txt',
    JSON.stringify(storedArray,null,1),
    (out) => {}
); 
```
#### create the accumulator
Then create the accumulator, passing the interval and writing function.
var testWrite = acc.storeAndWrite(100, inFcn)

#### run it through a simple test
This should write 10 file, each named with the first number in the array.
```javascript
async function waiter(){
  for(let j = 1; j < 1001; j++){
    await testWrite.add(j) 
  }
}
```

### Currently have to await the write function
The await is needed for when the write function fires.  
The write function is passed the internal storage, so currently you need  
to wait for the write to finish to add/clear this internal storage.  
I might change this to clone and then reset and not wait in the future.

## Counter usage
Very simple; pass the threshold to activate a statement, and the statement.  
Accepts custom log function as optional third argument.

let testcount = acc.counter(1000, 'Test entries counted')
```javascript
for(let j = 1; j < 10001; j++){
  testcount()
}
```

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