25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.9 KiB

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