# @prudent/encode

> Encode messages using Prudent's IPC protocol (for communicating between add-ons and Prudent). Also, date() helps convert date strings to comply to Prudent's date string protocol

Latest version **2.6.0** (published 2020-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @prudent/encode
pnpm add @prudent/encode
yarn add @prudent/encode
bun add @prudent/encode
```

## 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.6.0 |
| Published | 2020-05-24 |
| First published | 2018-10-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vito Chin |
| Maintainers | kiern, vitoc |
| Keywords | encode, Prudent, IPC |

## Links

- npm: https://www.npmjs.com/package/@prudent/encode
- npm.io page: https://npm.io/package/@prudent/encode

## Dependencies (1)

- [dateformat](https://npm.io/package/dateformat.md) ^3.0.3

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 2.6.0 (latest) — 2020-05-24
- 2.5.0 — 2020-01-19
- 2.3.0 — 2019-10-06
- 2.1.1 — 2019-09-28
- 2.2.0 — 2019-03-10
- 2.1.0 — 2019-03-10
- 2.0.0 — 2018-10-14
- 1.0.0 — 2018-10-14

## README

@prudent/encode
===============

Encode messages using Prudent's IPC protocol (for communicating between add-ons and Prudent). 

This is useful for Prudent add-on developers.

Installing
==========

```
$ npm install --save
```

Usage
=====

To encode a message that comply to Prudent's add-on communication protocol:

```
encode.protocol(messageName, content);
```

Typically, Prudent will listen to your add-on process' standard output. To send a message to Prudent, the following will do:

```
console.log(encode.protocol('transactions', arrayOfTransactions));
```

To format a date string into a Prudent compatible string:

```
console.log(encode.dateString('2019-12-25'));
```

To format a transaction to be Prudent compatible:

```
console.log(encode.transaction(date, payee, value, description, debit, credit, type));
```

```debit```, ```credit``` and ```type``` are optional. 

To create a chart object that can be sent to a Prudent compatible client:

```
encode.chart(visualizer, type, title, content);
```

See Format section below for the expected type that these parameters.

Protocols
=========

Prudent to Add-on:

| Message name | Expected content                            | Type of add-on applicable | Example                | Data type                    |
|--------------|---------------------------------------------|---------------------------|------------------------|------------------------------|
| file         | Absolute path and filename of file to parse | Parser                    | /Users/Cody/August.csv | String                       |
| transactions | List of transactions in parsed file         | Parser                    | ```[]```               | Array of transaction objects |


Format
=========

Supported date string format:

```
yyyy/mm/dd
```

Use ```encode.dateString()``` to convert most popular date strings to this format.

Expected transaction object format:

```
{
    date: date, // String: yyyy/mm/dd as per above
    payee: payee, // String
    value: value, // Numerics in String form, e.g. '3.89'
    description: description, // String
    debit: debit, // String, Optional
    credit: credit, // String, Optional
    type: type // String: DEBIT | CREDIT, Optional 
} 
```

Use ```encode.transaction()``` to create such an object.

Expected chart object format:

```
{
        visualizer: visualizer, // String, i.e. 'Nivo'
        type: type, // String, i.e. 'ResponsiveBar'
        title: title, // String, i.e. 'Interest earnings'
        chart: content // Object, i.e. props for Responsive Bar component
}
```

Use ```encode.chart()``` to create such an object.

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