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

@uev/odata-parser

v0.2.2

Published

Zero-dependency OData v4 Parser - outputs AST for any database backend

Readme

@uev/odata-parser

Zero-dependency OData v4 parser that outputs an Abstract Syntax Tree (AST). Use with any database backend.

Features

  • Zero runtime dependencies - Pure TypeScript
  • ~95% OData v4 spec coverage - All common query options and operators
  • Database agnostic - Outputs AST, you convert to your database's query format
  • Full TypeScript support - Typed tokens and visitor utilities
  • Dual module format - ESM and CommonJS

Installation

yarn add @uev/odata-parser
# or
npm install @uev/odata-parser

Quick Start

import { Parser, filter, query } from '@uev/odata-parser';

// Using the Parser class
const parser = new Parser();
const ast = parser.filter("Name eq 'John' and Age gt 21");

// Using standalone functions
const filterAst = filter("Status eq 'active'");
const queryAst = query("$filter=Name eq 'John'&$top=10&$orderby=Age desc");

// Access parsed values
console.log(queryAst.value.options); // Array of parsed query options

AST Structure

Every parsed result is a Token with this shape:

interface Token {
  position: number;    // Start position in source
  next: number;        // End position
  type: TokenType;     // What kind of token (EqualsExpression, Literal, etc.)
  raw: string;         // Original source text
  value: any;          // Parsed content (shape depends on type)
}

Example: Parsing Name eq 'John' returns:

{
  position: 0,
  next: 15,
  type: "EqualsExpression",
  raw: "Name eq 'John'",
  value: {
    left: { type: "FirstMemberExpression", raw: "Name", value: {...} },
    right: { type: "Literal", raw: "'John'", value: "Edm.String" }
  }
}

Error Handling

The parser returns undefined when parsing fails (does not throw):

const result = parser.filter("invalid ??? syntax");
if (!result) {
  console.log("Parse failed");
}

Supported Query Options

| Option | Example | |--------|---------| | $filter | Name eq 'John' and Age gt 21 | | $select | Name,Age,Email | | $expand | Orders($select=Id,Total) | | $orderby | CreatedAt desc,Name asc | | $top | 10 | | $skip | 20 | | $count | true | | $search | "search term" |

Filter Operators

  • Comparison: eq, ne, lt, le, gt, ge, has
  • Logical: and, or, not
  • Arithmetic: add, sub, mul, div, mod

Built-in Functions

  • String: contains, startswith, endswith, length, indexof, substring, tolower, toupper, trim, concat
  • Date/Time: year, month, day, hour, minute, second, now, date, time
  • Math: round, floor, ceiling
  • Lambda: any, all

AST Traversal

import { Parser, traverseAst, findAll, TokenType } from '@uev/odata-parser';

const parser = new Parser();
const ast = parser.query("$filter=Name eq 'John'&$orderby=Age desc");

// Find all tokens of a specific type
const orderByItems = findAll(ast, TokenType.OrderByItem);

// Custom traversal
traverseAst({
  [TokenType.EqualsExpression]: (token, parent) => {
    console.log('Found equals:', token.raw);
  },
  [TokenType.OrderByItem]: (token) => {
    console.log('Order by:', token.raw);
  },
}, ast);

Integration Example

The parser outputs AST only. Here's how you'd convert to a database query:

import { Parser, traverseAst, TokenType } from '@uev/odata-parser';

function buildWhereClause(filterString: string): string {
  const parser = new Parser();
  const ast = parser.filter(filterString);
  if (!ast) return '';

  const conditions: string[] = [];

  traverseAst({
    [TokenType.EqualsExpression]: (token) => {
      const field = token.value.left.raw;
      const value = token.value.right.raw;
      conditions.push(`${field} = ${value}`);
    },
    [TokenType.GreaterThanExpression]: (token) => {
      const field = token.value.left.raw;
      const value = token.value.right.raw;
      conditions.push(`${field} > ${value}`);
    },
  }, ast);

  return conditions.join(' AND ');
}

buildWhereClause("Name eq 'John' and Age gt 21");
// → "Name = 'John' AND Age > 21"

Not Currently Supported

These OData v4 features are not implemented:

  • $apply - Aggregation transformations
  • $compute - Computed properties (OData 4.01)

Building

yarn install
yarn build        # Build with tsup (ESM + CJS)
yarn typecheck    # Type check without emitting
yarn test         # Run tests

License

MIT

Attribution

This parser is based on the original odata-v4-parser by JayStack, which implemented the OASIS OData v4 ABNF grammar. That project is no longer maintained.