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

@haz3y0ne/parsexl

v0.0.4

Published

Parses Excel formulas into a clean, well-typed abstract syntax tree you can analyse or evaluate in TypeScript.

Readme

parsexl

A lightweight, dependency-free TypeScript library that parses raw Microsoft Excel formulas into well‑structured, strongly‑typed Abstract Syntax Trees (ASTs). Perfect for analysis, transformation, or formula tooling—without needing Excel or Office integration.

Inspired by psalaets/excel-formula-ast, this parser reimagines the approach using a Pratt (TDOP) parser instead of a Shunting Yard algorithm, improving readability, control, and extensibility.

TypeScript Parser Runtime Excel


✨ Highlights

| Feature | Description | | ----------------------------- | -------------------------------------------------------------------------------------------------------------------- | | Fully lossless token stream | Lexer preserves every character—sheet names, errors, quotes, and all. | | Pratt (TDOP) parser | Operator precedence, prefix/postfix disambiguation, ranges, spills (%) all handled via a precedence-driven design. | | Structured transform pipeline | Clean post-processing via optional AST passes like collapseBinary and normalizeFilters. | | Type-safe & dependency-free | Published as both ESM and CJS, with full .d.ts support and no runtime dependencies. | | Diagnostic-friendly AST | Every node and token includes source loc offsets to enable mapping back to original input. |


📦 Installation

npm i @haz3y0ne/parsexl

🚀 Quick Start

import { parseFormula } from "excel-formula-ast";

const ast = parseFormula('=SUM(FILTER(A1:C10,(B:B="West")*(C:C>1000)))');
console.dir(ast, { depth: null });

Each node in the tree includes precise loc.start and loc.end positions, ideal for linting, diagnostics, or source mapping.


🧐 Example: Formula → AST

Input

=IF(
  AND(ISNUMBER(B2), B2>100),
  TEXT(TODAY(), "mm/dd/yyyy"),
  IF(ISBLANK(C2), "Missing", "Check")
)

Output (JSON)

{
  "type": "IF",
  "args": [
    {
      "type": "AND",
      "args": [
        { "type": "ISNUMBER", "args": [{ "type": "CELL", "value": "B2" }] },
        {
          "type": ">",
          "args": [
            { "type": "CELL", "value": "B2" },
            { "type": "NUMBER", "value": 100 }
          ]
        }
      ]
    },
    {
      "type": "TEXT",
      "args": [
        { "type": "TODAY" },
        { "type": "LITERAL", "value": "mm/dd/yyyy" }
      ]
    },
    {
      "type": "IF",
      "args": [
        { "type": "ISBLANK", "args": [{ "type": "CELL", "value": "C2" }] },
        { "type": "LITERAL", "value": "Missing" },
        { "type": "LITERAL", "value": "Check" }
      ]
    }
  ]
}

📊 Supported Excel Functions

Supports over 50 Excel worksheet functions across logical, lookup, math, text, and dynamic array categories.

| Category | Examples | | ------------------------ | --------------------------------------------------------------------------------- | | Logical / Error Handling | IF, AND, OR, NOT, IFERROR, IFNA, ISERROR, ISBLANK, ISNUMBER | | Lookup & Reference | INDEX, MATCH, VLOOKUP, XLOOKUP, CHOOSE | | Math & Trigonometry | SUM, ROUND, ABS, FLOOR, CEILING, MIN, MAX, RANK, ROUNDUP, etc. | | Text | TEXT, LEFT, RIGHT, SUBSTITUTE, TEXTJOIN, VALUE, LEN, CONCAT, etc. | | Statistical | COUNT, COUNTA, AVERAGE, SUMIF, SUMIFS, COUNTIF, COUNTBLANK | | Dynamic Arrays | LET, LAMBDA, FILTER, UNIQUE, SORT, SEQUENCE, RANDARRAY, SORTBY |


⚙️ Architecture Overview

string → tokenize → guessToken → prattParse → collapseBinary → normalizeFilters → AST

Components

  • lexer/ — Regex-based tokenizer (longest-match)
  • parser/ — Pratt parser with binding power table
  • transforms/ — Optional AST passes
  • types/ — All type definitions and function metadata
  • parseFormula.ts — High-level orchestrator

📅 Testing

  • Lexer snapshots
  • Round‑trip validation (AST → string → Excel)
  • Complex transform edge cases
npm test         # Full test suite
npm run test:lex # Lexer-only tests

⚠️ Limitations

  • Array constants {} currently opaque
  • No full handling of intersection (space) or union (comma) yet
  • Spill ranges (#) are not parsed

🛠️ Extend It

| Task | Where to Modify | | --------------------- | ------------------------------------------------ | | Add new function | types/functions.ts | | New token type | lexer/patterns.ts | | Custom transform pass | transforms/ + export via transforms/index.ts | | Modify precedence | parser/pratt.ts |


📄 License

MIT © 2025 Chris Moran

This parser is a standalone tool built atop the structure and semantics of Microsoft Excel formulas. It is not affiliated with or endorsed by Microsoft.