1 | ## vscode-uri
|
2 |
|
3 | [![Build Status](https://travis-ci.org/Microsoft/vscode-uri.svg?branch=master)](https://travis-ci.org/Microsoft/vscode-uri)
|
4 |
|
5 | This module contains the URI implementation that is used by VS Code and its extensions.
|
6 | It has support for parsing a string into `scheme`, `authority`, `path`, `query`, and
|
7 | `fragment` URI components as defined in: http://tools.ietf.org/html/rfc3986
|
8 |
|
9 | ```
|
10 | foo://example.com:8042/over/there?name=ferret#nose
|
11 | \_/ \______________/\_________/ \_________/ \__/
|
12 | | | | | |
|
13 | scheme authority path query fragment
|
14 | | _____________________|__
|
15 | / \ / \
|
16 | urn:example:animal:ferret:nose
|
17 | ```
|
18 |
|
19 | ## Usage
|
20 |
|
21 | ```js
|
22 | import { URI } from 'vscode-uri'
|
23 |
|
24 | // parse an URI from string
|
25 |
|
26 | let uri = URI.parse('https://code.visualstudio.com/docs/extensions/overview#frag')
|
27 |
|
28 | assert.ok(uri.scheme === 'https');
|
29 | assert.ok(uri.authority === 'code.visualstudio.com');
|
30 | assert.ok(uri.path === '/docs/extensions/overview');
|
31 | assert.ok(uri.query === '');
|
32 | assert.ok(uri.fragment === 'frag');
|
33 | assert.ok(uri.toString() === 'https://code.visualstudio.com/docs/extensions/overview#frag')
|
34 |
|
35 |
|
36 | // create an URI from a fs path
|
37 |
|
38 | let uri = URI.file('/users/me/c#-projects/');
|
39 |
|
40 | assert.ok(uri.scheme === 'file');
|
41 | assert.ok(uri.authority === '');
|
42 | assert.ok(uri.path === '/users/me/c#-projects/');
|
43 | assert.ok(uri.query === '');
|
44 | assert.ok(uri.fragment === '');
|
45 | assert.ok(uri.toString() === 'file:///users/me/c%23-projects/')
|
46 | ```
|
47 |
|
48 | ## Usage: Util
|
49 |
|
50 | This module also exports a `Utils` package which is an extension, not part of `vscode.Uri`, and useful for path-math. There is:
|
51 |
|
52 | * `Utils.joinPath(URI, paths): URI`
|
53 | * `Utils.resolvePath(URI, paths): URI`
|
54 | * `Utils.dirname(URI): string`
|
55 | * `Utils.basename(URI): string`
|
56 | * `Utils.extname(URI): string`
|
57 |
|
58 | All util use posix path-math as defined by the node.js path module.
|
59 |
|
60 |
|
61 | ## Contributing
|
62 |
|
63 | 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!
|
64 |
|
65 | ## Code of Conduct
|
66 |
|
67 | 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.
|