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

@khvostpola/pathy

v0.1.1

Published

Type-safe path builder with automatic parameter extraction

Readme

@khvostpola/pathy

Khvost Pola npm version License: MIT

Type-safe path builder with automatic parameter extraction for TypeScript.

Features

  • Type-safe — Automatic parameter extraction from path templates
  • Zero dependencies — Lightweight and fast
  • Dual format — ESM and CommonJS support
  • Flexible — Support for required, optional, and rest parameters
  • RFC 3986 — Proper URL encoding

Installation

npm install @khvostpola/pathy
yarn add @khvostpola/pathy
pnpm add @khvostpola/pathy

Quick Start

import { createPath } from '@khvostpola/pathy'

const userPath = createPath('/users/:id')

userPath({ path: { id: '123' } })
// → "/users/123"

// TypeScript knows 'id' is required!
userPath({ path: {} })
// ❌ Type error: Property 'id' is missing

API

createPath(template, baseURL?)

Creates a type-safe path builder function.

const apiPath = createPath('/users/:id', 'https://api.example.com')
apiPath({ path: { id: '1' } })
// → "https://api.example.com/users/1"

Parameter Syntax

| Syntax | Type | Example | |--------|------|---------| | :param | Required | /users/:id{ id: string } | | :param? | Optional | /users/:id?{ id?: string } | | :param* | Rest (array) | /files/:path*{ path: string \| string[] } |

.withQuery<Q>()

Adds typed query parameter support.

type Filters = { page: number; sort?: string }

const listPath = createPath('/users').withQuery<Filters>()

listPath({ query: { page: 1, sort: 'name' } })
// → "/users?page=1&sort=name"

.template

Access the original template string.

const userPath = createPath('/users/:id')
console.log(userPath.template) // "/users/:id"

createPathsMap(paths)

Groups multiple paths into an organized object.

const api = createPathsMap({
  users: createPath('/users'),
  user: createPath('/users/:id'),
  userPosts: createPath('/users/:id/posts'),
})

api.users()                          // → "/users"
api.user({ path: { id: '5' } })      // → "/users/5"

createIndexedPathsMap(config)

Builds hierarchical paths automatically.

const paths = createIndexedPathsMap({
  index: 'api/v1',
  users: {
    index: 'users',
    detail: ':id',
    posts: ':id/posts',
  },
})

paths.users.detail({ path: { id: '42' } })  // → "/api/v1/users/42"
paths.users.posts({ path: { id: '42' } })   // → "/api/v1/users/42/posts"

Advanced Examples

Combining path and query params

type UserQuery = { includeProfile?: boolean }

const userPath = createPath('/users/:id').withQuery<UserQuery>()

userPath({
  path: { id: '42' },
  query: { includeProfile: true },
})
// → "/users/42?includeProfile=true"

Array query params

type SearchQuery = { tags: string[] }

const searchPath = createPath('/search').withQuery<SearchQuery>()

searchPath({ query: { tags: ['typescript', 'nodejs'] } })
// → "/search?tags=typescript&tags=nodejs"

BaseURL override

const apiPath = createPath('/users/:id', 'https://api.prod.com')

// Override for specific call
apiPath({
  path: { id: '1' },
  baseURL: 'https://api.staging.com',
})
// → "https://api.staging.com/users/1"

Rest parameters

const filesPath = createPath('/files/:segments*')

filesPath({ path: { segments: ['folder', 'subfolder', 'file.txt'] } })
// → "/files/folder/subfolder/file.txt"

TypeScript Support

The library provides full TypeScript support with automatic type inference:

const userPath = createPath('/users/:id/:action?')

// TypeScript infers: { id: string; action?: string }
userPath({ path: { id: '123' } })           // ✓ OK
userPath({ path: { id: '123', action: 'edit' } }) // ✓ OK
userPath({ path: {} })                      // ✗ Error: 'id' is required
userPath({ path: { id: '123', foo: 'bar' } }) // ✗ Error: 'foo' doesn't exist

License

MIT © Khvost Pola


"Aportar, crear, crecer... y tomar Pola."