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

os-slash

v1.0.3

Published

Cross-platform path utility for consistent slash normalization and manipulation

Readme

os-slash

Cross-platform, dependency-free JavaScript utility for consistent path normalization and manipulation.


Overview

os-slash is a lightweight utility library designed to handle file path transformations across multiple operating systems such as Windows, Linux, and macOS. It provides functions to:

  • Convert Windows backslashes (\) to POSIX-style forward slashes (/) and vice versa
  • Normalize paths by removing redundant slashes and trailing slashes
  • Detect absolute paths on different platforms
  • Safely join multiple path segments
  • Calculate relative paths between two paths
  • Manage trailing slashes (add or remove)
  • Preserve special Windows extended-length paths (\\?\) intact

The library is written in pure JavaScript, has zero dependencies, and is compatible with Node.js, browsers, React, Angular, and any JavaScript environment.


Installation

npm install os-slash

Usage

Import individual functions as needed in your project:

import {
	slash,
	backslash,
	normalize,
	ensureTrailingSlash,
	removeTrailingSlash,
	isAbsolute,
	join,
	relative,
} from "os-slash";

API Reference

slash(path: string): string

Converts Windows-style backslashes (\) to forward slashes (/). Leaves Windows extended-length paths (starting with \\?\) unchanged.

Example:

console.log(slash("C:\\Users\\Alice\\Documents"));
// Output: C:/Users/Alice/Documents

console.log(slash("\\\\?\\C:\\Very\\Long\\Path"));
// Output: \\?\C:\Very\Long\Path  (unchanged)

backslash(path: string): string

Converts forward slashes (/) to Windows backslashes ().

backslash(path: string): string

Example:

console.log(backslash("C:/Users/Alice/Documents"));
// Output: C:\Users\Alice\Documents

normalize(path: string): string

Normalizes paths by converting backslashes to forward slashes, removing redundant slashes, and trimming trailing slashes except root /. Preserves extended-length Windows paths.

Example:

console.log(normalize("C:\\Users\\\\Alice\\/Documents\\/"));
// Output: C:/Users/Alice/Documents

console.log(normalize("////usr//local///bin/"));
// Output: /usr/local/bin

ensureTrailingSlash(path: string): string

Adds a trailing slash (/) if it is missing.

Example:

console.log(ensureTrailingSlash("C:/Users/Alice"));
// Output: C:/Users/Alice/

console.log(ensureTrailingSlash("/usr/local/bin/"));
// Output: /usr/local/bin/

removeTrailingSlash(path: string): string

Removes trailing slash (/) unless the path is root (/).

Example:

console.log(removeTrailingSlash("C:/Users/Alice/"));
// Output: C:/Users/Alice

console.log(removeTrailingSlash("/"));
// Output: /

isAbsolute(path: string): boolean

Detects if a path is absolute on Windows or POSIX.

POSIX: paths starting with / Windows: paths starting with drive letter + :\ or UNC paths starting with \

Example:

console.log(isAbsolute("/usr/local/bin")); // true
console.log(isAbsolute("C:\\Windows")); // true
console.log(isAbsolute("Documents/file")); // false

join(...paths: string[]): string

Joins multiple path segments into a single normalized path using forward slashes.

Example:

console.log(join("C:/Users", "Alice", "Documents"));
// Output: C:/Users/Alice/Documents
console.log(join("/usr", "local//", "/bin/"));
// Output: /usr/local/bin

relative(from: string, to: string): string

Calculates relative path from from to to.

Example:

console.log(relative("/Users/Alice/Documents", "/Users/Alice/Music"));
// Output: ../Music
console.log(relative("C:/Projects/app/src", "C:/Projects/app/tests"));
// Output: ../tests