winsn
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

winsn

Windows Path Short Name (GetShortPathNameW) for NodeJS

Usage

Convert a long path name to short path name:

const shortName = require("winsn");
shortName("C:\\Program Files"); // C:\PROGRA~1

Handle non-Windows OS:

const shortName = require("winsn");
if (shortName.isAvailable()) {
    shortName("C:\\Program Files (x86)"); // C:\PROGRA~2
}

Handle potentially invalid long path name:

const shortName = require("winsn");
const long = "Q:\\nonexistent";
let short;

short = shortName.elseNull(long); // null (all host machines!)
console.log(`${long} -> ${short}`); // Q:\nonexistent -> null

short = shortName.elseLong(long); // Q:\nonexistent
console.log(`${long} -> ${short}`); // Q:\nonexistent -> Q:\nonexistent

Why

  • Flexibility in cross-platform toolkits that assume unix-like paths where no whitespace or quotes are allowed
  • Reduce console clutter
  • 🤷

/winsn/

    Package Sidebar

    Install

    npm i winsn

    Weekly Downloads

    0

    Version

    1.0.0

    License

    Apache-2.0

    Unpacked Size

    19.3 kB

    Total Files

    12

    Last publish

    Collaborators

    • wasabithumbs