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 🙏

© 2024 – Pkg Stats / Ryan Hefner

crosspath

v2.0.0

Published

A wrapper around the path module that always normalizes to POSIX (including converting backslashes to forward slashes)

Downloads

357,494

Readme

A wrapper around the path module that always normalizes to POSIX (including converting backslashes to forward slashes)

Description

The built-in path module in Node.js provides utilities for working with file and directory paths in Node.js. The default operation of it varies based on the operating system on which Node.js is running.

While this is generally a good thing, there are situations where you might want to normalize paths such that they always follow POSIX formatting. While the path module does export POSIX specific implementations via the path.posix property, it is not really sufficient, as it doesn't convert windows-style paths with backslashes into forward slashes.

crosspath is a drop-in replacement for path that wraps it to ensure that paths are always POSIX-formatted, including on Windows. You can still access the underlying implementations via the native property, which is useful when you do need to convert back into OS-specific paths, for example when writing to the file system

Features

  • A drop-in replacement
  • Tiny as it relies on the implementations of the underlying path module

Backers

| | | | | | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | BubblesTwitter: @usebubbles | Christopher Blanchard | Ideal Postcodes | Xerox | Trent Raymond | scrubtheweb |

Patreon

Table of Contents

Install

npm

$ npm install crosspath

Yarn

$ yarn add crosspath

pnpm

$ pnpm add crosspath

Usage

Simply import what you need, exactly as you would with the path module:

// Import just what you need:
import {join, relative} from "crosspath";

// or simply:
import path from "crosspath";

// Becomes 'C:/foo/bar'
path.join("C:\\foo", "\\bar");

// Becomes '../bar'
path.relative("C:\\foo", "C:\\bar");

If you want to use the native path helpers and constants without the POSIX normalization, these are all accessible via the path.native property:

import path from "crosspath";

// Becomes 'C:\foo\bar' on Windows and C:\foo/\bar on POSIX-systems
path.native.join("C:\\foo", "\\bar");

// Becomes '..\bar' on Windows and ../C:\bar on POSIX-systems
path.native.relative("C:\\foo", "C:\\bar");

This can be useful when you do want the paths to respect the OS convention, such as when you interact with the file system.

Contributing

Do you want to contribute? Awesome! Please follow these recommendations.

Maintainers

| | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Frederik WessbergTwitter: @FredWessbergGithub: @wessbergLead Developer |

FAQ

Why not simply use path.posix always? Isn't this library redundant?

No, not quite (but close). While it is true that path.posix can be used from Windows, it has the fundamental shortcoming that it doesn't convert backslashes into forward slashes. This is not a mistake, but rather a design decision. This library makes another decision and unifies the behavior between the two approaches to make it easier to build cross-platform libraries and tools.

License

MIT © Frederik Wessberg (@FredWessberg) (Website)