vscode-uri
Advanced tools
Comparing version 1.0.6 to 1.0.7
/** | ||
* @internal | ||
*/ | ||
export declare function setUriThrowOnMissingScheme(value: boolean): boolean; | ||
/** | ||
* Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986. | ||
@@ -15,3 +19,3 @@ * This class is a simple parser which creates the basic component parts | ||
*/ | ||
export default class URI implements UriComponents { | ||
export declare class URI implements UriComponents { | ||
static isUri(thing: any): thing is URI; | ||
@@ -43,3 +47,3 @@ /** | ||
*/ | ||
protected constructor(scheme: string, authority: string, path: string, query: string, fragment: string); | ||
protected constructor(scheme: string, authority?: string, path?: string, query?: string, fragment?: string, _strict?: boolean); | ||
/** | ||
@@ -87,3 +91,3 @@ * @internal | ||
*/ | ||
static parse(value: string): URI; | ||
static parse(value: string, _strict?: boolean): URI; | ||
/** | ||
@@ -102,3 +106,2 @@ * Creates a new URI from a file system path, e.g. `c:\my\files`, | ||
good.fragment === ''; | ||
const bad = URI.parse('file://' + '/coding/c#/project1'); | ||
@@ -121,3 +124,3 @@ bad.scheme === 'file'; | ||
/** | ||
* Creates a string presentation for this URI. It's guardeed that calling | ||
* Creates a string representation for this URI. It's guaranteed that calling | ||
* `URI.parse` with the result of this function creates an URI which is equal | ||
@@ -133,4 +136,7 @@ * to this URI. | ||
toString(skipEncoding?: boolean): string; | ||
toJSON(): object; | ||
static revive(data: UriComponents | any): URI; | ||
toJSON(): UriComponents; | ||
static revive(data: UriComponents | URI): URI; | ||
static revive(data: UriComponents | URI | undefined): URI | undefined; | ||
static revive(data: UriComponents | URI | null): URI | null; | ||
static revive(data: UriComponents | URI | undefined | null): URI | undefined | null; | ||
} | ||
@@ -137,0 +143,0 @@ export interface UriComponents { |
@@ -28,3 +28,20 @@ /*--------------------------------------------------------------------------------------------- | ||
var _doubleSlashStart = /^\/\//; | ||
function _validateUri(ret) { | ||
var _throwOnMissingSchema = true; | ||
/** | ||
* @internal | ||
*/ | ||
export function setUriThrowOnMissingScheme(value) { | ||
var old = _throwOnMissingSchema; | ||
_throwOnMissingSchema = value; | ||
return old; | ||
} | ||
function _validateUri(ret, _strict) { | ||
// scheme, must be set | ||
if (!ret.scheme) { | ||
if (_strict || _throwOnMissingSchema) { | ||
throw new Error("[UriError]: Scheme is missing: {scheme: \"\", authority: \"" + ret.authority + "\", path: \"" + ret.path + "\", query: \"" + ret.query + "\", fragment: \"" + ret.fragment + "\"}"); | ||
// } else { | ||
// console.warn(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`); | ||
} | ||
} | ||
// scheme, https://tools.ietf.org/html/rfc3986#section-3.1 | ||
@@ -53,2 +70,16 @@ // ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | ||
} | ||
// for a while we allowed uris *without* schemes and this is the migration | ||
// for them, e.g. an uri without scheme and without strict-mode warns and falls | ||
// back to the file-scheme. that should cause the least carnage and still be a | ||
// clear warning | ||
function _schemeFix(scheme, _strict) { | ||
if (_strict || _throwOnMissingSchema) { | ||
return scheme || _empty; | ||
} | ||
if (!scheme) { | ||
// console.trace('BAD uri lacks scheme, falling back to file-scheme.'); | ||
scheme = 'file'; | ||
} | ||
return scheme; | ||
} | ||
// implements a bit of https://tools.ietf.org/html/rfc3986#section-5 | ||
@@ -95,3 +126,4 @@ function _referenceResolution(scheme, path) { | ||
*/ | ||
function URI(schemeOrData, authority, path, query, fragment) { | ||
function URI(schemeOrData, authority, path, query, fragment, _strict) { | ||
if (_strict === void 0) { _strict = false; } | ||
if (typeof schemeOrData === 'object') { | ||
@@ -108,3 +140,3 @@ this.scheme = schemeOrData.scheme || _empty; | ||
else { | ||
this.scheme = schemeOrData || _empty; | ||
this.scheme = _schemeFix(schemeOrData, _strict); | ||
this.authority = authority || _empty; | ||
@@ -114,3 +146,3 @@ this.path = _referenceResolution(this.scheme, path || _empty); | ||
this.fragment = fragment || _empty; | ||
_validateUri(this); | ||
_validateUri(this, _strict); | ||
} | ||
@@ -129,3 +161,6 @@ } | ||
&& typeof thing.query === 'string' | ||
&& typeof thing.scheme === 'string'; | ||
&& typeof thing.scheme === 'string' | ||
&& typeof thing.fsPath === 'function' | ||
&& typeof thing.with === 'function' | ||
&& typeof thing.toString === 'function'; | ||
}; | ||
@@ -173,3 +208,3 @@ Object.defineProperty(URI.prototype, "fsPath", { | ||
var scheme = change.scheme, authority = change.authority, path = change.path, query = change.query, fragment = change.fragment; | ||
if (scheme === void 0) { | ||
if (scheme === undefined) { | ||
scheme = this.scheme; | ||
@@ -180,3 +215,3 @@ } | ||
} | ||
if (authority === void 0) { | ||
if (authority === undefined) { | ||
authority = this.authority; | ||
@@ -187,3 +222,3 @@ } | ||
} | ||
if (path === void 0) { | ||
if (path === undefined) { | ||
path = this.path; | ||
@@ -194,3 +229,3 @@ } | ||
} | ||
if (query === void 0) { | ||
if (query === undefined) { | ||
query = this.query; | ||
@@ -201,3 +236,3 @@ } | ||
} | ||
if (fragment === void 0) { | ||
if (fragment === undefined) { | ||
fragment = this.fragment; | ||
@@ -224,3 +259,4 @@ } | ||
*/ | ||
URI.parse = function (value) { | ||
URI.parse = function (value, _strict) { | ||
if (_strict === void 0) { _strict = false; } | ||
var match = _regexp.exec(value); | ||
@@ -230,3 +266,3 @@ if (!match) { | ||
} | ||
return new _URI(match[2] || _empty, decodeURIComponent(match[4] || _empty), decodeURIComponent(match[5] || _empty), decodeURIComponent(match[7] || _empty), decodeURIComponent(match[9] || _empty)); | ||
return new _URI(match[2] || _empty, decodeURIComponent(match[4] || _empty), decodeURIComponent(match[5] || _empty), decodeURIComponent(match[7] || _empty), decodeURIComponent(match[9] || _empty), _strict); | ||
}; | ||
@@ -246,3 +282,2 @@ /** | ||
good.fragment === ''; | ||
const bad = URI.parse('file://' + '/coding/c#/project1'); | ||
@@ -284,3 +319,3 @@ bad.scheme === 'file'; | ||
/** | ||
* Creates a string presentation for this URI. It's guardeed that calling | ||
* Creates a string representation for this URI. It's guaranteed that calling | ||
* `URI.parse` with the result of this function creates an URI which is equal | ||
@@ -311,4 +346,4 @@ * to this URI. | ||
var result = new _URI(data); | ||
result._fsPath = data.fsPath; | ||
result._formatted = data.external; | ||
result._fsPath = data._sep === _pathSepMarker ? data.fsPath : null; | ||
return result; | ||
@@ -319,3 +354,4 @@ } | ||
}()); | ||
export default URI; | ||
export { URI }; | ||
var _pathSepMarker = isWindows ? 1 : undefined; | ||
// tslint:disable-next-line:class-name | ||
@@ -360,2 +396,3 @@ var _URI = (function (_super) { | ||
res.fsPath = this._fsPath; | ||
res._sep = _pathSepMarker; | ||
} | ||
@@ -478,3 +515,2 @@ if (this._formatted) { | ||
* Compute `fsPath` for the given uri | ||
* @param uri | ||
*/ | ||
@@ -481,0 +517,0 @@ function _makeFsPath(uri) { |
/** | ||
* @internal | ||
*/ | ||
export declare function setUriThrowOnMissingScheme(value: boolean): boolean; | ||
/** | ||
* Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986. | ||
@@ -15,3 +19,3 @@ * This class is a simple parser which creates the basic component parts | ||
*/ | ||
export default class URI implements UriComponents { | ||
export declare class URI implements UriComponents { | ||
static isUri(thing: any): thing is URI; | ||
@@ -43,3 +47,3 @@ /** | ||
*/ | ||
protected constructor(scheme: string, authority: string, path: string, query: string, fragment: string); | ||
protected constructor(scheme: string, authority?: string, path?: string, query?: string, fragment?: string, _strict?: boolean); | ||
/** | ||
@@ -87,3 +91,3 @@ * @internal | ||
*/ | ||
static parse(value: string): URI; | ||
static parse(value: string, _strict?: boolean): URI; | ||
/** | ||
@@ -102,3 +106,2 @@ * Creates a new URI from a file system path, e.g. `c:\my\files`, | ||
good.fragment === ''; | ||
const bad = URI.parse('file://' + '/coding/c#/project1'); | ||
@@ -121,3 +124,3 @@ bad.scheme === 'file'; | ||
/** | ||
* Creates a string presentation for this URI. It's guardeed that calling | ||
* Creates a string representation for this URI. It's guaranteed that calling | ||
* `URI.parse` with the result of this function creates an URI which is equal | ||
@@ -133,4 +136,7 @@ * to this URI. | ||
toString(skipEncoding?: boolean): string; | ||
toJSON(): object; | ||
static revive(data: UriComponents | any): URI; | ||
toJSON(): UriComponents; | ||
static revive(data: UriComponents | URI): URI; | ||
static revive(data: UriComponents | URI | undefined): URI | undefined; | ||
static revive(data: UriComponents | URI | null): URI | null; | ||
static revive(data: UriComponents | URI | undefined | null): URI | undefined | null; | ||
} | ||
@@ -137,0 +143,0 @@ export interface UriComponents { |
@@ -38,3 +38,21 @@ var __extends = (this && this.__extends) || (function () { | ||
var _doubleSlashStart = /^\/\//; | ||
function _validateUri(ret) { | ||
var _throwOnMissingSchema = true; | ||
/** | ||
* @internal | ||
*/ | ||
function setUriThrowOnMissingScheme(value) { | ||
var old = _throwOnMissingSchema; | ||
_throwOnMissingSchema = value; | ||
return old; | ||
} | ||
exports.setUriThrowOnMissingScheme = setUriThrowOnMissingScheme; | ||
function _validateUri(ret, _strict) { | ||
// scheme, must be set | ||
if (!ret.scheme) { | ||
if (_strict || _throwOnMissingSchema) { | ||
throw new Error("[UriError]: Scheme is missing: {scheme: \"\", authority: \"" + ret.authority + "\", path: \"" + ret.path + "\", query: \"" + ret.query + "\", fragment: \"" + ret.fragment + "\"}"); | ||
// } else { | ||
// console.warn(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`); | ||
} | ||
} | ||
// scheme, https://tools.ietf.org/html/rfc3986#section-3.1 | ||
@@ -63,2 +81,16 @@ // ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | ||
} | ||
// for a while we allowed uris *without* schemes and this is the migration | ||
// for them, e.g. an uri without scheme and without strict-mode warns and falls | ||
// back to the file-scheme. that should cause the least carnage and still be a | ||
// clear warning | ||
function _schemeFix(scheme, _strict) { | ||
if (_strict || _throwOnMissingSchema) { | ||
return scheme || _empty; | ||
} | ||
if (!scheme) { | ||
// console.trace('BAD uri lacks scheme, falling back to file-scheme.'); | ||
scheme = 'file'; | ||
} | ||
return scheme; | ||
} | ||
// implements a bit of https://tools.ietf.org/html/rfc3986#section-5 | ||
@@ -105,3 +137,4 @@ function _referenceResolution(scheme, path) { | ||
*/ | ||
function URI(schemeOrData, authority, path, query, fragment) { | ||
function URI(schemeOrData, authority, path, query, fragment, _strict) { | ||
if (_strict === void 0) { _strict = false; } | ||
if (typeof schemeOrData === 'object') { | ||
@@ -118,3 +151,3 @@ this.scheme = schemeOrData.scheme || _empty; | ||
else { | ||
this.scheme = schemeOrData || _empty; | ||
this.scheme = _schemeFix(schemeOrData, _strict); | ||
this.authority = authority || _empty; | ||
@@ -124,3 +157,3 @@ this.path = _referenceResolution(this.scheme, path || _empty); | ||
this.fragment = fragment || _empty; | ||
_validateUri(this); | ||
_validateUri(this, _strict); | ||
} | ||
@@ -139,3 +172,6 @@ } | ||
&& typeof thing.query === 'string' | ||
&& typeof thing.scheme === 'string'; | ||
&& typeof thing.scheme === 'string' | ||
&& typeof thing.fsPath === 'function' | ||
&& typeof thing.with === 'function' | ||
&& typeof thing.toString === 'function'; | ||
}; | ||
@@ -183,3 +219,3 @@ Object.defineProperty(URI.prototype, "fsPath", { | ||
var scheme = change.scheme, authority = change.authority, path = change.path, query = change.query, fragment = change.fragment; | ||
if (scheme === void 0) { | ||
if (scheme === undefined) { | ||
scheme = this.scheme; | ||
@@ -190,3 +226,3 @@ } | ||
} | ||
if (authority === void 0) { | ||
if (authority === undefined) { | ||
authority = this.authority; | ||
@@ -197,3 +233,3 @@ } | ||
} | ||
if (path === void 0) { | ||
if (path === undefined) { | ||
path = this.path; | ||
@@ -204,3 +240,3 @@ } | ||
} | ||
if (query === void 0) { | ||
if (query === undefined) { | ||
query = this.query; | ||
@@ -211,3 +247,3 @@ } | ||
} | ||
if (fragment === void 0) { | ||
if (fragment === undefined) { | ||
fragment = this.fragment; | ||
@@ -234,3 +270,4 @@ } | ||
*/ | ||
URI.parse = function (value) { | ||
URI.parse = function (value, _strict) { | ||
if (_strict === void 0) { _strict = false; } | ||
var match = _regexp.exec(value); | ||
@@ -240,3 +277,3 @@ if (!match) { | ||
} | ||
return new _URI(match[2] || _empty, decodeURIComponent(match[4] || _empty), decodeURIComponent(match[5] || _empty), decodeURIComponent(match[7] || _empty), decodeURIComponent(match[9] || _empty)); | ||
return new _URI(match[2] || _empty, decodeURIComponent(match[4] || _empty), decodeURIComponent(match[5] || _empty), decodeURIComponent(match[7] || _empty), decodeURIComponent(match[9] || _empty), _strict); | ||
}; | ||
@@ -256,3 +293,2 @@ /** | ||
good.fragment === ''; | ||
const bad = URI.parse('file://' + '/coding/c#/project1'); | ||
@@ -294,3 +330,3 @@ bad.scheme === 'file'; | ||
/** | ||
* Creates a string presentation for this URI. It's guardeed that calling | ||
* Creates a string representation for this URI. It's guaranteed that calling | ||
* `URI.parse` with the result of this function creates an URI which is equal | ||
@@ -321,4 +357,4 @@ * to this URI. | ||
var result = new _URI(data); | ||
result._fsPath = data.fsPath; | ||
result._formatted = data.external; | ||
result._fsPath = data._sep === _pathSepMarker ? data.fsPath : null; | ||
return result; | ||
@@ -329,3 +365,4 @@ } | ||
}()); | ||
exports.default = URI; | ||
exports.URI = URI; | ||
var _pathSepMarker = isWindows ? 1 : undefined; | ||
// tslint:disable-next-line:class-name | ||
@@ -370,2 +407,3 @@ var _URI = (function (_super) { | ||
res.fsPath = this._fsPath; | ||
res._sep = _pathSepMarker; | ||
} | ||
@@ -488,3 +526,2 @@ if (this._formatted) { | ||
* Compute `fsPath` for the given uri | ||
* @param uri | ||
*/ | ||
@@ -491,0 +528,0 @@ function _makeFsPath(uri) { |
{ | ||
"name": "vscode-uri", | ||
"author": "Microsoft", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "The URI implementation that is used by VS Code and its extensions", | ||
@@ -6,0 +6,0 @@ "main": "./lib/umd/index.js", |
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
62195
1484