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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@synstack/path

v1.2.0

Published

Advanced path manipulation utilities

Readme

@synstack/path

Advanced path manipulation utilities

What is it for?

This package provides a strongly-typed interface for working with file system paths. It ensures type safety between absolute and relative paths while offering comprehensive utilities for path manipulation, extension handling, and MIME type detection:

import { path } from "@synstack/path";

// Type-safe path resolution
const absolutePath = path.resolve("/base", "subdir", "file.txt");
console.log(absolutePath); // "/base/subdir/file.txt"

// Path type checking
const isAbs = path.isAbsolute("/absolute/path"); // true
const isAbs2 = path.isAbsolute("relative/path"); // false

// Path manipulation
const dirName = path.dirname("/path/to/file.txt"); // "/path/to"
const relativePath = path.relative("/base/dir", "/base/dir/subdir/file.txt"); // "subdir/file.txt"

Installation

# Using npm
npm install @synstack/path

# Using yarn
yarn add @synstack/path

# Using pnpm
pnpm add @synstack/path

Features

Type-Safe Paths

The package provides type definitions for different kinds of paths:

import type { AbsolutePath, RelativePath, AnyPath } from "@synstack/path";

// Type-safe path handling
function processPath(path: AbsolutePath) {
  // Only absolute paths are accepted
}

function processRelative(path: RelativePath) {
  // Only relative paths are accepted
}

function processAny(path: AnyPath) {
  // Any path type is accepted
}

Path Operations

Path Resolution and Validation

import { path } from "@synstack/path";

// Resolve paths
const abs = path.resolve("relative/path"); // Converts to absolute path
const isAbs = path.isAbsolute("/some/path"); // Check if path is absolute
const dir = path.dirname("/path/to/file.txt"); // Get directory name

Path Relationships

// Check path containment
path.isInPath("/base", "/base/subdir"); // true
path.isInPath("/base", "/other"); // false

// Create relative paths
path.relative("/base/dir", "/base/dir/subdir/file.txt"); // "subdir/file.txt"

Path Joining and Manipulation

// Join paths
path.join("/absolute", "path", "file.txt"); // "/absolute/path/file.txt"
path.join("relative", "path", "file.txt"); // "relative/path/file.txt"

// Remove relative indicators
path.removeRelativeIndicator("./file.txt"); // "file.txt"

File Extensions

// Add or ensure extensions
path.addMissingExtension("/path/to/file", "txt"); // "/path/to/file.txt"
path.ensureFileExtension("/path/to/file", ".txt"); // "/path/to/file.txt"
// extension can be provided without leading dot
path.ensureFileExtension("/path/to/file", "txt"); // "/path/to/file.txt"

// Get file information
path.filename("/path/to/file.txt"); // "file.txt"
path.filenameWithoutExtension("/path/to/file.txt"); // "file"
path.fileExtension("/path/to/file.txt"); // ".txt"

MIME Types

// Get MIME type from path
path.mimeType("/path/to/image.png"); // "image/png"
path.mimeType("/path/to/unknown"); // null

ES Module Support

// Convert import URLs to file system paths
const dirPath = path.importUrlToAbsolutePath(import.meta.url);

Error Handling

The package includes custom error types for specific path-related issues:

import { PathNotInCwdException } from "@synstack/path";

try {
  // Operations that might throw PathNotInCwdException
} catch (error) {
  if (error instanceof PathNotInCwdException) {
    console.error(
      "Path operation outside current working directory:",
      error.message,
    );
  }
}