提交学习笔记专用
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.

67 lines
2.4 KiB

  1. ## vscode-uri
  2. [![Build Status](https://travis-ci.org/Microsoft/vscode-uri.svg?branch=master)](https://travis-ci.org/Microsoft/vscode-uri)
  3. This module contains the URI implementation that is used by VS Code and its extensions.
  4. It has support for parsing a string into `scheme`, `authority`, `path`, `query`, and
  5. `fragment` URI components as defined in: http://tools.ietf.org/html/rfc3986
  6. ```
  7. foo://example.com:8042/over/there?name=ferret#nose
  8. \_/ \______________/\_________/ \_________/ \__/
  9. | | | | |
  10. scheme authority path query fragment
  11. | _____________________|__
  12. / \ / \
  13. urn:example:animal:ferret:nose
  14. ```
  15. ## Usage
  16. ```js
  17. import { URI } from 'vscode-uri'
  18. // parse an URI from string
  19. let uri = URI.parse('https://code.visualstudio.com/docs/extensions/overview#frag')
  20. assert.ok(uri.scheme === 'https');
  21. assert.ok(uri.authority === 'code.visualstudio.com');
  22. assert.ok(uri.path === '/docs/extensions/overview');
  23. assert.ok(uri.query === '');
  24. assert.ok(uri.fragment === 'frag');
  25. assert.ok(uri.toString() === 'https://code.visualstudio.com/docs/extensions/overview#frag')
  26. // create an URI from a fs path
  27. let uri = URI.file('/users/me/c#-projects/');
  28. assert.ok(uri.scheme === 'file');
  29. assert.ok(uri.authority === '');
  30. assert.ok(uri.path === '/users/me/c#-projects/');
  31. assert.ok(uri.query === '');
  32. assert.ok(uri.fragment === '');
  33. assert.ok(uri.toString() === 'file:///users/me/c%23-projects/')
  34. ```
  35. ## Usage: Util
  36. This module also exports a `Utils` package which is an extension, not part of `vscode.Uri`, and useful for path-math. There is:
  37. * `Utils.joinPath(URI, paths): URI`
  38. * `Utils.resolvePath(URI, paths): URI`
  39. * `Utils.dirname(URI): string`
  40. * `Utils.basename(URI): string`
  41. * `Utils.extname(URI): string`
  42. All util use posix path-math as defined by the node.js path module.
  43. ## Contributing
  44. The source of this module is taken straight from the [vscode](https://github.com/microsoft/vscode)-sources and because of that issues and pull request should be created in that repository. Thanks and Happy Coding!
  45. ## Code of Conduct
  46. This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.