@stoplight/common
Advanced tools
Comparing version 0.0.31 to 0.0.32-beta.0
@@ -1,14 +0,1 @@ | ||
import { Emitter } from './event'; | ||
import { Event, IDisposable } from './types'; | ||
export declare function create(func: () => void): IDisposable; | ||
export declare const NOOP: IDisposable; | ||
export declare class Collection implements IDisposable { | ||
protected readonly disposables: IDisposable[]; | ||
protected readonly onDisposeEmitter: Emitter<void>; | ||
readonly onDispose: Event<void>; | ||
readonly disposed: boolean; | ||
dispose(): void; | ||
push(disposable: IDisposable): IDisposable; | ||
pushAll(disposables: IDisposable[]): IDisposable[]; | ||
protected checkDisposed(): void; | ||
} | ||
export * from '@stoplight/disposable'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var event_1 = require("./event"); | ||
function create(func) { | ||
return { | ||
dispose: func, | ||
}; | ||
} | ||
exports.create = create; | ||
exports.NOOP = create(function () { | ||
// nada | ||
}); | ||
var Collection = /** @class */ (function () { | ||
function Collection() { | ||
this.disposables = []; | ||
this.onDisposeEmitter = new event_1.Emitter(); | ||
} | ||
Object.defineProperty(Collection.prototype, "onDispose", { | ||
get: function () { | ||
return this.onDisposeEmitter.event; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Collection.prototype, "disposed", { | ||
get: function () { | ||
return this.disposables.length === 0; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Collection.prototype.dispose = function () { | ||
if (this.disposed) | ||
return; | ||
while (!this.disposed) { | ||
this.disposables.pop().dispose(); | ||
} | ||
this.checkDisposed(); | ||
}; | ||
Collection.prototype.push = function (disposable) { | ||
var _this = this; | ||
this.disposables.push(disposable); | ||
var originalDispose = disposable.dispose.bind(disposable); | ||
var toRemove = create(function () { | ||
var index = _this.disposables.indexOf(disposable); | ||
if (index !== -1) { | ||
_this.disposables.splice(index, 1); | ||
} | ||
_this.checkDisposed(); | ||
}); | ||
disposable.dispose = function () { | ||
toRemove.dispose(); | ||
originalDispose(); | ||
}; | ||
return toRemove; | ||
}; | ||
Collection.prototype.pushAll = function (disposables) { | ||
var _this = this; | ||
return disposables.map(function (disposable) { return _this.push(disposable); }); | ||
}; | ||
Collection.prototype.checkDisposed = function () { | ||
if (this.disposed) { | ||
this.onDisposeEmitter.fire(undefined); | ||
} | ||
}; | ||
return Collection; | ||
}()); | ||
exports.Collection = Collection; | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("@stoplight/disposable"), exports); | ||
//# sourceMappingURL=disposable.js.map |
@@ -1,23 +0,1 @@ | ||
import { Event } from './types'; | ||
export declare const NOOP: Event<any>; | ||
export interface IEmitterOptions { | ||
onFirstListenerAdd?: Function; | ||
onLastListenerRemove?: Function; | ||
} | ||
export declare class Emitter<T> { | ||
private _options?; | ||
private static _noop; | ||
private _event?; | ||
private _callbacks; | ||
constructor(_options?: IEmitterOptions | undefined); | ||
/** | ||
* Allows the public to subscribe to events from this Emitter | ||
*/ | ||
readonly event: Event<T>; | ||
/** | ||
* To be kept private to fire an event to | ||
* subscribers | ||
*/ | ||
fire(event: T): any; | ||
dispose(): void; | ||
} | ||
export * from '@stoplight/emitter'; |
133
lib/event.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Disposable = require("./disposable"); | ||
exports.NOOP = function () { | ||
return Disposable.NOOP; | ||
}; | ||
var CallbackList = /** @class */ (function () { | ||
function CallbackList() { | ||
} | ||
CallbackList.prototype.add = function (callback, context, bucket) { | ||
var _this = this; | ||
if (context === void 0) { context = null; } | ||
if (!this._callbacks) { | ||
this._callbacks = []; | ||
this._contexts = []; | ||
} | ||
this._callbacks.push(callback); | ||
this._contexts.push(context); | ||
if (Array.isArray(bucket)) { | ||
bucket.push({ dispose: function () { return _this.remove(callback, context); } }); | ||
} | ||
}; | ||
CallbackList.prototype.remove = function (callback, context) { | ||
if (context === void 0) { context = null; } | ||
if (!this._callbacks) { | ||
return; | ||
} | ||
var foundCallbackWithDifferentContext = false; | ||
for (var i = 0, len = this._callbacks.length; i < len; i++) { | ||
if (this._callbacks[i] === callback) { | ||
if (this._contexts[i] === context) { | ||
// callback & context match => remove it | ||
this._callbacks.splice(i, 1); | ||
this._contexts.splice(i, 1); | ||
return; | ||
} | ||
else { | ||
foundCallbackWithDifferentContext = true; | ||
} | ||
} | ||
} | ||
if (foundCallbackWithDifferentContext) { | ||
throw new Error('When adding a listener with a context, you should remove it with the same context'); | ||
} | ||
}; | ||
CallbackList.prototype.invoke = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
if (!this._callbacks) { | ||
return []; | ||
} | ||
var ret = []; | ||
var callbacks = this._callbacks.slice(0); | ||
var contexts = this._contexts.slice(0); | ||
for (var i = 0, len = callbacks.length; i < len; i++) { | ||
try { | ||
ret.push(callbacks[i].apply(contexts[i], args)); | ||
} | ||
catch (e) { | ||
// FIXME: log error | ||
} | ||
} | ||
return ret; | ||
}; | ||
CallbackList.prototype.isEmpty = function () { | ||
return !this._callbacks || this._callbacks.length === 0; | ||
}; | ||
CallbackList.prototype.dispose = function () { | ||
this._callbacks = undefined; | ||
this._contexts = undefined; | ||
}; | ||
return CallbackList; | ||
}()); | ||
var Emitter = /** @class */ (function () { | ||
function Emitter(_options) { | ||
this._options = _options; | ||
} | ||
Object.defineProperty(Emitter.prototype, "event", { | ||
/** | ||
* Allows the public to subscribe to events from this Emitter | ||
*/ | ||
get: function () { | ||
var _this = this; | ||
if (!this._event) { | ||
this._event = function (listener, thisArgs, disposables) { | ||
if (!_this._callbacks) { | ||
_this._callbacks = new CallbackList(); | ||
} | ||
if (_this._options && _this._options.onFirstListenerAdd && _this._callbacks.isEmpty()) { | ||
_this._options.onFirstListenerAdd(_this); | ||
} | ||
_this._callbacks.add(listener, thisArgs); | ||
var result = Disposable.create(function () { | ||
_this._callbacks.remove(listener, thisArgs); | ||
result.dispose = Emitter._noop; | ||
if (_this._options && _this._options.onLastListenerRemove && _this._callbacks.isEmpty()) { | ||
_this._options.onLastListenerRemove(_this); | ||
} | ||
}); | ||
if (Array.isArray(disposables)) { | ||
disposables.push(result); | ||
} | ||
return result; | ||
}; | ||
} | ||
return this._event; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* To be kept private to fire an event to | ||
* subscribers | ||
*/ | ||
Emitter.prototype.fire = function (event) { | ||
if (this._callbacks) { | ||
this._callbacks.invoke.call(this._callbacks, event); | ||
} | ||
}; | ||
Emitter.prototype.dispose = function () { | ||
if (this._callbacks) { | ||
this._callbacks.dispose(); | ||
this._callbacks = undefined; | ||
} | ||
}; | ||
Emitter._noop = function () { | ||
// nada | ||
}; | ||
return Emitter; | ||
}()); | ||
exports.Emitter = Emitter; | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("@stoplight/emitter"), exports); | ||
//# sourceMappingURL=event.js.map |
@@ -1,12 +0,1 @@ | ||
export declare const stringify: (target: any, replacer?: ((key: any, value: any) => any) | undefined, offset?: number | undefined) => any; | ||
export declare const parse: (target: string) => any; | ||
export declare const decycle: (target: object, replacer?: ((val: any, k: string, stack: [any, any][], parent?: any) => any) | undefined) => any; | ||
export declare const getValue: (obj: any, path: string | string[], defaultVal?: any) => any; | ||
export declare const setValue: (obj: any, path: string | string[], value: any) => any; | ||
export declare const startsWith: (source: string | any[], val: string | any[]) => boolean; | ||
/** | ||
* Removes elems from target, matched in order, starting on the left | ||
* trimStart([1, 2, 3], [1, 2]) === [3] | ||
* trimStart([1, 2, 3], [999, 2]) === [1, 2, 3] since source[0] does not equal elems[0] | ||
*/ | ||
export declare const trimStart: (target: string | any[], elems: string | any[]) => any; | ||
export * from '@stoplight/json'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fast_safe_stringify_1 = require("@stoplight/fast-safe-stringify"); | ||
var _get = require('lodash.get'); | ||
var _trimStart = require('lodash.trimstart'); | ||
var _set = require('lodash.set'); | ||
exports.stringify = function (target, replacer, offset) { | ||
if (!target || typeof target === 'string') | ||
return target; | ||
try { | ||
// try regular stringify first as mentioned in this tip: https://github.com/davidmarkclements/fast-safe-stringify#protip | ||
return JSON.stringify(target, replacer, offset); | ||
} | ||
catch (_) { | ||
// @ts-ignore | ||
return fast_safe_stringify_1.default(target, replacer, offset); | ||
} | ||
}; | ||
exports.parse = function (target) { | ||
if (typeof target !== 'string') | ||
return target; | ||
return JSON.parse(target); | ||
}; | ||
exports.decycle = function (target, replacer) { | ||
if (typeof target !== 'object') | ||
return target; | ||
fast_safe_stringify_1.default.decycle(target, replacer); | ||
return target; | ||
}; | ||
exports.getValue = function (obj, path, defaultVal) { | ||
return _get(obj, path, defaultVal); | ||
}; | ||
exports.setValue = function (obj, path, value) { | ||
return _set(obj, path, value); | ||
}; | ||
exports.startsWith = function (source, val) { | ||
if (source instanceof Array) { | ||
if (val instanceof Array) { | ||
if (val.length > source.length) | ||
return false; | ||
for (var i in val) { | ||
if (!val.hasOwnProperty(i)) | ||
continue; | ||
var si = parseInt(source[i]); | ||
var vi = parseInt(val[i]); | ||
// support if numeric index is stringified in one but not the other | ||
if (!isNaN(si) || !isNaN(vi)) { | ||
if (si !== vi) { | ||
return false; | ||
} | ||
} | ||
else if (source[i] !== val[i]) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
else if (typeof source === 'string') { | ||
if (typeof val === 'string') { | ||
return source.startsWith(val); | ||
} | ||
} | ||
else { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
/** | ||
* Removes elems from target, matched in order, starting on the left | ||
* trimStart([1, 2, 3], [1, 2]) === [3] | ||
* trimStart([1, 2, 3], [999, 2]) === [1, 2, 3] since source[0] does not equal elems[0] | ||
*/ | ||
exports.trimStart = function (target, elems) { | ||
if (typeof target === 'string') { | ||
return _trimStart(target, elems); | ||
} | ||
if (!elems || !elems.length || !(elems instanceof Array)) | ||
return target; | ||
var toRemove = 0; | ||
for (var i in target) { | ||
if (!target.hasOwnProperty(i)) | ||
continue; | ||
if (target[i] !== elems[i]) | ||
break; | ||
toRemove++; | ||
} | ||
return target.slice(toRemove); | ||
}; | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("@stoplight/json"), exports); | ||
//# sourceMappingURL=json.js.map |
@@ -1,164 +0,2 @@ | ||
/** | ||
* Emulates Node's `path` module. This module contains utilities for handling and | ||
* transforming file paths. **All** of these methods perform only string | ||
* transformations. The file system is not consulted to check whether paths are | ||
* valid. | ||
* @see http://nodejs.org/api/path.html | ||
* @class | ||
*/ | ||
declare class path { | ||
/** | ||
* Normalize a string path, taking care of '..' and '.' parts. | ||
* | ||
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. | ||
* @example Usage example | ||
* path.normalize('/foo/bar//baz/asdf/quux/..') | ||
* // returns | ||
* '/foo/bar/baz/asdf' | ||
* @param {String} p The path to normalize. | ||
* @return {String} | ||
*/ | ||
static normalize(p: string): string; | ||
/** | ||
* Join all arguments together and normalize the resulting path. | ||
* | ||
* Arguments must be strings. | ||
* @example Usage | ||
* path.join('/foo', 'bar', 'baz/asdf', 'quux', '..') | ||
* // returns | ||
* '/foo/bar/baz/asdf' | ||
* | ||
* path.join('foo', {}, 'bar') | ||
* // throws exception | ||
* TypeError: Arguments to path.join must be strings | ||
* @param [String,...] paths Each component of the path | ||
* @return [String] | ||
*/ | ||
static join(...paths: any[]): string; | ||
/** | ||
* Resolves to to an absolute path. | ||
* | ||
* If to isn't already absolute from arguments are prepended in right to left | ||
* order, until an absolute path is found. If after using all from paths still | ||
* no absolute path is found, the current working directory is used as well. | ||
* The resulting path is normalized, and trailing slashes are removed unless | ||
* the path gets resolved to the root directory. Non-string arguments are | ||
* ignored. | ||
* | ||
* Another way to think of it is as a sequence of cd commands in a shell. | ||
* | ||
* path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile') | ||
* | ||
* Is similar to: | ||
* | ||
* cd foo/bar | ||
* cd /tmp/file/ | ||
* cd .. | ||
* cd a/../subfile | ||
* pwd | ||
* | ||
* The difference is that the different paths don't need to exist and may also | ||
* be files. | ||
* @example Usage example | ||
* path.resolve('/foo/bar', './baz') | ||
* // returns | ||
* '/foo/bar/baz' | ||
* | ||
* path.resolve('/foo/bar', '/tmp/file/') | ||
* // returns | ||
* '/tmp/file' | ||
* | ||
* path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif') | ||
* // if currently in /home/myself/node, it returns | ||
* '/home/myself/node/wwwroot/static_files/gif/image.gif' | ||
* @param [String,...] paths | ||
* @return [String] | ||
*/ | ||
static resolve(...paths: string[]): string; | ||
/** | ||
* Solve the relative path from from to to. | ||
* | ||
* At times we have two absolute paths, and we need to derive the relative path | ||
* from one to the other. This is actually the reverse transform of | ||
* path.resolve, which means we see that: | ||
* | ||
* path.resolve(from, path.relative(from, to)) == path.resolve(to) | ||
* | ||
* @example Usage example | ||
* path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb') | ||
* // returns | ||
* '..\\..\\impl\\bbb' | ||
* | ||
* path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb') | ||
* // returns | ||
* '../../impl/bbb' | ||
* @param {String} from | ||
* @param {String} to | ||
* @return [String] | ||
*/ | ||
static relative(from: string, to: string): string; | ||
/** | ||
* Return the directory name of a path. Similar to the Unix `dirname` command. | ||
* | ||
* Note that BrowserFS does not validate if the path is actually a valid | ||
* directory. | ||
* @example Usage example | ||
* path.dirname('/foo/bar/baz/asdf/quux') | ||
* // returns | ||
* '/foo/bar/baz/asdf' | ||
* @param [String] p The path to get the directory name of. | ||
* @return [String] | ||
*/ | ||
static dirname(p: string): string; | ||
/** | ||
* Return the last portion of a path. Similar to the Unix basename command. | ||
* @example Usage example | ||
* path.basename('/foo/bar/baz/asdf/quux.html') | ||
* // returns | ||
* 'quux.html' | ||
* | ||
* path.basename('/foo/bar/baz/asdf/quux.html', '.html') | ||
* // returns | ||
* 'quux' | ||
* @param [String] p | ||
* @param [String?] ext | ||
* @return [String] | ||
*/ | ||
static basename(p: string, ext?: string): string; | ||
/** | ||
* Return the extension of the path, from the last '.' to end of string in the | ||
* last portion of the path. If there is no '.' in the last portion of the path | ||
* or the first character of it is '.', then it returns an empty string. | ||
* @example Usage example | ||
* path.extname('index.html') | ||
* // returns | ||
* '.html' | ||
* | ||
* path.extname('index.') | ||
* // returns | ||
* '.' | ||
* | ||
* path.extname('index') | ||
* // returns | ||
* '' | ||
* @param [String] p | ||
* @return [String] | ||
*/ | ||
static extname(p: string): string; | ||
/** | ||
* Checks if the given path is an absolute path. | ||
* | ||
* Despite not being documented, this is a tested part of Node's path API. | ||
* @param [String] p | ||
* @return [Boolean] True if the path appears to be an absolute path. | ||
*/ | ||
static isAbsolute(p: string): boolean; | ||
/** | ||
* Unknown. Undocumented. | ||
*/ | ||
static _makeLong(p: string): string; | ||
static sep: string; | ||
private static _replaceRegex; | ||
private static _removeDuplicateSeps; | ||
} | ||
import path = require('@stoplight/path'); | ||
export = path; |
406
lib/path.js
"use strict"; | ||
/* tslint:disable */ | ||
// adapted from https://github.com/wjordan/browser-path/blob/master/src/node_path.ts | ||
// TODO: really, all we need is a basic normalize function... | ||
// should take paths like foo/bar/../fee.json and return foo/fee.json | ||
// note have to handle the OS differences, and test lots of combinations (can use part of test suite from browser-path library) | ||
/** | ||
* Emulates Node's `path` module. This module contains utilities for handling and | ||
* transforming file paths. **All** of these methods perform only string | ||
* transformations. The file system is not consulted to check whether paths are | ||
* valid. | ||
* @see http://nodejs.org/api/path.html | ||
* @class | ||
*/ | ||
var path = /** @class */ (function () { | ||
function path() { | ||
} | ||
/** | ||
* Normalize a string path, taking care of '..' and '.' parts. | ||
* | ||
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. | ||
* @example Usage example | ||
* path.normalize('/foo/bar//baz/asdf/quux/..') | ||
* // returns | ||
* '/foo/bar/baz/asdf' | ||
* @param {String} p The path to normalize. | ||
* @return {String} | ||
*/ | ||
path.normalize = function (p) { | ||
// Special case: '' -> '.' | ||
if (p === '') { | ||
p = '.'; | ||
} | ||
// It's very important to know if the path is relative or not, since it | ||
// changes how we process .. and reconstruct the split string. | ||
var absolute = p.charAt(0) === path.sep; | ||
// Remove repeated //s | ||
p = path._removeDuplicateSeps(p); | ||
// Try to remove as many '../' as possible, and remove '.' completely. | ||
var components = p.split(path.sep); | ||
var goodComponents = []; | ||
for (var idx = 0; idx < components.length; idx++) { | ||
var c = components[idx]; | ||
if (c === '.') { | ||
continue; | ||
} | ||
else if (c === '..' && | ||
(absolute || (!absolute && goodComponents.length > 0 && goodComponents[0] !== '..'))) { | ||
// In the absolute case: Path is relative to root, so we may pop even if | ||
// goodComponents is empty (e.g. /../ => /) | ||
// In the relative case: We're getting rid of a directory that preceded | ||
// it (e.g. /foo/../bar -> /bar) | ||
goodComponents.pop(); | ||
} | ||
else { | ||
goodComponents.push(c); | ||
} | ||
} | ||
// Add in '.' when it's a relative path with no other nonempty components. | ||
// Possible results: '.' and './' (input: [''] or []) | ||
// @todo Can probably simplify this logic. | ||
if (!absolute && goodComponents.length < 2) { | ||
switch (goodComponents.length) { | ||
case 1: | ||
if (goodComponents[0] === '') { | ||
goodComponents.unshift('.'); | ||
} | ||
break; | ||
default: | ||
goodComponents.push('.'); | ||
} | ||
} | ||
p = goodComponents.join(path.sep); | ||
if (absolute && p.charAt(0) !== path.sep) { | ||
p = path.sep + p; | ||
} | ||
return p; | ||
}; | ||
/** | ||
* Join all arguments together and normalize the resulting path. | ||
* | ||
* Arguments must be strings. | ||
* @example Usage | ||
* path.join('/foo', 'bar', 'baz/asdf', 'quux', '..') | ||
* // returns | ||
* '/foo/bar/baz/asdf' | ||
* | ||
* path.join('foo', {}, 'bar') | ||
* // throws exception | ||
* TypeError: Arguments to path.join must be strings | ||
* @param [String,...] paths Each component of the path | ||
* @return [String] | ||
*/ | ||
path.join = function () { | ||
var paths = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
paths[_i] = arguments[_i]; | ||
} | ||
// Required: Prune any non-strings from the path. I also prune empty segments | ||
// so we can do a simple join of the array. | ||
var processed = []; | ||
for (var i = 0; i < paths.length; i++) { | ||
var segment = paths[i]; | ||
if (typeof segment !== 'string') { | ||
throw new TypeError('Invalid argument type to path.join: ' + typeof segment); | ||
} | ||
else if (segment !== '') { | ||
processed.push(segment); | ||
} | ||
} | ||
return path.normalize(processed.join(path.sep)); | ||
}; | ||
/** | ||
* Resolves to to an absolute path. | ||
* | ||
* If to isn't already absolute from arguments are prepended in right to left | ||
* order, until an absolute path is found. If after using all from paths still | ||
* no absolute path is found, the current working directory is used as well. | ||
* The resulting path is normalized, and trailing slashes are removed unless | ||
* the path gets resolved to the root directory. Non-string arguments are | ||
* ignored. | ||
* | ||
* Another way to think of it is as a sequence of cd commands in a shell. | ||
* | ||
* path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile') | ||
* | ||
* Is similar to: | ||
* | ||
* cd foo/bar | ||
* cd /tmp/file/ | ||
* cd .. | ||
* cd a/../subfile | ||
* pwd | ||
* | ||
* The difference is that the different paths don't need to exist and may also | ||
* be files. | ||
* @example Usage example | ||
* path.resolve('/foo/bar', './baz') | ||
* // returns | ||
* '/foo/bar/baz' | ||
* | ||
* path.resolve('/foo/bar', '/tmp/file/') | ||
* // returns | ||
* '/tmp/file' | ||
* | ||
* path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif') | ||
* // if currently in /home/myself/node, it returns | ||
* '/home/myself/node/wwwroot/static_files/gif/image.gif' | ||
* @param [String,...] paths | ||
* @return [String] | ||
*/ | ||
path.resolve = function () { | ||
var paths = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
paths[_i] = arguments[_i]; | ||
} | ||
// Monitor for invalid paths, throw out empty paths, and look for the *last* | ||
// absolute path that we see. | ||
var processed = []; | ||
for (var i = 0; i < paths.length; i++) { | ||
var p = paths[i]; | ||
if (typeof p !== 'string') { | ||
throw new TypeError('Invalid argument type to path.join: ' + typeof p); | ||
} | ||
else if (p !== '') { | ||
// Remove anything that has occurred before this absolute path, as it | ||
// doesn't matter. | ||
if (p.charAt(0) === path.sep) { | ||
processed = []; | ||
} | ||
processed.push(p); | ||
} | ||
} | ||
// Special: Remove trailing slash unless it's the root | ||
var resolved = path.normalize(processed.join(path.sep)); | ||
if (resolved.length > 1 && resolved.charAt(resolved.length - 1) === path.sep) { | ||
return resolved.substr(0, resolved.length - 1); | ||
} | ||
// Special: If it doesn't start with '/', it's relative and we need to append | ||
// the current directory. | ||
if (resolved.charAt(0) !== path.sep) { | ||
// Remove ./, since we're going to append the current directory. | ||
if (resolved.charAt(0) === '.' && | ||
(resolved.length === 1 || resolved.charAt(1) === path.sep)) { | ||
resolved = resolved.length === 1 ? '' : resolved.substr(2); | ||
} | ||
// Append the current directory, which *must* be an absolute path. | ||
// var cwd = process.cwd(); // not available in browser | ||
var cwd = ''; | ||
if (resolved !== '') { | ||
// cwd will never end in a /... unless it's the root. | ||
resolved = this.normalize("" + cwd + (cwd !== '/' ? path.sep : '') + resolved); | ||
} | ||
else { | ||
resolved = cwd; | ||
} | ||
} | ||
return resolved; | ||
}; | ||
/** | ||
* Solve the relative path from from to to. | ||
* | ||
* At times we have two absolute paths, and we need to derive the relative path | ||
* from one to the other. This is actually the reverse transform of | ||
* path.resolve, which means we see that: | ||
* | ||
* path.resolve(from, path.relative(from, to)) == path.resolve(to) | ||
* | ||
* @example Usage example | ||
* path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb') | ||
* // returns | ||
* '..\\..\\impl\\bbb' | ||
* | ||
* path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb') | ||
* // returns | ||
* '../../impl/bbb' | ||
* @param {String} from | ||
* @param {String} to | ||
* @return [String] | ||
*/ | ||
path.relative = function (from, to) { | ||
var i; | ||
// Alright. Let's resolve these two to absolute paths and remove any | ||
// weirdness. | ||
from = path.resolve(from); | ||
to = path.resolve(to); | ||
var fromSegs = from.split(path.sep); | ||
var toSegs = to.split(path.sep); | ||
// Remove the first segment on both, as it's '' (both are absolute paths) | ||
toSegs.shift(); | ||
fromSegs.shift(); | ||
// There are two segments to this path: | ||
// * Going *up* the directory hierarchy with '..' | ||
// * Going *down* the directory hierarchy with foo/baz/bat. | ||
var upCount = 0; | ||
var downSegs = []; | ||
// Figure out how many things in 'from' are shared with 'to'. | ||
for (i = 0; i < fromSegs.length; i++) { | ||
var seg = fromSegs[i]; | ||
if (seg === toSegs[i]) { | ||
continue; | ||
} | ||
// The rest of 'from', including the current element, indicates how many | ||
// directories we need to go up. | ||
upCount = fromSegs.length - i; | ||
break; | ||
} | ||
// The rest of 'to' indicates where we need to change to. We place this | ||
// outside of the loop, as toSegs.length may be greater than fromSegs.length. | ||
downSegs = toSegs.slice(i); | ||
// Special case: If 'from' is '/' | ||
if (fromSegs.length === 1 && fromSegs[0] === '') { | ||
upCount = 0; | ||
} | ||
// upCount can't be greater than the number of fromSegs | ||
// (cd .. from / is still /) | ||
if (upCount > fromSegs.length) { | ||
upCount = fromSegs.length; | ||
} | ||
// Create the final string! | ||
var rv = ''; | ||
for (i = 0; i < upCount; i++) { | ||
rv += '../'; | ||
} | ||
rv += downSegs.join(path.sep); | ||
// Special case: Remove trailing '/'. Happens if it's all up and no down. | ||
if (rv.length > 1 && rv.charAt(rv.length - 1) === path.sep) { | ||
rv = rv.substr(0, rv.length - 1); | ||
} | ||
return rv; | ||
}; | ||
/** | ||
* Return the directory name of a path. Similar to the Unix `dirname` command. | ||
* | ||
* Note that BrowserFS does not validate if the path is actually a valid | ||
* directory. | ||
* @example Usage example | ||
* path.dirname('/foo/bar/baz/asdf/quux') | ||
* // returns | ||
* '/foo/bar/baz/asdf' | ||
* @param [String] p The path to get the directory name of. | ||
* @return [String] | ||
*/ | ||
path.dirname = function (p) { | ||
// We get rid of //, but we don't modify anything else (e.g. any extraneous . | ||
// and ../ are kept intact) | ||
p = path._removeDuplicateSeps(p); | ||
var absolute = p.charAt(0) === path.sep; | ||
var sections = p.split(path.sep); | ||
// Do 1 if it's /foo/bar, 2 if it's /foo/bar/ | ||
if (sections.pop() === '' && sections.length > 0) { | ||
sections.pop(); | ||
} | ||
// # of sections needs to be > 1 if absolute, since the first section is '' for '/'. | ||
// If not absolute, the first section is the first part of the path, and is OK | ||
// to return. | ||
if (sections.length > 1 || (sections.length === 1 && !absolute)) { | ||
return sections.join(path.sep); | ||
} | ||
else if (absolute) { | ||
return path.sep; | ||
} | ||
else { | ||
return '.'; | ||
} | ||
}; | ||
/** | ||
* Return the last portion of a path. Similar to the Unix basename command. | ||
* @example Usage example | ||
* path.basename('/foo/bar/baz/asdf/quux.html') | ||
* // returns | ||
* 'quux.html' | ||
* | ||
* path.basename('/foo/bar/baz/asdf/quux.html', '.html') | ||
* // returns | ||
* 'quux' | ||
* @param [String] p | ||
* @param [String?] ext | ||
* @return [String] | ||
*/ | ||
path.basename = function (p, ext) { | ||
if (ext === void 0) { ext = ''; } | ||
// Special case: Normalize will modify this to '.' | ||
if (p === '') { | ||
return p; | ||
} | ||
// Normalize the string first to remove any weirdness. | ||
p = path.normalize(p); | ||
// Get the last part of the string. | ||
var sections = p.split(path.sep); | ||
var lastPart = sections[sections.length - 1]; | ||
// Special case: If it's empty, then we have a string like so: foo/ | ||
// Meaning, 'foo' is guaranteed to be a directory. | ||
if (lastPart === '' && sections.length > 1) { | ||
return sections[sections.length - 2]; | ||
} | ||
// Remove the extension, if need be. | ||
if (ext.length > 0) { | ||
var lastPartExt = lastPart.substr(lastPart.length - ext.length); | ||
if (lastPartExt === ext) { | ||
return lastPart.substr(0, lastPart.length - ext.length); | ||
} | ||
} | ||
return lastPart; | ||
}; | ||
/** | ||
* Return the extension of the path, from the last '.' to end of string in the | ||
* last portion of the path. If there is no '.' in the last portion of the path | ||
* or the first character of it is '.', then it returns an empty string. | ||
* @example Usage example | ||
* path.extname('index.html') | ||
* // returns | ||
* '.html' | ||
* | ||
* path.extname('index.') | ||
* // returns | ||
* '.' | ||
* | ||
* path.extname('index') | ||
* // returns | ||
* '' | ||
* @param [String] p | ||
* @return [String] | ||
*/ | ||
path.extname = function (p) { | ||
p = path.normalize(p); | ||
var sections = p.split(path.sep); | ||
p = sections.pop() || ''; | ||
// Special case: foo/file.ext/ should return '.ext' | ||
if (p === '' && sections.length > 0) { | ||
p = sections.pop() || ''; | ||
} | ||
if (p === '..') { | ||
return ''; | ||
} | ||
var i = p.lastIndexOf('.'); | ||
if (i === -1 || i === 0) { | ||
return ''; | ||
} | ||
return p.substr(i); | ||
}; | ||
/** | ||
* Checks if the given path is an absolute path. | ||
* | ||
* Despite not being documented, this is a tested part of Node's path API. | ||
* @param [String] p | ||
* @return [Boolean] True if the path appears to be an absolute path. | ||
*/ | ||
path.isAbsolute = function (p) { | ||
return p.length > 0 && p.charAt(0) === path.sep; | ||
}; | ||
/** | ||
* Unknown. Undocumented. | ||
*/ | ||
path._makeLong = function (p) { | ||
return p; | ||
}; | ||
path._removeDuplicateSeps = function (p) { | ||
p = p.replace(this._replaceRegex, this.sep); | ||
return p; | ||
}; | ||
// The platform-specific file separator. BrowserFS uses `/`. | ||
path.sep = '/'; | ||
path._replaceRegex = new RegExp('//+', 'g'); | ||
return path; | ||
}()); | ||
var path = require("@stoplight/path"); | ||
module.exports = path; | ||
//# sourceMappingURL=path.js.map |
@@ -1,1 +0,1 @@ | ||
export declare const pluralize: (single: string, count: number, plural?: string | undefined) => string; | ||
export * from '@stoplight/text'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// TODO: this is very naive - at least some smarts around non standard plural (family, families) | ||
// can look to other similar libraries for inspiration to cover the most common use cases | ||
exports.pluralize = function (single, count, plural) { | ||
if (!single) | ||
return single; | ||
if (count === 1) | ||
return single; | ||
if (plural) | ||
return plural; | ||
if (single[single.length - 1] === 's') | ||
return single; | ||
return single + "s"; | ||
}; | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("@stoplight/text"), exports); | ||
//# sourceMappingURL=text.js.map |
@@ -1,54 +0,4 @@ | ||
export interface IDisposable { | ||
dispose(): void; | ||
} | ||
export interface IExtension extends IDisposable { | ||
readonly id: string; | ||
readonly name: string; | ||
readonly longName: string; | ||
readonly icon?: any; | ||
activate(): Promise<any> | void; | ||
deactivate(): Promise<any> | void; | ||
} | ||
export interface IStringObject<T> { | ||
[key: string]: T; | ||
} | ||
export interface INumberedObject<T> { | ||
[key: number]: T; | ||
} | ||
export interface IUriComponents { | ||
scheme?: string; | ||
authority?: string; | ||
path?: string; | ||
query?: string; | ||
fragment?: string; | ||
} | ||
export interface IUri { | ||
scheme: string; | ||
authority: string; | ||
path: string; | ||
query: string; | ||
fragment: string; | ||
} | ||
export interface IUriState extends IUri { | ||
$mid: number; | ||
fsPath: string; | ||
external: string; | ||
} | ||
export interface ILocation { | ||
hash: string; | ||
host: string; | ||
hostname: string; | ||
href: string; | ||
origin: string; | ||
pathname: string; | ||
port: string; | ||
protocol: string; | ||
search: string; | ||
} | ||
/** | ||
* @param listener The listener function will be call when the event happens. | ||
* @param thisArgs The 'this' which will be used when calling the event listener. | ||
* @param disposables An array to which a {{IDisposable}} will be added. | ||
* @return a disposable to remove the listener again. | ||
*/ | ||
export declare type Event<T> = (listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[]) => IDisposable; | ||
export { IExtension, IStringObject, INumberedObject } from '@stoplight/types'; | ||
export { IDisposable } from '@stoplight/disposable'; | ||
export { Event } from '@stoplight/emitter'; | ||
export { IUriComponents, IUri, IUriState, ILocation } from '@stoplight/uri'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var types_1 = require("@stoplight/types"); | ||
exports.IExtension = types_1.IExtension; | ||
exports.IStringObject = types_1.IStringObject; | ||
exports.INumberedObject = types_1.INumberedObject; | ||
var disposable_1 = require("@stoplight/disposable"); | ||
exports.IDisposable = disposable_1.IDisposable; | ||
var emitter_1 = require("@stoplight/emitter"); | ||
exports.Event = emitter_1.Event; | ||
var uri_1 = require("@stoplight/uri"); | ||
exports.IUriComponents = uri_1.IUriComponents; | ||
exports.IUri = uri_1.IUri; | ||
exports.IUriState = uri_1.IUriState; | ||
exports.ILocation = uri_1.ILocation; | ||
//# sourceMappingURL=types.js.map |
@@ -1,92 +0,1 @@ | ||
import { ILocation, IUriComponents } from './types'; | ||
/** | ||
* Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986. | ||
* This class is a simple parser which creates the basic component paths | ||
* (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation | ||
* and encoding. | ||
* | ||
* foo://example.com:8042/over/there?name=ferret#nose | ||
* \_/ \______________/\_________/ \_________/ \__/ | ||
* | | | | | | ||
* scheme authority path query fragment | ||
* | _____________________|__ | ||
* / \ / \ | ||
* urn:example:animal:ferret:nose | ||
* | ||
* | ||
*/ | ||
export declare class URI { | ||
static isUri(thing: any): thing is URI; | ||
static parse(value: string, decode?: boolean): URI; | ||
static file(path: string): URI; | ||
static from(components: IUriComponents): URI; | ||
static revive(data: any): URI; | ||
private static _schemePattern; | ||
private static _singleSlashStart; | ||
private static _doubleSlashStart; | ||
private static _empty; | ||
private static _slash; | ||
private static _regexp; | ||
private static _driveLetterPath; | ||
private static _upperCaseDrive; | ||
private static _parseComponents; | ||
private static _validate; | ||
private static _asFormatted; | ||
private _scheme; | ||
private _authority; | ||
private _path; | ||
private _query; | ||
private _fragment; | ||
private _formatted; | ||
private _fsPath; | ||
constructor(); | ||
/** | ||
* scheme is the 'http' part of 'http://www.msft.com/some/path?query#fragment'. | ||
* The part before the first colon. | ||
*/ | ||
readonly scheme: string; | ||
/** | ||
* authority is the 'www.msft.com' part of 'http://www.msft.com/some/path?query#fragment'. | ||
* The part between the first double slashes and the next slash. | ||
*/ | ||
readonly authority: string; | ||
/** | ||
* path is the '/some/path' part of 'http://www.msft.com/some/path?query#fragment'. | ||
*/ | ||
readonly path: string; | ||
/** | ||
* query is the 'query' part of 'http://www.msft.com/some/path?query#fragment'. | ||
*/ | ||
readonly query: string; | ||
/** | ||
* fragment is the 'fragment' part of 'http://www.msft.com/some/path?query#fragment'. | ||
*/ | ||
readonly fragment: string; | ||
/** | ||
* 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. | ||
*/ | ||
readonly fsPath: string; | ||
readonly origin: string; | ||
readonly location: ILocation; | ||
isAbsolute(): boolean; | ||
isFile(root?: URI): boolean; | ||
isJSONPointer(): boolean; | ||
with(change: { | ||
scheme?: string; | ||
authority?: string; | ||
path?: string; | ||
query?: string; | ||
fragment?: string; | ||
}): URI; | ||
/** | ||
* | ||
* @param skipEncoding Do not encode the result, default is `true` | ||
*/ | ||
toString(skipEncoding?: boolean): string; | ||
toURL(): any; | ||
toJSON(): any; | ||
toJSONPointer(): string; | ||
} | ||
export * from '@stoplight/uri'; |
503
lib/uri.js
"use strict"; | ||
// adapted from https://github.com/Microsoft/vscode-uri | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// @ts-ignore | ||
var path_1 = require("./path"); | ||
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) { | ||
return ('%' + | ||
ch | ||
.charCodeAt(0) | ||
.toString(16) | ||
.toUpperCase()); | ||
} | ||
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent | ||
function encodeURIComponent2(str) { | ||
return encodeURIComponent(str).replace(/[!'()*]/g, _encode); | ||
} | ||
function encodeNoop(str) { | ||
return str.replace(/[#?]/, _encode); | ||
} | ||
/** | ||
* Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986. | ||
* This class is a simple parser which creates the basic component paths | ||
* (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation | ||
* and encoding. | ||
* | ||
* foo://example.com:8042/over/there?name=ferret#nose | ||
* \_/ \______________/\_________/ \_________/ \__/ | ||
* | | | | | | ||
* scheme authority path query fragment | ||
* | _____________________|__ | ||
* / \ / \ | ||
* urn:example:animal:ferret:nose | ||
* | ||
* | ||
*/ | ||
var URI = /** @class */ (function () { | ||
function URI() { | ||
this._scheme = URI._empty; | ||
this._authority = URI._empty; | ||
this._path = URI._empty; | ||
this._query = URI._empty; | ||
this._fragment = URI._empty; | ||
this._formatted = null; | ||
this._fsPath = null; | ||
} | ||
URI.isUri = function (thing) { | ||
if (thing instanceof URI) { | ||
return true; | ||
} | ||
if (!thing) { | ||
return false; | ||
} | ||
return (typeof thing.authority === 'string' && | ||
typeof thing.fragment === 'string' && | ||
typeof thing.path === 'string' && | ||
typeof thing.query === 'string' && | ||
typeof thing.scheme === 'string'); | ||
}; | ||
// ---- parse & validate ------------------------ | ||
URI.parse = function (value, decode) { | ||
var ret = new URI(); | ||
var data = URI._parseComponents(value); | ||
ret._scheme = data.scheme; | ||
ret._authority = decode ? decodeURIComponent(data.authority) : data.authority; | ||
ret._path = decode ? decodeURIComponent(data.path) : data.path; | ||
ret._query = decode ? decodeURIComponent(data.query) : data.query; | ||
ret._fragment = decode ? decodeURIComponent(data.fragment) : data.fragment; | ||
URI._validate(ret); | ||
return ret; | ||
}; | ||
URI.file = function (path) { | ||
var ret = new URI(); | ||
ret._scheme = 'file'; | ||
// normalize to fwd-slashes on windows, | ||
// on other systems bwd-slaches are valid | ||
// filename character, eg /f\oo/ba\r.txt | ||
if (isWindows) { | ||
path = path.replace(/\\/g, URI._slash); | ||
} | ||
// check for authority as used in UNC shares | ||
// or use the path as given | ||
if (path[0] === URI._slash && path[0] === path[1]) { | ||
var idx = path.indexOf(URI._slash, 2); | ||
if (idx === -1) { | ||
ret._authority = path.substring(2); | ||
} | ||
else { | ||
ret._authority = path.substring(2, idx); | ||
ret._path = path.substring(idx); | ||
} | ||
} | ||
else { | ||
ret._path = path; | ||
} | ||
ret._path = path_1.normalize(ret._path); | ||
// Ensure that path starts with a slash | ||
// or that it is at least a slash | ||
if (ret._path[0] !== URI._slash) { | ||
ret._path = URI._slash + ret._path; | ||
} | ||
URI._validate(ret); | ||
return ret; | ||
}; | ||
URI.from = function (components) { | ||
return new URI().with(components); | ||
}; | ||
URI.revive = function (data) { | ||
var result = new URI(); | ||
result._scheme = data.scheme || URI._empty; | ||
result._authority = data.authority || URI._empty; | ||
result._path = data.path || URI._empty; | ||
result._query = data.query || URI._empty; | ||
result._fragment = data.fragment || URI._empty; | ||
result._fsPath = data.fsPath; | ||
result._formatted = data.external; | ||
URI._validate(result); | ||
return result; | ||
}; | ||
URI._parseComponents = function (value) { | ||
var ret = { | ||
scheme: URI._empty, | ||
authority: URI._empty, | ||
path: URI._empty, | ||
query: URI._empty, | ||
fragment: URI._empty, | ||
}; | ||
var match = URI._regexp.exec(value); | ||
if (match) { | ||
ret.scheme = match[2] || ret.scheme; | ||
ret.authority = match[4] || ret.authority; | ||
ret.path = match[5] || ret.path; | ||
ret.query = match[7] || ret.query; | ||
ret.fragment = match[9] || ret.fragment; | ||
} | ||
return ret; | ||
}; | ||
URI._validate = function (ret) { | ||
// scheme, https://tools.ietf.org/html/rfc3986#section-3.1 | ||
// ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | ||
if (ret.scheme && !URI._schemePattern.test(ret.scheme)) { | ||
throw new Error('[UriError]: Scheme contains illegal characters.'); | ||
} | ||
// 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 | ||
// does not contain an authority component, then the path cannot begin | ||
// with two slash characters ("//"). | ||
if (ret.path) { | ||
if (ret.authority) { | ||
if (!URI._singleSlashStart.test(ret.path)) { | ||
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'); | ||
} | ||
} | ||
else { | ||
if (URI._doubleSlashStart.test(ret.path)) { | ||
throw new Error('[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")'); | ||
} | ||
} | ||
} | ||
}; | ||
URI._asFormatted = function (uri, skipEncoding) { | ||
var encoder = !skipEncoding ? encodeURIComponent2 : encodeNoop; | ||
var parts = []; | ||
var scheme = uri.scheme, query = uri.query, fragment = uri.fragment; | ||
var authority = uri.authority, path = uri.path; | ||
if (scheme) { | ||
parts.push(scheme, ':'); | ||
} | ||
if (authority || scheme === 'file') { | ||
parts.push('//'); | ||
} | ||
if (authority) { | ||
authority = authority.toLowerCase(); | ||
var idx = authority.indexOf(':'); | ||
if (idx === -1) { | ||
parts.push(encoder(authority)); | ||
} | ||
else { | ||
parts.push(encoder(authority.substr(0, idx)), authority.substr(idx)); | ||
} | ||
} | ||
if (path) { | ||
// lower-case windows drive letters in /C:/fff or C:/fff | ||
var m = URI._upperCaseDrive.exec(path); | ||
if (m) { | ||
if (m[1]) { | ||
path = '/' + m[2].toLowerCase() + path.substr(3); // "/c:".length === 3 | ||
} | ||
else { | ||
path = m[2].toLowerCase() + path.substr(2); // // "c:".length === 2 | ||
} | ||
} | ||
if (scheme === 'mailto') { | ||
parts.push(path); | ||
} | ||
else { | ||
// encode every segement but not slashes | ||
// make sure that # and ? are always encoded | ||
// when occurring in paths - otherwise the result | ||
// cannot be parsed back again | ||
var lastIdx = 0; | ||
while (true) { | ||
var idx = path.indexOf(URI._slash, lastIdx); | ||
if (idx === -1) { | ||
parts.push(encoder(path.substring(lastIdx))); | ||
break; | ||
} | ||
parts.push(encoder(path.substring(lastIdx, idx)), URI._slash); | ||
lastIdx = idx + 1; | ||
} | ||
} | ||
} | ||
if (query) { | ||
parts.push('?', encoder(query)); | ||
} | ||
if (fragment) { | ||
parts.push('#', encoder(fragment)); | ||
} | ||
return parts.join(URI._empty); | ||
}; | ||
Object.defineProperty(URI.prototype, "scheme", { | ||
/** | ||
* scheme is the 'http' part of 'http://www.msft.com/some/path?query#fragment'. | ||
* The part before the first colon. | ||
*/ | ||
get: function () { | ||
return this._scheme; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "authority", { | ||
/** | ||
* authority is the 'www.msft.com' part of 'http://www.msft.com/some/path?query#fragment'. | ||
* The part between the first double slashes and the next slash. | ||
*/ | ||
get: function () { | ||
return this._authority; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "path", { | ||
/** | ||
* path is the '/some/path' part of 'http://www.msft.com/some/path?query#fragment'. | ||
*/ | ||
get: function () { | ||
return this._path; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "query", { | ||
/** | ||
* query is the 'query' part of 'http://www.msft.com/some/path?query#fragment'. | ||
*/ | ||
get: function () { | ||
return this._query; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "fragment", { | ||
/** | ||
* fragment is the 'fragment' part of 'http://www.msft.com/some/path?query#fragment'. | ||
*/ | ||
get: function () { | ||
return this._fragment; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "fsPath", { | ||
// ---- filesystem path ----------------------- | ||
/** | ||
* 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. | ||
*/ | ||
get: function () { | ||
if (!this._fsPath) { | ||
var value = void 0; | ||
if (this._authority && this._path && this.scheme === 'file') { | ||
// unc path: file://shares/c$/far/boo | ||
value = "//" + this._authority + path_1.normalize(this._path); | ||
} | ||
else if (URI._driveLetterPath.test(this._path)) { | ||
// windows drive letter: file:///c:/far/boo | ||
value = this._path[1].toLowerCase() + path_1.normalize(this._path.substr(2)); | ||
} | ||
else { | ||
// other path | ||
value = path_1.normalize(this._path); | ||
} | ||
if (isWindows) { | ||
value = value.replace(/\//g, '\\'); | ||
} | ||
this._fsPath = value; | ||
} | ||
return this._fsPath; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "origin", { | ||
get: function () { | ||
if (this.scheme && this.authority) { | ||
return this.scheme + "://" + this.authority; | ||
} | ||
return ''; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "location", { | ||
get: function () { | ||
var res = { | ||
hash: '', | ||
host: '', | ||
hostname: '', | ||
href: this.toURL(), | ||
origin: this.origin, | ||
pathname: '', | ||
port: '', | ||
protocol: '', | ||
search: '', | ||
}; | ||
if (this.scheme) { | ||
res.protocol = this.scheme + ":"; | ||
} | ||
if (this.authority) { | ||
res.host = this.authority; | ||
var parts = this.authority.split(':'); | ||
res.hostname = parts[0]; | ||
res.port = parts[1]; | ||
} | ||
if (this.path) { | ||
res.pathname = this.path; | ||
} | ||
if (this.query) { | ||
res.search = "?" + this.query; | ||
} | ||
if (this.fragment) { | ||
res.hash = "#" + this.fragment; | ||
} | ||
return res; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
URI.prototype.isAbsolute = function () { | ||
return this.scheme === 'mailto' || (this.scheme && this.authority) ? true : false; | ||
}; | ||
URI.prototype.isFile = function (root) { | ||
if (root && this.scheme === '') { | ||
return root.scheme === '' || root.scheme === 'file'; | ||
} | ||
return this.scheme === 'file'; | ||
}; | ||
URI.prototype.isJSONPointer = function () { | ||
return this.fragment !== '' && this.scheme === '' && this.authority === '' && this.path === ''; | ||
}; | ||
// ---- modify to new ------------------------- | ||
URI.prototype.with = function (change) { | ||
if (!change) { | ||
return this; | ||
} | ||
var scheme = change.scheme, authority = change.authority, path = change.path, query = change.query, fragment = change.fragment; | ||
if (scheme === void 0) { | ||
scheme = this.scheme; | ||
} | ||
else if (scheme === null) { | ||
scheme = ''; | ||
} | ||
if (authority === void 0) { | ||
authority = this.authority; | ||
} | ||
else if (authority === null) { | ||
authority = ''; | ||
} | ||
if (path === void 0) { | ||
path = this.path; | ||
} | ||
else if (path === null) { | ||
path = ''; | ||
} | ||
if (query === void 0) { | ||
query = this.query; | ||
} | ||
else if (query === null) { | ||
query = ''; | ||
} | ||
if (fragment === void 0) { | ||
fragment = this.fragment; | ||
} | ||
else if (fragment === null) { | ||
fragment = ''; | ||
} | ||
if (scheme === this.scheme && | ||
authority === this.authority && | ||
path === this.path && | ||
query === this.query && | ||
fragment === this.fragment) { | ||
return this; | ||
} | ||
var ret = new URI(); | ||
ret._scheme = scheme; | ||
ret._authority = authority; | ||
ret._path = path; | ||
ret._query = query; | ||
ret._fragment = fragment; | ||
if (ret.isFile()) { | ||
ret._path = path_1.normalize(ret._path); | ||
} | ||
URI._validate(ret); | ||
return ret; | ||
}; | ||
// ---- printing/externalize --------------------------- | ||
/** | ||
* | ||
* @param skipEncoding Do not encode the result, default is `true` | ||
*/ | ||
URI.prototype.toString = function (skipEncoding) { | ||
if (skipEncoding === void 0) { skipEncoding = true; } | ||
if (!skipEncoding) { | ||
if (!this._formatted) { | ||
this._formatted = URI._asFormatted(this, false); | ||
} | ||
return this._formatted; | ||
} | ||
else { | ||
// we don't cache that | ||
return URI._asFormatted(this, true); | ||
} | ||
}; | ||
URI.prototype.toURL = function () { | ||
var url = ''; | ||
if (this._scheme) { | ||
url += this._scheme + ":"; | ||
if (this._authority || this._scheme === 'file') { | ||
url += '//'; | ||
} | ||
} | ||
if (this._authority) { | ||
url += this._authority; | ||
} | ||
if (this._path) { | ||
url += this._path; | ||
} | ||
if (this._query) { | ||
url += "?" + this._query; | ||
} | ||
if (this._fragment) { | ||
url += "#" + this._fragment; | ||
} | ||
return url; | ||
}; | ||
URI.prototype.toJSON = function () { | ||
var res = { | ||
fsPath: this.fsPath, | ||
external: this.toString(true), | ||
$mid: 1, | ||
}; | ||
if (this.path) { | ||
res.path = this.path; | ||
} | ||
if (this.scheme) { | ||
res.scheme = this.scheme; | ||
} | ||
if (this.authority) { | ||
res.authority = this.authority; | ||
} | ||
if (this.query) { | ||
res.query = this.query; | ||
} | ||
if (this.fragment) { | ||
res.fragment = this.fragment; | ||
} | ||
return res; | ||
}; | ||
URI.prototype.toJSONPointer = function () { | ||
return this.fragment ? "#" + (this.fragment || '/') : ''; | ||
}; | ||
URI._schemePattern = /^\w[\w\d+.-]*$/; | ||
URI._singleSlashStart = /^\//; | ||
URI._doubleSlashStart = /^\/\//; | ||
URI._empty = ''; | ||
URI._slash = '/'; | ||
URI._regexp = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/; | ||
URI._driveLetterPath = /^\/[a-zA-z]:/; | ||
URI._upperCaseDrive = /^(\/)?([A-Z]:)/; | ||
return URI; | ||
}()); | ||
exports.URI = URI; | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("@stoplight/uri"), exports); | ||
//# sourceMappingURL=uri.js.map |
{ | ||
"name": "@stoplight/common", | ||
"version": "0.0.31", | ||
"version": "0.0.32-beta.0", | ||
"description": "Stoplight common type and interface definitions.", | ||
@@ -23,11 +23,12 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@stoplight/fast-safe-stringify": "2.1.x", | ||
"@types/lodash.get": "4.x.x", | ||
"@types/lodash.set": "4.x.x", | ||
"lodash.get": "4.x.x", | ||
"lodash.set": "4.x.x", | ||
"lodash.trimstart": "4.x.x", | ||
"@stoplight/disposable": "^0.0.32-beta.0", | ||
"@stoplight/emitter": "^0.0.32-beta.0", | ||
"@stoplight/json": "^0.0.32-beta.0", | ||
"@stoplight/path": "^0.0.32-beta.0", | ||
"@stoplight/text": "^0.0.32-beta.0", | ||
"@stoplight/types": "^0.0.32-beta.0", | ||
"@stoplight/uri": "^0.0.32-beta.0", | ||
"tslib": "1.x.x" | ||
}, | ||
"gitHead": "9cd1a2077c23087a06571e7bdf718d801f9ac4d9" | ||
"gitHead": "994c0ed717cae1f95ed698003f6202c728ab6854" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
5482
8
70
1
+ Added@stoplight/disposable@0.0.32(transitive)
+ Added@stoplight/emitter@0.0.32(transitive)
+ Added@stoplight/json@0.0.32(transitive)
+ Added@stoplight/path@0.0.32(transitive)
+ Added@stoplight/text@0.0.32(transitive)
+ Added@stoplight/types@0.0.32(transitive)
+ Added@stoplight/uri@0.0.32(transitive)
- Removed@stoplight/fast-safe-stringify@2.1.x
- Removed@types/lodash.get@4.x.x
- Removed@types/lodash.set@4.x.x
- Removedlodash.get@4.x.x
- Removedlodash.set@4.x.x
- Removedlodash.trimstart@4.x.x