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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hs2js

v0.1.0

Published

Experimental Haskell in JavaScript interpreter

Readme

hs2js

Experimental haskell in javascript interpreter. Many haskell features are not implemented. This projects mainly exists to be able to write and interpret Tidal Cycles code in the browser, as part of Strudel. This project could only exist thanks to tree-sitter-haskell.

Installation

Via Script Tag

You can load the library directly from a script tag via unpkg:

<script src="https://unpkg.com/[email protected]"></script>
<button id="hello">hello</button>
<script>
  hs2js.setBase('https://unpkg.com/[email protected]/dist/');
  hs2js.loadParser().then(()=>{
    document.getElementById('hello').addEventListener('click', () => {
      hs2js.evaluate('alert "hello from haskell!"');
    });
  })
</script>

Via npm

You need to add postinstall to your package.json script to copy the parser to your public folder:

{
  "scripts": {
    "postinstall": "cp node_modules/hs2js/dist/tree-sitter.wasm public && cp node_modules/hs2js/dist/tree-sitter-haskell.wasm public"
  }
}

Depending on your setup, replace public with the folder that will serve your assets to /. Then install the package:

npm i hs2js

and use it:

import * as hs2js from 'hs2js';
hs2js.loadParser();
document.getElementById('hello').addEventListener('click', () => {
  hs2js.evaluate('alert "hello from haskell!"');
});

API

These are all functions exported by the package:

evaluate

Evaluates a piece of haskell code

  • code: valid haskell code
  • scope: global scope, defaults to globalThis. Allows you to pass an object of your own functions / variables from JS to Haskell.
  • ops: mapping for custom infix operator

Example:

// simple
hs2js.evaluate(`2 + 2`) // = 4
// passing variables via scope:
hs2js.evaluate(`a + b`, { a: 1, b: 2 }) // = 3
// custom operator
hs2js.evaluate(`2 |* 3`, {}, { '|*': (l, r) => l * r }) // = 6

parse

Parses a piece of haskell code, returning its AST representation.

Example:

const ast = hs2js.parse(`2 + 2`)
console.log(ast.toString())
// (haskell declarations: (declarations (top_splice (apply function: (variable) argument: (literal (integer))))))

run

Evaluates rootNode of haskell AST (used by evaluate internally).

  • rootNode: haskell AST root node, as returned by parse
  • scope: see evaluate
  • ops: see evaluate

Example:

const ast = hs2js.parse(`2 + 3`);
const res = hs2js.run(ast.rootNode);
console.log(res); // = 5

loadParser

Loads and caches the parser by fetching tree-sitter.wasm and tree-sitter-haskell.wasm. Make sure to call and await this function before calling parse or evaluate.

hs2js.loadParser().then(() => hs2js.evaluate('alert "ready"'))

setBase

Sets the base path where the WASM files are expected by loadParser. Defaults to /. Expects tree-sitter.wasm and tree-sitter-haskell.wasm to be present. Can either be a relative path or a URL.

hs2js.setBase('https://unpkg.com/[email protected]/dist/');
hs2js.loadParser(); 
/* loads 
- https://unpkg.com/[email protected]/dist/tree-sitter.wasm
- https://unpkg.com/[email protected]/dist/tree-sitter-haskell.wasm
*/