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

@eserstack/parsing

v5.1.0

Published

Readme

〰️ @eserstack/parsing

Note: JSR is frozen at 4.5.x. From 5.0.0, @eserstack/parsing is published on npm under the same name (pnpm add @eserstack/parsing); the JSR versions stay available but get no updates.

eserstack Library — eser/stack on GitHub Install: pnpm add @eserstack/parsing

@eserstack/parsing is a parsing library for analyzing and tokenizing strings. While it includes a lexer component, its capabilities extend beyond simple lexing, providing a flexible and efficient way to parse strings into meaningful tokens or an abstract syntax tree.

🚀 Getting Started with Parsing

Parsing is the process of analyzing a sequence of symbols (usually in the form of text) to determine its grammatical structure with respect to a given formal grammar. It's a crucial step in many computer science tasks, from compiling programming languages to understanding natural language.

Tokenizer (also known as Lexer)

A tokenizer is a crucial component in compilers and interpreters. It reads the input of raw text and breaks it down into a series of tokens, which are sequences of characters with a known meaning. The lexer included in @eserstack/parsing is designed to be both efficient and versatile, making it suitable for a wide range of input sources.

Parser

A parser takes the tokens produced by the tokenizer and arranges them in a structure, often hierarchical, that represents the syntactic meaning of the tokens in the context of the input. The output of the parser is usually a tree-like representation of the input, which can be processed further or translated into another form.

Abstract Syntax Tree (AST)

Abstract Syntax Tree is a tree representation of the syntactic structure of source code. Each node in the tree denotes a construct occurring in the source code. The syntax is 'abstract' in not representing every detail appearing in the real syntax, but rather just the structural or content-related details. ASTs are used extensively in compilers and source code analysis tools.

🛠 Usage

Here you'll find a list of features provided by @eserstack/parsing along with brief descriptions and usage examples.

Tokenizing from source

Basic usage:

import * as parsing from "@eserstack/parsing";

const lexer = new parsing.Tokenizer(
  parsing.createTokenizerState(parsing.simpleTokens),
);

for (const token of lexer.tokenizeFromString("1 + 2")) {
  console.log(token);
}

Using a different token dictionary:

A token dictionary maps each token kind to a literal string or a pattern function, and the first entry that matches wins. Put your own kinds before the ones from simpleTokens, so << becomes one T_SHIFT_LEFT token instead of two T_IS_SMALLER tokens:

import * as parsing from "@eserstack/parsing";

const tokens: parsing.TokenDefinitions = {
  T_SHIFT_LEFT: "<<",
  ...parsing.simpleTokens,
};

const lexer = new parsing.Tokenizer(parsing.createTokenizerState(tokens));

const kinds = Array.from(
  lexer.tokenizeFromString("cout << 'hello C++' << endl;"),
  (token) => token.kind,
);

console.log(kinds);

Reading from a ReadableStream:

tokenize() reads a stream of string chunks, such as a file or a response body piped through a TextDecoderStream. A token that a pattern function matches may span two chunks:

import * as parsing from "@eserstack/parsing";

const input = ReadableStream.from(["const total", " = 1 + 2;"]);

const lexer = new parsing.Tokenizer(
  parsing.createTokenizerState(parsing.simpleTokens),
);

for await (const token of lexer.tokenize(input)) {
  console.log(token);
}

📕 API Reference

The following is a list of all available methods and their descriptions.

Tokenizer

new Tokenizer(createTokenizerState(tokens))
Tokenizer is a class that can be used to tokenize strings. It is initialized with a list of tokens.

Tokenizer.tokenizeFromString(input: string)
Tokenizes the given input string and returns an iterator for the tokens.

Tokenizer.tokenize(input: ReadableStream)
Tokenizes a readable stream of string chunks and returns an async iterator for the tokens.


🔗 For further details, visit the eserstack repository.