|
1 | | -# true-case-path |
| 1 | +# true-case-path |
| 2 | + |
| 3 | +## Usage |
| 4 | + |
| 5 | +`trueCasePathSync(<fileSystemPath>)` |
| 6 | + |
| 7 | +## Description |
| 8 | + |
| 9 | +Given a possibly case-variant version of an existing filesystem path, returns |
| 10 | +the case-exact, normalized version as stored in the filesystem. |
| 11 | + |
| 12 | +If the input path is a globbing *pattern* as defined by the 'glob' npm |
| 13 | +package, only the 1st match, if any, is returned. |
| 14 | +Only a literal input path guarantees an unambiguous result. |
| 15 | + |
| 16 | +If no matching path exists, undefined is returned. |
| 17 | +On case-SENSITIVE filesystems, a match will also be found, but if case |
| 18 | +variations of a given path exist, it is undefined which match is returned. |
| 19 | + |
| 20 | +## Platforms |
| 21 | + |
| 22 | +Windows, OSX, and Linux (though note the limitations with case-insensitive filesystems). |
| 23 | + |
| 24 | +## Limitations |
| 25 | + |
| 26 | +- Paths starting with `'./'` are acceptable, but paths starting with `'../'` |
| 27 | + are not - when in doubt, resolve with `fs.realPathSync()` first. |
| 28 | + An initial `'.'` and *interior* `'..'` instances are normalized, but a relative |
| 29 | + input path still results in a relative output path. If you want to ensure |
| 30 | + an absolute output path, apply `fs.realPathSync()` to the result. |
| 31 | +- On Windows, no attempt is made to case-correct the drive letter or UNC-share |
| 32 | + component of the path. |
| 33 | +- Unicode support: |
| 34 | + - Be sure to use UTF8 source-code files (with a BOM on Windows) |
| 35 | + - On OSX, the input path is automatically converted to NFD Unicode form |
| 36 | + to match how the filesystem stores names, but note that the result will |
| 37 | + invariably be NFD too (which makes no difference for ASCII-characters-only |
| 38 | + names). |
| 39 | + |
| 40 | +## Examples |
| 41 | + |
| 42 | +``` |
| 43 | +const trueCasePathSync = require('true-case-path') |
| 44 | +
|
| 45 | +trueCasePathSync('/users/guest') // OSX: -> '/Users/Guest' |
| 46 | +
|
| 47 | +trueCasePathSync('c:\\users\\all users') // Windows: -> 'c:\Users\All Users' |
| 48 | +``` |
0 commit comments