• Overview

    twtxt-lib

    An isomorphic TypeScript library of utility functions for parsing and interacting with twtxt.txt files.

    These functions include:

    • hashTwt: takes the constituent parts of a “twt” and generates an extension-compatible hash for it.
    • parseTwtxt: parses a twtxt file string, returning an object with information about the file and its owner (including hashes for each twt and any metadata in the file).
    • loadAndParseTwtxtFile: fetches a twtxt file from the internet and parses it into an object (as above).

    Features

    • Isomorphic, available as an (optionally minified) ES6+ library for the browser, with NPM and JSR versions coming soon.
    • Fully typed and source-mapped.
    • Built as an ES6 module (and ESM only)
    • Includes an interactive demo (you're looking at it).

    Installation

    This library can be installed in several different ways:

    For the Browser

    1. Grab the latest copy of the twtxt-lib.js file, either by downloading it from the git repo, the website, or doing a git clone https://git.itsericwoodward.com/eric/twtxt-lib.git and pulling it out of the dist-browser folder.
      • Alternatively, you can grab the minified version from the same sources.
    2. Add the newly acquired file to your static site / progressive web app / over-engineered blog.
    3. Import the desired function(s) via ESM: import { hashTwt, loadAndParseTwtxtFile } from "./twtxt-lib.js";

    For Node

    1. Add the package to your project.
      • Via NPM: yarn add twtxt-lib
      • Via JSR: yarn add jsr:@itsericwoodward/twtxt-lib
    2. Import the desired function(s) into your code: import { hashTwt, loadAndParseTwtxtFile } from "twtxt-lib";

    Use the tabs to learn more.


    Example parsed file from /twtxt-demos/demo-hipster-twtxt.txt :

    Copyright © 2026 Eric Woodward, released under the MIT License.

  • hashTwt

    A function that takes the constituent parts of a “twt” and generates an extension-compatible hash for it.

  • parseTwtxt

    A function that parses a twtxt file string, returning an object with information about the file and its owner (including hashes for each twt and any metadata in the file).

    Pre-included examples:

    • /twtxt-demos/demo-hipster-twtxt.txt
    • /twtxt-demos/demo-pirate-twtxt.txt
    • /twtxt-demos/demo-sagan-twtxt.txt

    Note that CORS restrictions may limit the effectiveness of using this function from another domain.

  • loadAndParseTwtxtFile

    An async function that fetches a twtxt.txt-compatible file from a URL and parses it into an object

    Pre-included examples:

    • /twtxt-demos/demo-hipster-twtxt.txt
    • /twtxt-demos/demo-pirate-twtxt.txt
    • /twtxt-demos/demo-sagan-twtxt.txt

    Note that CORS restrictions may limit the effectiveness of using this function from another domain.