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

path-interop

v1.0.2

Published

Provides path format conversion between Windows and Linux including path seperator conversion and environment variable expansion.

Downloads

11

Readme

path-interop

Build Status NPM MIT

Provides path format conversion between Windows and Linux including path seperator conversion and environment variable expansion.

Allows you to add Linux path format interoperability into your Windows/Linux cross-platform apps.

Install

npm install --save path-interop

Usage

// Single instance
const PathInterop = require('path-interop');

// When multiple instances are required, use clone()
const interop1 = require('path-interop');
const interop2 = interop1.clone();

Functions

windowsToLinux(path, expand)

Converts path format from Windows to Linux with/without environment variable expansion.

Specify true for expand in order to expand environment variables like %VAR%.

Otherwise, variable names are preserved. For example, windowsToLinux('%USERPROFILE%/') will return '~/' without expansion.

NOTE: Windows Drive letter and colon (C:) is not convertible to Linux format. Therefore, by default it is preserved. For exmaple, windowsToLinux('C:\\') returns 'C:/'. You can change this behavior by using driveLetterConverter option.

linuxToWindows(path, expand)

Converts path format from Linux to Windows with/without environment variable expansion.

Specify true for expand in order to expand environment variables like ~/, $VAR or ${VAR}.

Otherwise, variable names are preserved. For example, linuxToWindows('~/') will return '%USERPROFILE%/' without expansion.

NOTE: ~otherUserName/ is unsupported

toLinux(path, expand)

Forcely converts path format to Linux with/without environment variable expansion.

Equivalent to windowsToLinux(linuxToWindows(path), expand).

toWindows(path, expand)

Forcely converts path format to Windows with/without environment variable expansion.

Equivalent to linuxToWindows(windowsToLinux(path), expand).

toSystem(path, expand)

Forcely converts path format to current platform. If process.platform is win32 internally calls toWindows, otherwise calls toLinux.

Options

driveLetterConverter

Specify converter function to convert drive letter.

// Default value (Preserve)
PathInterop.driveLetterConverter = letter => {
  return letter + ':'
}

// For MSYS2 (C:\ => /c)
PathInterop.driveLetterConverter = letter => {
    return '/' + letter.toLowerCase(); 
}

// Just only remove drive letter and colon
PathInterop.driveLetterConverter = letter => {
  return '';
}

caseInsensitivePlatforms

Array of platform name that store case-insensitive variable name like Windows. Return values of process.platform() are used.

// Default value
PathInterop.caseInsensitivePlatforms = [ 'win32' ];

// Custom additional value
PathInterop.caseInsensitivePlatforms.push('futurePlatform');

// Custom value
PathInterop.caseInsensitivePlatforms = [ 'win32', 'futurePlatform' ]

linuxEnvToWindowsEnv

Object that represent conversion table of environment variable name (Linux to Windows).

// Default value
PathInterop.linuxEnvToWindowsEnv.HOME = 'USERPROFILE';

// Custom additonal value
PathInterop.linuxEnvToWindowsEnv.LINUXENV = 'WINENV';

// Custom overwrite
PathInterop.linuxEnvToWindowsEnv = { LINUXENV: 'WINENV' };

windowsEnvToLinuxEnv

Object that represent conversion table of environment variable name (Windows to Linux).

// Default value
PathInterop.windowsEnvToLinuxEnv.USERPROFILE = 'HOME';

// Custom additonal value
PathInterop.windowsEnvToLinuxEnv.WINENV = 'LINUXENV';

// Custom overwrite
PathInterop.windowsEnvToLinuxEnv = { WINENV: 'LINUXENV' };

clone

Creates a new object that is a copy of the current instance.

var p1 = require('path-interop');
var p2 = require('path-interop');

console.log(p1 === p2); // True (Because of require-cache)

var p3 = p1.clone();

console.log(p1 === p3); // False
console.log(p1.linuxEnvToWindowsEnv 
  === p3.linuxEnvToWindowsEnv); // False

License

Distributed under the MIT license

Copyright (C) 2016 Retorillo