npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dolma

v1.1.1

Published

A token encoder and decoder for DogeHouse and associated projects

Downloads

4

Readme

How to install

To install this, simply go to your project and run the following command:

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.

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.

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.

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!
*/