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

short-windows-path

v1.0.3

Published

Converts a Windows path to 8.3 short path

Downloads

32

Readme

short-windows-path

On Windows, this package tries to generate a short path using javascript, like C:\Program Files (x86)\Windows Media Player\Media Renderer\DMR_120.png to C:\PROGRA~2\WINDOW~4\MEDIAR~1\DMR_120.png. On other OS it returns the same path.

This can be used to bypass the 260 character limit on Windows by reducing the path length.

Table of Contents

Installation

npm install short-windows-path

Methods

This package can be used using CommonJS or ES Module.

// CommonJS
const shortWindowsPath = require('short-windows-path');

// ES Module
import * as shortWindowsPath from 'short-windows-path';

Simple example of package usage

const fs = require('fs');
const p = require('path');
const shortWindowsPath = require('short-windows-path');

shortWindowsPath.setCacheTime(5000); // In milliseconds

// Using shortWindowsPath.generate
(async function(){

	const files = await fs.promises.readdir('C:\\Program Files (x86)');

	let shortened = {};
	console.time('shortWindowsPath.generate');

	for(let key in files)
	{
		const file = files[key];
		const path = p.join('C:\\Program Files (x86)', file);

		let shortPath = await shortWindowsPath.generate(path, true);
		shortened[path] = shortPath;
	}

	console.timeEnd('shortWindowsPath.generate');
	console.log(shortened);

})();

// Using shortWindowsPath.generateSync
(function(){

	const files = fs.readdirSync('C:\\Program Files (x86)');

	let shortened = {};
	console.time('shortWindowsPath.generateSync');

	for(let key in files)
	{
		const file = files[key];
		const path = p.join('C:\\Program Files (x86)', file);

		let shortPath = shortWindowsPath.generateSync(path, true);
		shortened[path] = shortPath;
	}

	console.timeEnd('shortWindowsPath.generateSync');
	console.log(shortened);

})();

// Using shortWindowsPath.get
(async function(){

	const files = await fs.promises.readdir('C:\\Program Files (x86)');

	let shortened = {};
	console.time('shortWindowsPath.get');

	for(let key in files)
	{
		const file = files[key];
		const path = p.join('C:\\Program Files (x86)', file);

		let shortPath = await shortWindowsPath.get(path, true);
		shortened[path] = shortPath;
	}

	console.timeEnd('shortWindowsPath.get');
	console.log(shortened);

})();

setCacheTime

Set the cache time, some data is cached to optimize the generation of the short path and reduce disk reads, the cache may result in not generating the full short path of newly created folder/files if a short path has been generated in the same place recently.

const shortPath = shortWindowsPath.setCacheTime(Int time = 10000);
  • time Cache time in milliseconds.

generate

Try to generate the short path and check that it exists, this method is faster than shortWindowsPath.get but may not get the short path for some folder/files, also uses various read functions to generate the path (fs.promises.readdir, fs.promises.stat and fs.existsSync)

const shortPath = await shortWindowsPath.generate(String path, Boolean force = false);
  • force Force the sort path generation, by default the short path it is only generated if the path is equal or greater than 260 characters and it will stop generating when the path is below.

generateSync

Try to generate the short path and check that it exists synchronously, this method is faster than shortWindowsPath.get but may not get the short path for some folder/files, also uses various read functions to generate the path (fs.readdir, fs.stat and fs.existsSync)

const shortPath = shortWindowsPath.generateSync(String path, Boolean force = false);
  • force Force the sort path generation, by default the short path it is only generated if the path is equal or greater than 260 characters and it will stop generating when the path is below.

get

Get the shorten path using the command for %I in ("path") do @echo %~sI, this can be slower that other methods but it will return the correct short path.

const shortPath = await shortWindowsPath.get(String path, Boolean force = false);
  • force Force the sort path generation, by default the short path it is only generated if the path is equal or greater than 260 characters.