clone

tiny dependency-free nostr libraries for plain html, each under 5kb and named for an element. public domain

main
nobel / neon
README.md

🔗 neon.js - readable nostr

neon.js is a miniature nip19 plus a content renderer. It encodes and decodes npub, note, nprofile, nevent and naddr, and loaded alongside xenon.js it gives templates linked, escaped content and friendly fields. Relative times stay fresh on their own.

<ol nxe-filter='{"kinds":[1]}'>
  <template>
    <li><a href="https://njump.me/{npub}">{npub}</a> <time nne-ago="{created_at}">{ago}</time><p>{content}</p></li>
  </template>
</ol>

Each note shows its author's npub, a time like 5m that keeps updating, and content with links, images and nostr: mentions.

Attributes

attribute description
nne-ago Unix time. Text becomes now, 5m, 3h, 2d or a date, refreshed every 30s

window.nneCfg = {link} sets the prefix for nostr: links (default https://njump.me/).

Template fields

field value
{content} escaped content with links, images and nostr: mentions. npub mentions carry nrn-profile for radon.js
{npub}, {note}, {nevent} encoded ids
{naddr} for kinds 30000-39999
{ago} relative time at render

API

function returns
neon.encode(type, data) bech32 string. data is hex for npub, nsec, note, or an object for nprofile, nevent, naddr
neon.decode(str) {type, data}. Accepts a nostr: prefix
neon.rich(text) escaped, linked HTML
neon.ago(unix) short relative time
neon.esc(text) escaped HTML