You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
2.8 KiB

3 months ago
  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 |