830925058278374d315496b6c70281dd9ad83581e2d08199a08d0ed55fa379d52dda237470075ade9330173a6dfd6a012984d69b03a4b77002e0b3f7ca945b 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # @jridgewell/resolve-uri
  2. > Resolve a URI relative to an optional base URI
  3. Resolve any combination of absolute URIs, protocol-realtive URIs, absolute paths, or relative paths.
  4. ## Installation
  5. ```sh
  6. npm install @jridgewell/resolve-uri
  7. ```
  8. ## Usage
  9. ```typescript
  10. function resolve(input: string, base?: string): string;
  11. ```
  12. ```js
  13. import resolve from '@jridgewell/resolve-uri';
  14. resolve('foo', 'https://example.com'); // => 'https://example.com/foo'
  15. ```
  16. | Input | Base | Resolution | Explanation |
  17. |-----------------------|-------------------------|--------------------------------|--------------------------------------------------------------|
  18. | `https://example.com` | _any_ | `https://example.com/` | Input is normalized only |
  19. | `//example.com` | `https://base.com/` | `https://example.com/` | Input inherits the base's protocol |
  20. | `//example.com` | _rest_ | `//example.com/` | Input is normalized only |
  21. | `/example` | `https://base.com/` | `https://base.com/example` | Input inherits the base's origin |
  22. | `/example` | `//base.com/` | `//base.com/example` | Input inherits the base's host and remains protocol relative |
  23. | `/example` | _rest_ | `/example` | Input is normalized only |
  24. | `example` | `https://base.com/dir/` | `https://base.com/dir/example` | Input is joined with the base |
  25. | `example` | `https://base.com/file` | `https://base.com/example` | Input is joined with the base without its file |
  26. | `example` | `//base.com/dir/` | `//base.com/dir/example` | Input is joined with the base's last directory |
  27. | `example` | `//base.com/file` | `//base.com/example` | Input is joined with the base without its file |
  28. | `example` | `/base/dir/` | `/base/dir/example` | Input is joined with the base's last directory |
  29. | `example` | `/base/file` | `/base/example` | Input is joined with the base without its file |
  30. | `example` | `base/dir/` | `base/dir/example` | Input is joined with the base's last directory |
  31. | `example` | `base/file` | `base/example` | Input is joined with the base without its file |