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

astro-path-helpers

v0.5.0

Published

Dynamic path helpers for Astro routes.

Readme

Astro Path Helpers

This Astro integration generates type-safe path helper functions for your Astro routes.

Why Astro Path Helpers

When building content-oriented sites, you frequently need to link between pages. Standard Astro doesn't provide a type-safe method for this, leaving you with plain text paths that are prone to typos and difficult to maintain when route structures change.

Astro Path Helpers solves this problem by automatically generating a named type-safe, helper function for each route in your project.

For example, instead of writing:

<a href="/posts/my-post">My Post</a>

You can use the generated helper:

<a href={postPath('my-post')}>My Post</a>

Installation

Quick Install

Run the astro add command below with your package manager of choice and follow the prompts:

# Using PNPM
pnpm astro add astro-path-helpers
# Using NPM
npx astro add astro-path-helpers
# Using Yarn
yarn astro add astro-path-helpers

Manual Install

First, install the astro-path-helpers package using your package manager:

# Using PNPM
pnpm add astro-path-helpers
# Using NPM
npm install astro-path-helpers
# Using Yarn
yarn add astro-path-helpers

Second, add the integration to your astro.config.* file:

astro.config.mjs

 import { defineConfig } from "astro/config";
+import pathHelpers from "astro-path-helpers";

 export default defineConfig({
   integrations: [
     // ...other integrations
+     pathHelpers()
   ],
 });

Usage

After setup, you'll have auto-generated type-safe path helpers available to import throughout your application. For example, if you have these routes

/pages/posts.astro
/pages/posts/[slug].astro

Then you'll have path helpers available:

---
import { postsPath, postPath } from "astro-path-helpers/generated";
---

<a href={postsPath()}>View all posts</a>
<a href={postPath("my-first-post")}>Read my first post</a>

Configuration

Astro Path Helpers has no configuration options yet. Path helpers are generated automatically based on your routes.

Examples

Resources

When a path segment is plural, it is considered a resource segment. Path helpers are generated for deeply nested resources.

Route: /pages/products.astro
Helper: productsPath()

Route: /pages/products/[id].astro
Helper: productPath(productId: string)

Route: /pages/products/[id]/categories.astro
Helper: productCategoriesPath(productId: string)

Route: /pages/products/[id]/categories/[id].astro
Helper: productCategoryPath(productId: string, categoryId: string)

Route: /pages/products/categories.astro
Helper: productsCategoriesPath()

Route: /pages/products/categories/[id].astro
Helper: productsCategoryPath(categoryId: string)

Notice the resource name is singularized in the helper name when it precedes a parameter.

Namespaces

When a path segment is singular, it is treated as a namespace rather than a resource, and we don't ever pluralize it in helper names:

In this example, "role" is a namespace segment, and "members" is a resource segment:

Route: /role/members.astro
Helper: roleMembersPath()

Sometimes you might have a dynamic segment after a namespace segment. Unlike resource routes, the path helper name will contain the parameter:

Route: /dashboard/[id].astro
Helper: dashboardIdPath(id: string)

Other Examples

Rest Parameters

Route: /docs/[...slug]
Helper: docPath(slug: string[]) Notice: slug is an array of strings.

First Segment is Dynamic

When the first segment in the route is dynamic, it will be used in the path helper name.

For example: Route: /[locale]/[...slug]
Helper: localePath(slug: string[])

Multi-part Segments

Route: /reports/[startDate]-to-[endDate]
Helper: reportPath(startDate: string, endDate: string)

Sequential parameters

Route: /docs/[lang]/[version]
Helper: docPath(lang: string, version: string)
Note: Consecutive parameters must be unique. E.g. /product/[id]/[id] will not generate a path helper.

Path Helper Conflicts

It is possible for two different routes to generate helpers with the same name. For example, these two routes would generate path helpers with the same name, dashboardSectionPath:

  1. /pages/dashboard/sections/[sectionId].astro\
  2. /pages/dashboard/[section].astro

Only one will be present in the generated code to avoid duplicate identifiers. It is recommended to rename one of the parameters so that you get path helpers for both routes. For example: change the second route to /pages/dashboard/[id].astro to change its path helper to dashboardIdPath(id: string).

Roadmap

These are possible features in future releases:

  • [ ] Configuration options
  • [ ] Custom path helpers via the integration config
  • [ ] Override auto-generated path helper names via the integration config
  • [ ] Support for Endpoints
  • [x] Support for rest parameters, e.g. /pages/books/[...slug]
  • [x] Support for multi-part segments
  • [x] Support for consecutive dynamic parts, e.g. /pages/products/[id]/[variant] --> productPath(id, variant)
  • [ ] Custom rules and overrides for route name singularization and pluralization

I'd love to hear your ideas! Have a feature you'd like to see? Please reach out and share your suggestions - community feedback helps make this integration better for everyone!

Changelog

See CHANGELOG.md for a history of changes to this integration.