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

hyperpubee

v0.3.1

Published

Self-publishing over the decentralised internet

Downloads

8

Readme

HyperPubee

HyperPubee is a data structure for written text which allows (self-)publishing on the decentralised internet. An interesting feature is the ability to embed parts of other texts.

It currently supports basic poetry and prose texts, as well as collections.

Warning: this library is still in early alfa, and there are likely to be breaking changes before it reaches v1.0.0.

Install

npm add hyperpubee

Data Structure

HyperPubees are stored in a distributed key-value store called hyperbee. Hyperbees allow sparse loading of their content, which is particularly important if you are using embeddings (if you are embedding a single line from a book, it would not be very efficient to first load the entire book to then extract the embedded phrase).

Hyperbees are also versioned, which is important when embedding other texts (when you embed a specific version, the embedded text will always remain the same, even if the referenced text is updated).

Hyperbees are not stored in some centralised location, they are stored on a decentralised network. This implies that you do not have to worry about the work you referenced suddenly becoming unavailable--you can actually help host it.

HyperPubees are structured in a tree format. There are currently three kinds of leaf nodes: plain text, embeddings and links. Non-leaf nodes impose structure (for example, multiple embeddings can be combined in a line, multiple lines can be combined in a verse...)

You can create hyperpubees with any kind of self-defined structures you wish, you will simply have to make sure that the library which renders them knows how to interpret your structures. For example, a simple renderer for a poem would introduce a new line after each 'line' structure, and two new lines after each 'verse' structure.

Rendering

HyperPubees are meant to be rendered by some front-end library, such as hyperpubee-app.

The basic algorithm is:

  • Start by requesting the root

  • Then Interpret its contents and recursively request all children until reaching leaf nodes

    • When you encounter an embedding, you should request the embedded content from the referenced HyperPubee, apply the patch if it exists, then render the text.
    • When you encounter a link, you should describe its content and provide a way to access the linked work (for example: loading and displaying its title, and providing a way to load the hyperpubee corresponding to its hash)

Usage

Note: these examples use the random-access-memory package, so it will need to be installed.

Poetry

const ram = require('random-access-memory')
const HyperInterface = require('hyperpubee-hyper-interface')
const { api, helpers } = require('hyperpubee')
const Corestore = require('corestore')

const corestore = new Corestore(ram)
const hyperInterface = new HyperInterface(corestore)
await hyperInterface.ready()

// Creating a poem
const text = `[poetry]
# My poem

This is an example poem
It is very brief
`

pubee = await api.buildWorkFromText(
  text,
  'my test poem',
  hyperInterface
)

console.log("Created poem with key", pubee.key)

// Normally you would use some front-end renderer,
// but these are not included in this package
// so we print a JSON representation of the internal structure
const resolvedPubee = await helpers.resolvePubeeToJson(pubee)
console.log(JSON.stringify(resolvedPubee, null, 1))

/* Expected output:
[
 {
  "title": [
   "My poem"
  ]
 },
 {
  "poem": [
   {
    "verse": [
     {
      "line": [
       "This is an example poem"
      ]
     },
     {
      "line": [
       "It is very brief"
      ]
     }
    ]
   }
  ]
 }
]
*/

Prose

You can create prose works in the same way, except that you should now indicate the 'prose' type at the start of the text.

const ram = require('random-access-memory')
const HyperInterface = require('hyperpubee-hyper-interface')
const { api, helpers } = require('hyperpubee')
const Corestore = require('corestore')

const corestore = new Corestore(ram)
const hyperInterface = new HyperInterface(corestore)
await hyperInterface.ready()

// Creating prose
const text = `[prose]
# My Story

## Chapter 1

This is my story.

I separate paragraphs with 2 newlines.

## Chapter 2

The end!
`

pubee = await api.buildWorkFromText(
  text,
  'my piece of prose',
  hyperInterface
)

console.log("Created prose with key", pubee.key)

const resolvedPubee = await helpers.resolvePubeeToJson(pubee)
console.log(JSON.stringify(resolvedPubee, null, 1))

/* Expected output:
[
 {
  "title": [
   "My Story"
  ]
 },
 {
  "prose": [
   {
    "chapter": [
     {
      "chapterTitle": [
       "Chapter 1"
      ]
     },
     {
      "paragraph": [
       "This is my story."
      ]
     },
     {
      "paragraph": [
       "I separate paragraphs with 2 newlines."
      ]
     }
    ]
   },
   {
    "chapter": [
     {
      "chapterTitle": [
       "Chapter 2"
      ]
     },
     {
      "paragraph": [
       "The end!"
      ]
     }
    ]
   }
  ]
 }
]
*/

Collections

Collections are simply references to other hyperpubees:

const ram = require('random-access-memory')
const HyperInterface = require('hyperpubee-hyper-interface')
const { api, helpers } = require('hyperpubee')
const Corestore = require('corestore')

const corestore = new Corestore(ram)
const hyperInterface = new HyperInterface(corestore)
await hyperInterface.ready()

// Creating a collection

// Note: you should use hashes of existing and available works.
// These dummy hashes serve only as illustration of the concept.
const hash1 = "a".repeat(64)
const hash2 = "b".repeat(64)

const text = `[collection]
# My Collection

[${hash1}]
[${hash2}/structure/chapter/2]
`

pubee = await api.buildWorkFromText(
  text,
  'my collection',
  hyperInterface
)

console.log("Created collection with key", pubee.key)

const resolvedPubee = await helpers.resolvePubeeToJson(pubee)
console.log(JSON.stringify(resolvedPubee, null, 1))

/* Expected output:
[
 {
  "title": [
   "My Collection"
  ]
 },
 {
  "collection": [
   {
    "linkedHash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
   },
   {
    "linkedHash": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
    "linkedLocation": "structure\u0000chapter\u000002"
   }
  ]
 }
]
*/