Acme.BookStore.HttpApi.Host/node_modules/upath/readme.md
(开头部分) 17KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
# upath v1.1.2
[](https://travis-ci.org/anodynos/upath)
[](https://david-dm.org/anodynos/upath)
A drop-in replacement / proxy to nodejs's `path` that:
* Replaces the windows `\` with the unix `/` in all string params & results. This has significant positives - see below.
* Adds **filename extensions** functions `addExt`, `trimExt`, `removeExt`, `changeExt`, and `defaultExt`.
* Add a `normalizeSafe` function to preserve any meaningful leading `./` & a `normalizeTrim` which additionally trims any useless ending `/`.
* Plus a helper `toUnix` that simply converts `\` to `/` and consolidates duplicates.
**Useful note: these docs are actually auto generated from [specs](https://github.com/anodynos/upath/blob/master/source/spec/upath-spec.coffee), running on Linux.**
Notes:
* `upath.sep` is set to `'/'` for seamless replacement (as of 1.0.3).
* upath has no runtime dependencies, except built-in `path` (as of 1.0.4)
* travis-ci tested in node versions 4 to 10
## Why ?
Normal `path` doesn't convert paths to a unified format (ie `/`) before calculating paths (`normalize`, `join`), which can lead to numerous problems.
Also path joining, normalization etc on the two formats is not consistent, depending on where it runs. Running `path` on Windows yields different results than when it runs on Linux / Mac.
In general, if you code your paths logic while developing on Unix/Mac and it runs on Windows, you may run into problems when using `path`.
Note that using **Unix `/` on Windows** works perfectly inside nodejs (and other languages), so there's no reason to stick to the Windows legacy at all.
##### Examples / specs
Check out the different (improved) behavior to vanilla `path`:
`upath.normalize(path)` --returns-->
✓ `'c:/windows/nodejs/path'` ---> `'c:/windows/nodejs/path'` // equal to `path.normalize()`
✓ `'c:/windows/../nodejs/path'` ---> `'c:/nodejs/path'` // equal to `path.normalize()`
✓ `'c:\\windows\\nodejs\\path'` ---> `'c:/windows/nodejs/path'` // `path.normalize()` gives `'c:\windows\nodejs\path'`
✓ `'c:\\windows\\..\\nodejs\\path'` ---> `'c:/nodejs/path'` // `path.normalize()` gives `'c:\windows\..\nodejs\path'`
✓ `'//windows\\unix/mixed'` ---> `'/windows/unix/mixed'` // `path.normalize()` gives `'/windows\unix/mixed'`
✓ `'\\windows//unix/mixed'` ---> `'/windows/unix/mixed'` // `path.normalize()` gives `'\windows/unix/mixed'`
✓ `'////\\windows\\..\\unix/mixed/'` ---> `'/unix/mixed/'` // `path.normalize()` gives `'/\windows\..\unix/mixed/'`
Joining paths can also be a problem:
`upath.join(paths...)` --returns-->
✓ `'some/nodejs/deep', '../path'` ---> `'some/nodejs/path'` // equal to `path.join()`
✓ `'some/nodejs\\windows', '../path'` ---> `'some/nodejs/path'` // `path.join()` gives `'some/path'`
✓ `'some\\windows\\only', '..\\path'` ---> `'some/windows/path'` // `path.join()` gives `'some\windows\only/..\path'`
Parsing with `path.parse()` should also be consistent across OSes:
后面还有 275 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
