Gathering detailed insights and metrics for normalized-tmpdir
Gathering detailed insights and metrics for normalized-tmpdir
Gathering detailed insights and metrics for normalized-tmpdir
Gathering detailed insights and metrics for normalized-tmpdir
npm install normalized-tmpdir
Typescript
Module System
Node Version
NPM Version
69.1
Supply Chain
87
Quality
75.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
15,014
Last Day
4
Last Week
21
Last Month
110
Last Year
2,587
54 Commits
1 Watching
2 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
normalized-tmpdir@1.0.1
Unpacked Size
11.96 kB
Size
4.62 kB
File Count
5
NPM Version
8.12.1
Node Version
16.15.1
Publised On
26 Jan 2023
Cumulative downloads
Total Downloads
Last day
-63.6%
4
Compared to previous day
Last week
-55.3%
21
Compared to previous week
Last month
-1.8%
110
Compared to previous month
Last year
-78.8%
2,587
Compared to previous year
6
Normalize the value returned from os.tmpdir()
to eliminate OS-specific symlinks and naming variations. This is mainly useful in tests that rely on path comparisons.
os.tmpdir()
may return /var/...
which is a symlink to /private/var/...
. This can be fixed with fs.realpathSync()
.
On Windows, os.tmpdir()
uses the value of the TEMP
or TMP
environment variables. In some cases (including on GitHub Actions runners), if the user directory name is more than 8 characters, these variables may include a short (8.3) name for the user directory.
Node doesn't have an API to convert between short and long names. There are various possible workarounds, including:
cmd
built-in or one-liner for this. However, attrib.exe
appears to always expand the last path segment into a long path.os.homedir()
(as long as it's the same directory and not a short name).This package currently tries the os.homedir()
workaround first (since it doesn't require spawning a process), and tries iterating through path segments and calling attrib.exe
as a fallback.
normalizedTmpdir(options?): string
Return a normalized version of os.tmpdir()
.
1import { normalizedTmpdir } from 'normalized-tmpdir'; 2 3const tmpdir = normalizedTmpdir();
The function accepts an options object:
console?: boolean | { warn: typeof console['warn'] }
: By default, the library does not log warnings if normalization fails. If this option is true, log warnings to the default console. If a console object is provided, use it for logging.To avoid potentially doing the Windows normalization on every call, the calculated full path is cached.
If you have Jest tests that mock the console methods, but you want errors from normalizedTmpdir
to display anyway (for easier debugging), you can do the following:
1import { normalizedTmpdir } from 'normalized-tmpdir'; 2import realConsole from 'console'; 3 4const tmpdir = normalizedTmpdir({ console: realConsole });
expandShortPath(shortPath: string): string | false
On Windows only: expand an absolute path with short (8.3) segments to a long path. If the user name is the only short segment, and shortPath
is under os.homedir()
(which must not include any short segments), uses os.homedir()
as a replacement for the short part. Otherwise, expands each short segment of the path using attrib.exe
.
Returns the expanded path, or false if not on Windows, it's an unsupported type of path, or there's an error expanding any of the segments.
1import os from 'os'; 2import { expandShortPath } from 'normalized-tmpdir'; 3 4if (os.platform() === 'win32') { 5 // Example: expand a short path to C:\Users\VeryLongName 6 const longPath = expandShortPath('C:\\Users\\VERYLO~1'); 7}
No vulnerabilities found.
No security vulnerabilities found.