vscode-uri
Advanced tools
Comparing version 0.0.1 to 0.0.2
/** | ||
* Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986. | ||
* Uniform Resource Identifier (Uri) http://tools.ietf.org/html/rfc3986. | ||
* This class is a simple parser which creates the basic component paths | ||
@@ -54,8 +54,20 @@ * (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation | ||
/** | ||
* Returns a string representing the corresponding file system path of this URI. | ||
* Returns a string representing the corresponding file system path of this Uri. | ||
* Will handle UNC paths and normalize windows drive letters to lower-case. Also | ||
* uses the platform specific path separator. Will *not* validate the path for | ||
* invalid characters and semantics. Will *not* look at the scheme of this URI. | ||
* invalid characters and semantics. Will *not* look at the scheme of this Uri. | ||
*/ | ||
fsPath: string; | ||
/** | ||
* Derive a new Uri from this Uri. | ||
* | ||
* @param change An object that describes a change to this Uri. | ||
* @return A new Uri that reflects the given change. Will return `this` Uri if the change | ||
* is not changing anything. | ||
* @sample ``` | ||
let file = Uri.parse('before:some/file/path'); | ||
let other = file.with({ scheme: 'after' }); | ||
assert.ok(other.toString() === 'after:some/file/path'); | ||
* ``` | ||
*/ | ||
with(change: { | ||
@@ -68,6 +80,32 @@ scheme?: string; | ||
}): Uri; | ||
/** | ||
* Create an Uri from uri components. | ||
* | ||
* @param components An object containing the Uri components | ||
* @return A new Uri instance | ||
*/ | ||
static from(components: { | ||
scheme?: string; | ||
authority?: string; | ||
path?: string; | ||
query?: string; | ||
fragment?: string; | ||
}): Uri; | ||
/** | ||
* Create an Uri from a string. Will throw if the given value is not | ||
* valid. | ||
* | ||
* @param value The string value of an Uri. | ||
* @return A new Uri instance. | ||
*/ | ||
static parse(value: string): Uri; | ||
/** | ||
* Create an Uri from a file system path. The [scheme](#Uri.scheme) | ||
* will be `file`. | ||
* | ||
* @param path A file system or UNC path. | ||
* @return A new Uri instance. | ||
*/ | ||
static file(path: string): Uri; | ||
private static _parseComponents(value); | ||
static create(scheme?: string, authority?: string, path?: string, query?: string, fragment?: string): Uri; | ||
private static _validate(ret); | ||
@@ -74,0 +112,0 @@ /** |
@@ -6,10 +6,2 @@ /*--------------------------------------------------------------------------------------------- | ||
'use strict'; | ||
var isWindows; | ||
if (typeof process === 'object') { | ||
isWindows = process.platform === 'win32'; | ||
} | ||
else if (typeof navigator === 'object') { | ||
var userAgent = navigator.userAgent; | ||
isWindows = userAgent.indexOf('Windows') >= 0; | ||
} | ||
function _encode(ch) { | ||
@@ -26,3 +18,3 @@ return '%' + ch.charCodeAt(0).toString(16).toUpperCase(); | ||
/** | ||
* Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986. | ||
* Uniform Resource Identifier (Uri) http://tools.ietf.org/html/rfc3986. | ||
* This class is a simple parser which creates the basic component paths | ||
@@ -107,6 +99,6 @@ * (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation | ||
/** | ||
* Returns a string representing the corresponding file system path of this URI. | ||
* Returns a string representing the corresponding file system path of this Uri. | ||
* Will handle UNC paths and normalize windows drive letters to lower-case. Also | ||
* uses the platform specific path separator. Will *not* validate the path for | ||
* invalid characters and semantics. Will *not* look at the scheme of this URI. | ||
* invalid characters and semantics. Will *not* look at the scheme of this Uri. | ||
*/ | ||
@@ -139,2 +131,14 @@ get: function () { | ||
// ---- modify to new ------------------------- | ||
/** | ||
* Derive a new Uri from this Uri. | ||
* | ||
* @param change An object that describes a change to this Uri. | ||
* @return A new Uri that reflects the given change. Will return `this` Uri if the change | ||
* is not changing anything. | ||
* @sample ``` | ||
let file = Uri.parse('before:some/file/path'); | ||
let other = file.with({ scheme: 'after' }); | ||
assert.ok(other.toString() === 'after:some/file/path'); | ||
* ``` | ||
*/ | ||
Uri.prototype.with = function (change) { | ||
@@ -166,2 +170,18 @@ if (!change) { | ||
// ---- parse & validate ------------------------ | ||
/** | ||
* Create an Uri from uri components. | ||
* | ||
* @param components An object containing the Uri components | ||
* @return A new Uri instance | ||
*/ | ||
Uri.from = function (components) { | ||
return new Uri().with(components); | ||
}; | ||
/** | ||
* Create an Uri from a string. Will throw if the given value is not | ||
* valid. | ||
* | ||
* @param value The string value of an Uri. | ||
* @return A new Uri instance. | ||
*/ | ||
Uri.parse = function (value) { | ||
@@ -178,2 +198,9 @@ var ret = new Uri(); | ||
}; | ||
/** | ||
* Create an Uri from a file system path. The [scheme](#Uri.scheme) | ||
* will be `file`. | ||
* | ||
* @param path A file system or UNC path. | ||
* @return A new Uri instance. | ||
*/ | ||
Uri.file = function (path) { | ||
@@ -225,17 +252,14 @@ var ret = new Uri(); | ||
}; | ||
Uri.create = function (scheme, authority, path, query, fragment) { | ||
return new Uri().with({ scheme: scheme, authority: authority, path: path, query: query, fragment: fragment }); | ||
}; | ||
Uri._validate = function (ret) { | ||
// validation | ||
// path, http://tools.ietf.org/html/rfc3986#section-3.3 | ||
// If a URI contains an authority component, then the path component | ||
// must either be empty or begin with a slash ("/") character. If a URI | ||
// If a Uri contains an authority component, then the path component | ||
// must either be empty or begin with a slash ("/") character. If a Uri | ||
// does not contain an authority component, then the path cannot begin | ||
// with two slash characters ("//"). | ||
if (ret.authority && ret.path && ret.path[0] !== '/') { | ||
throw new Error('[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character'); | ||
throw new Error('[UriError]: If a Uri contains an authority component, then the path component must either be empty or begin with a slash ("/") character'); | ||
} | ||
if (!ret.authority && ret.path.indexOf('//') === 0) { | ||
throw new Error('[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")'); | ||
throw new Error('[UriError]: If a Uri does not contain an authority component, then the path cannot begin with two slash characters ("//")'); | ||
} | ||
@@ -332,1 +356,9 @@ }; | ||
exports.default = Uri; | ||
var isWindows; | ||
if (typeof process === 'object') { | ||
isWindows = process.platform === 'win32'; | ||
} | ||
else if (typeof navigator === 'object') { | ||
var userAgent = navigator.userAgent; | ||
isWindows = userAgent.indexOf('Windows') >= 0; | ||
} |
{ | ||
"name": "vscode-uri", | ||
"author": "Microsoft", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "The URI implementation that is used by VS Code and its extensions", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"compile": "tsc && tsc -p spec/tsconfig.json", | ||
"test": "npm run compile && mocha --ui tdd spec/", | ||
"prepublish": "npm run test" | ||
}, | ||
@@ -19,5 +21,6 @@ "repository": { | ||
"homepage": "https://github.com/Microsoft/vscode-uri#readme", | ||
"dependencies": { | ||
"devDependencies": { | ||
"mocha": "^2.5.3", | ||
"typescript": "^1.8.10" | ||
} | ||
} |
@@ -1,2 +0,42 @@ | ||
# vscode-uri | ||
The URI implementation that is used in VS Code and its extensions. | ||
## vscode-uri | ||
This module contains the URI implementation that is used by VS Code and its extensions. | ||
It has support for parsing a string into `scheme`, `authority`, `path`, `query`, and | ||
`fragment` URI components as defined in: http://tools.ietf.org/html/rfc3986 | ||
``` | ||
foo://example.com:8042/over/there?name=ferret#nose | ||
\_/ \______________/\_________/ \_________/ \__/ | ||
| | | | | | ||
scheme authority path query fragment | ||
| _____________________|__ | ||
/ \ / \ | ||
urn:example:animal:ferret:nose | ||
``` | ||
## Usage | ||
```js | ||
import Uri from ('vscode-uri') | ||
// parse an Uri from string | ||
let uri = Uri.parse('https://code.visualstudio.com/docs/extensions/overview#frag') | ||
assert.ok(uri.scheme === 'https'); | ||
assert.ok(uri.authority === 'code.visualstudio.com'); | ||
assert.ok(uri.path === '/docs/extensions/overview'); | ||
assert.ok(uri.query === ''); | ||
assert.ok(uri.fragment === 'frag'); | ||
// create an Uri from a fs path | ||
let uri = Uri.file('/users/me/c#-projects/'); | ||
assert.ok(uri.scheme === 'file'); | ||
assert.ok(uri.authority === ''); | ||
assert.ok(uri.path === '/users/me/c#-projects/'); | ||
assert.ok(uri.query === ''); | ||
assert.ok(uri.fragment === ''); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
19642
0
473
1
42
2
- Removedtypescript@^1.8.10
- Removedtypescript@1.8.10(transitive)