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

@igor.dvlpr/upath

v2.1.2

Published

🎍 Provides a universal way of formatting file-paths in Unix-like and Windows operating systems as an alternative to the built-in path.normalize(). 🧬

Downloads

118

Readme

uPath

🎍 Provides a universal way of formatting file-paths in Unix-like and Windows operating systems as an alternative to the built-in path.normalize(). 🧬

Why uPath? Simple. Working with file paths inside Strings in Windows + JavaScript is a hassle. By calling u(), the file path you provided is converted to your OS-preferred file path format, i.e. you can get away with writing "C:/Users/JohnDoe/" without having to worry about those backslashes that Windows uses. On the other hand, UNIX-like slashes in file paths are left as-is. An extra feature that uPath provides is redundant trailing slash removal.

✨Since version 2.0.0 upath is a hybrid module that supports both CommonJS (legacy) and ES modules, thanks to Modern Module.

✨Since version 1.2.0 support for UNC paths has been added, thanks to unc-path.

Usage

Install it first by doing

npm i @igor.dvlpr/upath

and call require in your code, i.e.:

// for CommonJS
const upath = require('@igor.dvlpr/upath')
// or for ESM
import * as upath from '@igor.dvlpr/upath'

// or destructure the object and import only needed function(s)
// e.g.
// for CommonJS
const { u } = require('@igor.dvlpr/upath')
// or for ESM
import { u } from '@igor.dvlpr/upath'

// do something cool with it

API

upath() => returns a proper file path depending on the host OS.

✨Note: upath() has an alias, named u() for your convenience.

Signature

upath(fsPath: string, addTrailingSlash: boolean = false): string
u(fsPath: string, addTrailingSlash: boolean = false): string

Parameters

fsPath: string // a string that represents the path to process,

addTrailingSlash: boolean = false
// a boolean that represents whether a trailing slash should be added to the fsPath or not

Example - Any OS

const { u } = require('@igor.dvlpr/upath')

console.log(u()) // returns ''
console.log(u('')) // returns ''
console.log(u(null)) // returns ''

Example - Windows OS

const { u } = require('@igor.dvlpr/upath')

console.log(u('C:/')) // returns 'C:\\'
console.log(u('C:/WINDOWS//////')) // returns 'C:\\WINDOWS\\'
console.log(u('C:/Users', true)) // returns 'C:\\Users\\'
console.log(u('\\\\ComputerName\\SharedFolder')) // returns '\\\\ComputerName\\SharedFolder'
console.log(u('//ComputerName/SharedFolder')) // returns '\\\\ComputerName\\SharedFolder'

Example - UNIX-like OS

const { u } = require('@igor.dvlpr/upath')

console.log(u('/mnt/')) // returns '/mnt/'
console.log(u('/usr/bin/////////')) // returns '/usr/bin/'
console.log(u('/usr/bin', true)) // returns '/usr/bin/'
console.log(u('//ComputerName/SharedFolder')) // returns '//ComputerName/SharedFolder'
console.log(u('\\\\ComputerName\\SharedFolder')) // returns '//ComputerName/SharedFolder'

uw() => returns a proper file path for Windows operating system.

Signature

uw(fsPath: string, addTrailingSlash: boolean = false): string

Parameters

fsPath: string // a string that represents the path to process,

addTrailingSlash: boolean = false
// a boolean that represents whether a trailing slash should be added to the fsPath or not

Example - Any OS

const { uw } = require('@igor.dvlpr/upath')

console.log(uw('C:/WINDOWS/System32')) // returns 'C:\\WINDOWS\\System32'
console.log(uw('//ComputerName/SharedFolder')) // returns '\\\\ComputerName\\SharedFolder'

ux() => returns a proper file path for UNIX-like operating systems.

Signature

ux(fsPath: string, addTrailingSlash: boolean = false): string

Parameters

fsPath: string // a string that represents the path to process,

addTrailingSlash: boolean = false
// a boolean that represents whether a trailing slash should be added to the fsPath or not

Example - Any OS

const { ux } = require('@igor.dvlpr/upath')

console.log(ux('/usr/local')) // returns '/usr/local'
console.log(ux('\\\\ComputerName\\SharedFolder'))
// returns '//ComputerName/SharedFolder'

✨ Since v.1.0.3 a string property named slash is exposed as well, provides an easy way to access file path OS-specific delimiter.

On Windows slash = '\\'.

On UNIX-like slash = '/'.