https://github.com/wasabithumb/winsn
Windows Path Short Name for NodeJS
https://github.com/wasabithumb/winsn
javascript node-gyp nodejs shortpath win32 windows
Last synced: 26 days ago
JSON representation
Windows Path Short Name for NodeJS
- Host: GitHub
- URL: https://github.com/wasabithumb/winsn
- Owner: WasabiThumb
- License: apache-2.0
- Created: 2023-10-03T11:46:07.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-03T11:49:53.000Z (over 2 years ago)
- Last Synced: 2025-08-04T13:37:45.973Z (10 months ago)
- Topics: javascript, node-gyp, nodejs, shortpath, win32, windows
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# winsn
Windows Path Short Name ([GetShortPathNameW](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getshortpathnamew)) for NodeJS
## Usage
Convert a long path name to short path name:
```js
const shortName = require("winsn");
shortName("C:\\Program Files"); // C:\PROGRA~1
```
Handle non-Windows OS:
```js
const shortName = require("winsn");
if (shortName.isAvailable()) {
shortName("C:\\Program Files (x86)"); // C:\PROGRA~2
}
```
Handle potentially invalid long path name:
```js
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
- 🤷