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

path.js

v2.0.1

Published

Browser-friendly enhanced path fully compatible with standard node.js

Readme

path.js Build Status npm downloads license

Browser-friendly enhanced path fully compatible with standard node.js path

A lightweight, cross-platform library for manipulating paths.

This package modifies and enhances the standard path from node.js

API

Path Class

import { Path } from 'path.js';

// Default constructor with optional string or object parameter
const myPath = new Path('custom_separator'); // String: sets custom path separator
const myPathWithOptions = new Path({
  sep: 'custom_separator', // Custom path separator
  delimiter: 'custom_delimiter', // Custom path delimiter
  splitPathReStr: 'custom_regular_expression', // Custom regular expression for splitting paths
});

Properties

  • sep: The path separator character. Can be set at instantiation or later via a getter/setter.
  • delimiter: The path delimiter character. Can be set at instantiation or later via a getter/setter.
  • splitPathReStr: A string representing a regular expression used to split paths. Must include the placeholder &SEP&, which will be replaced with the current sep. Can be set at instantiation or later via a getter/setter.

Methods

  • updateSplitPathRe(): Updates the internal splitPathRe regular expression based on the current splitPathReStr and sep.
  • splitPath(filename): Splits a given filename using the current splitPathRe and returns the resulting array.
  • toArray(aPath): Converts a given aPath to an array of path segments, trimming any leading or trailing empty elements.
  • normalizeArray(parts, allowAboveRoot): Normalizes an array of path segments, resolving . and .. elements, and optionally allowing paths above the root.
  • trimArray(arr): Removes leading and trailing empty elements from the given array.
  • isAbsolute(path): Returns true if the given path is absolute, false otherwise.
  • normalize(path): Normalizes the given path, resolving . and .. elements, removing redundant separators, and ensuring proper absolute or relative form.
  • cwd(): Returns the current working directory as a string ('.' for default implementation).
  • resolveArray(): Resolves a sequence of paths or path segments into an absolute path, taking the current working directory into account.
  • _join(): Internal method for joining path segments, handling arrays and strings.
  • join(): Joins multiple path segments into a single path, normalizing and resolving relative segments.
  • _isSame(aDir1, aDir2): Compares two directories for equality, returning true if they are the same, false otherwise.
  • relative(from, to): Computes the relative path from from to to.
  • dirname(path): Extracts the directory name from the given path.
  • basename(path, ext): Extracts the base name from the given path, optionally removing a specified extension.
  • replaceExt(path, ext): Replaces the extension of the given path with a new one.
  • extname(path): Extracts the extension from the given path.
  • format(pathObject): Constructs a path string from an object with root, dir, and base properties.
  • parse(pathString): Parses a path string into an object with root, dir, base, ext, and name properties.
  • _makeLong(path): Returns the given path unchanged (internal placeholder for potential long path handling).

WinPath Class

import { WinPath } from 'path.js';
import path from 'path.js';

// path.win32
const winPath = new WinPath();

PosixPath class

import { PosixPath } from 'path.js';
import path from 'path.js';

// path.posix
const posixPath = new PosixPath();

Usage

import { Path, WinPath, PosixPath } from 'path.js';
import path from 'path.js';

// Using the default Path class
const _path = new Path();
console.log(_path.normalize('/path/to/../file.ext')); // '/path/file.ext'

// Using the WinPath subclass or path.win32
const winPath = new WinPath();

console.log(winPath.normalize('C:\\path\\to\\..\\file.ext')); // 'C:\path\file.ext'

// Using the PosixPath subclass or path.posix
const posixPath = new PosixPath();

console.log(posixPath.normalize('/path/to/../file.ext')); // '/path/file.ext'