# dolma

> A token encoder and decoder for DogeHouse and associated projects

Latest version **1.1.1** (published 2021-05-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install dolma
pnpm add dolma
yarn add dolma
bun add dolma
```

## 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.1 |
| Published | 2021-05-08 |
| First published | 2021-05-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Maintainers | holopanio |
| Keywords | dolma, dogehouse, doghouse.js, doghouse-tokens, tokens |

## Links

- npm: https://www.npmjs.com/package/dolma
- Repository: https://github.com/HoloPanio/dolma
- Homepage: https://github.com/HoloPanio/kefler#readme
- Issues: https://github.com/HoloPanio/dolma/issues
- npm.io page: https://npm.io/package/dolma

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) ^15.0.2

## Recent versions

- 1.1.1 (latest) — 2021-05-08

## README

<h1 align=center>
Dolma Token Transcoder<br>
<a href="https://www.npmjs.com/package/dolma"><img src="https://img.shields.io/npm/v/dolma?style=for-the-badge"></a>
</h1>
This is a token transcoder that is used to encode and decode DogeHouse chat message token arrays.  This package is written for bot/bot library devlopers to be able to easily transcode dogehouse chat message tokens.  

## How to install
To install this, simply go to your project and run the following command:
```cmd
npm install dolma@latest --save
```

## How to use
This will show you how to encode and decode tokens

### Encoding Tokens
In this example, you will see multiple ways to encode your tokens.  The first one is in plain text.  You can pass any string into the encoder and it will convert it into an array of Message Tokens.

```ts
import { dolma } from 'dolma';

const str = "I'm @HoloPanio, and I'd like to goto `Paris, France` one day :catJAM: Also, https://google.com is epic!";

const tokens = dolma.encode(str);

console.log(tokens);

/**
Returns: 
[
  { t: 'text', v: "I'm" },
  { t: 'mention', v: 'HoloPanio' },
  { t: 'text', v: ',' },
  { t: 'text', v: 'and' },
  { t: 'text', v: "I'd" },
  { t: 'text', v: 'like' },
  { t: 'text', v: 'to' },
  { t: 'text', v: 'goto' },
  { t: 'block', v: 'Paris, France' },
  { t: 'text', v: 'one' },
  { t: 'text', v: 'day' },
  { t: 'emote', v: 'catJAM' },
  { t: 'text', v: 'Also,' },
  { t: 'link', v: 'https://google.com' },
  { t: 'text', v: 'is' },
  { t: 'text', v: 'epic!' }
]
*/
```

In this example, you will see that you can have an mixed array with strings, and unitokens!  A unitoken is a token object where you define your object key as the token type, and the value as the value of the token, doing so would look like such: `{link: "https://google.com"}`, and this can be done for all token types.

```ts
import { dolma } from 'dolma';

const arr = ["I'm", {mention: "HoloPanio"},", and I'd like to goto", {block: "Paris, France"},"one day", {emote: "catJAM"}, "Also",{link: 'https://google.com'}, "is epic!"];

const tokens = dolma.encode(str);

console.log(tokens);

/**
Returns: 
[
  { t: 'text', v: "I'm" },
  { t: 'mention', v: 'HoloPanio' },
  { t: 'text', v: ',' },
  { t: 'text', v: 'and' },
  { t: 'text', v: "I'd" },
  { t: 'text', v: 'like' },
  { t: 'text', v: 'to' },
  { t: 'text', v: 'goto' },
  { t: 'block', v: 'Paris, France' },
  { t: 'text', v: 'one' },
  { t: 'text', v: 'day' },
  { t: 'emote', v: 'catJAM' },
  { t: 'text', v: 'Also,' },
  { t: 'link', v: 'https://google.com' },
  { t: 'text', v: 'is' },
  { t: 'text', v: 'epic!' }
]
*/
```
You can also pass in message tokens like `{t: 'link', v: 'https://google.com'}`, and it will work because the encoder checks for all possible methods that can be used.


### Decoding Tokens
When you get a payload from DogeHouse, you can use the decode method which will take the tokens, and turn it into a raw text string when you can use anywhere you please.  The decode method will always encode the data sent to it to ensure that the data is parsed correctly, so that means you can also pass in un-encoded data, such as the array in the previous example, and will print out a plain text string.  In this example, we will take the array from above, and return it to a plain text string using the decode method.

```ts
import { dolma } from 'dolma';

const tokens = [
  { t: 'text', v: "I'm" },
  { t: 'mention', v: 'HoloPanio' },
  { t: 'text', v: ',' },
  { t: 'text', v: 'and' },
  { t: 'text', v: "I'd" },
  { t: 'text', v: 'like' },
  { t: 'text', v: 'to' },
  { t: 'text', v: 'goto' },
  { t: 'block', v: 'Paris, France' },
  { t: 'text', v: 'one' },
  { t: 'text', v: 'day' },
  { t: 'emote', v: 'catJAM' },
  { t: 'text', v: 'Also,' },
  { t: 'link', v: 'https://google.com' },
  { t: 'text', v: 'is' },
  { t: 'text', v: 'epic!' }
];

const message = dolma.decode(tokens);

console.log(message);

/**
Returns: 

I'm @HoloPanio , and I'd like to goto `Paris, France` one day :catJAM: Also, https://google.com is epic!
*/
```

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