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

url-ast

v3.0.1

Published

High-performance typed URL parser with AST-based analysis, automatic type casting, and route pattern matching for modern web applications

Readme

url-ast

npm version license-info stars-info

last-commit commit-activity code-size

top-language bundle-size

💡 About

High-performance typed URL parser with automatic type casting and AST-based analysis.

url-ast is a specialized module for analyzing and manipulating URLs using an Abstract Syntax Tree (AST) approach. It provides deep and structured URL analysis, transforming URLs into interconnected nodes that represent each component (protocol, hostname, parameters, etc.), facilitating manipulation and validation with full TypeScript support and automatic type casting.

📖 Full Documentation


🚀 Key Features

  • AST-Based Analysis: Deep URL structure analysis through interconnected nodes for precise parsing
  • Automatic Type Casting: Built-in support for number, boolean, string, array, and enum type conversion
  • Full TypeScript Support: Complete type inference for parameters and values with compile-time safety
  • Pattern Matching: Advanced support for route patterns with dynamic, optional, and catch-all parameters
  • High Performance: Optimized parser with efficient buffer handling and minimal overhead
  • UTF-8 Decoding: Robust support for special characters and encoded URLs
  • Visual Debugging: Colored visualization of URL structure for easy debugging and analysis
  • Zero Dependencies: Lightweight implementation with no external dependencies

📦 Installation

You can install url-ast using your preferred package manager:

bun add url-ast

(Works with npm, yarn, or pnpm as well)


🛣️ Supported Routing Patterns

| Pattern | Syntax | URL Example | Description | | :--- | :--- | :--- | :--- | | Static | /exact/path | /about/contact | Requires exact match. No variables captured. | | Dynamic (colon) | /:param | /users/:id | Captures a single URL segment. | | Dynamic (bracket) | /[param] | /posts/[slug] | Bracket syntax, Next.js/SvelteKit style. | | Dynamic with type | /:param.type or /[param.type] | /users/:id.number | Captures and converts the type automatically. | | Optional | /:~param or /[~param] | /posts/:id/comments/:~commentId | Parameter can be undefined. | | Catch-all | /[...slug] | /docs/[...path] | Captures multiple segments as string[]. | | Optional catch-all | /[[...slug]] | /blog/[[...slug]] | Base route remains valid without parameters. | | Query params | ?param | ?sort=desc&limit=10 | Captures query string arguments. | | Query with type | ?param.type | ?page.number&active.boolean | Query params with type casting. | | Query with default | ?param.type=value | ?page.number=1 | Query with type and default value. | | Fragment (hash) | #section | #introduction | Captures the anchor at the end of the URL. |


🎯 Type Casting

| Type | Syntax | Description | Input → Output | | :--- | :--- | :--- | :--- | | String | .string (or omitted) | Default behavior. Preserves the text. | user_123'user_123' | | Number | .number | Converts to a numeric value. | -42-42 | | Boolean | .boolean | Analyzes intent and converts to boolean. | true or 1true | | Array | .array | Splits values by comma into a list. | a,b,c['a', 'b', 'c'] | | Enum | .enum[op1,op2] | Restricts values to an allowed list. | admin'admin' | | Generic enum | .enum | Enum without variant restriction. | anything'anything' |


🏁 Quick Start

import { Analyze } from 'url-ast'

const template = new Analyze('/users/:id.number')
const parsed = new Analyze('/users/42', template)

parsed.getParams()        // { id: 42 }

For more examples, check the examples directory or the full documentation.


🤝 Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue. If you want to contribute code, please open a pull request.


📜 License

This project is licensed under the MIT License. See the LICENSE file for details.