UNPKG

2.48 kBMarkdownView Raw
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
5This module contains the URI implementation that is used by VS Code and its extensions.
6It 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 | | | | |
13scheme authority path query fragment
14 | _____________________|__
15 / \ / \
16 urn:example:animal:ferret:nose
17```
18
19## Usage
20
21```js
22import { URI } from 'vscode-uri'
23
24// parse an URI from string
25
26let uri = URI.parse('https://code.visualstudio.com/docs/extensions/overview#frag')
27
28assert.ok(uri.scheme === 'https');
29assert.ok(uri.authority === 'code.visualstudio.com');
30assert.ok(uri.path === '/docs/extensions/overview');
31assert.ok(uri.query === '');
32assert.ok(uri.fragment === 'frag');
33assert.ok(uri.toString() === 'https://code.visualstudio.com/docs/extensions/overview#frag')
34
35
36// create an URI from a fs path
37
38let uri = URI.file('/users/me/c#-projects/');
39
40assert.ok(uri.scheme === 'file');
41assert.ok(uri.authority === '');
42assert.ok(uri.path === '/users/me/c#-projects/');
43assert.ok(uri.query === '');
44assert.ok(uri.fragment === '');
45assert.ok(uri.toString() === 'file:///users/me/c%23-projects/')
46```
47
48## Usage: Util
49
50This 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
58All util use posix path-math as defined by the node.js path module.
59
60
61## Contributing
62
63The 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
67This 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.