Socket
Socket
Sign inDemoInstall

@stoplight/common

Package Overview
Dependencies
Maintainers
4
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoplight/common - npm Package Compare versions

Comparing version 0.0.11-2 to 0.0.11-3

lib/path.d.ts

63

lib/disposable.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var event_1 = require("./event");
const event_1 = require("./event");
function create(func) {

@@ -10,25 +10,17 @@ return {

exports.create = create;
exports.NOOP = create(function () {
exports.NOOP = create(() => {
// nada
});
var Collection = /** @class */ (function () {
function Collection() {
class Collection {
constructor() {
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 () {
get onDispose() {
return this.onDisposeEmitter.event;
}
get disposed() {
return this.disposables.length === 0;
}
dispose() {
if (this.disposed)

@@ -40,15 +32,14 @@ return;

this.checkDisposed();
};
Collection.prototype.push = function (disposable) {
var _this = this;
}
push(disposable) {
this.disposables.push(disposable);
var originalDispose = disposable.dispose.bind(disposable);
var toRemove = create(function () {
var index = _this.disposables.indexOf(disposable);
const originalDispose = disposable.dispose.bind(disposable);
const toRemove = create(() => {
const index = this.disposables.indexOf(disposable);
if (index !== -1) {
_this.disposables.splice(index, 1);
this.disposables.splice(index, 1);
}
_this.checkDisposed();
this.checkDisposed();
});
disposable.dispose = function () {
disposable.dispose = () => {
toRemove.dispose();

@@ -58,15 +49,13 @@ originalDispose();

return toRemove;
};
Collection.prototype.pushAll = function (disposables) {
var _this = this;
return disposables.map(function (disposable) { return _this.push(disposable); });
};
Collection.prototype.checkDisposed = function () {
}
pushAll(disposables) {
return disposables.map(disposable => this.push(disposable));
}
checkDisposed() {
if (this.disposed) {
this.onDisposeEmitter.fire(undefined);
}
};
return Collection;
}());
}
}
exports.Collection = Collection;
//# sourceMappingURL=disposable.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Disposable = require("./disposable");
exports.NOOP = function () {
const Disposable = require("./disposable");
exports.NOOP = () => {
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; }
class CallbackList {
add(callback, context = null, bucket) {
if (!this._callbacks) {

@@ -20,12 +16,11 @@ this._callbacks = [];

if (Array.isArray(bucket)) {
bucket.push({ dispose: function () { return _this.remove(callback, context); } });
bucket.push({ dispose: () => this.remove(callback, context) });
}
};
CallbackList.prototype.remove = function (callback, context) {
if (context === void 0) { context = null; }
}
remove(callback, context = null) {
if (!this._callbacks) {
return;
}
var foundCallbackWithDifferentContext = false;
for (var i = 0, len = this._callbacks.length; i < len; i++) {
let foundCallbackWithDifferentContext = false;
for (let i = 0, len = this._callbacks.length; i < len; i++) {
if (this._callbacks[i] === callback) {

@@ -46,15 +41,11 @@ if (this._contexts[i] === context) {

}
};
CallbackList.prototype.invoke = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
}
invoke(...args) {
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++) {
const ret = [];
const callbacks = this._callbacks.slice(0);
const contexts = this._contexts.slice(0);
for (let i = 0, len = callbacks.length; i < len; i++) {
try {

@@ -68,49 +59,43 @@ ret.push(callbacks[i].apply(contexts[i], args));

return ret;
};
CallbackList.prototype.isEmpty = function () {
}
isEmpty() {
return !this._callbacks || this._callbacks.length === 0;
};
CallbackList.prototype.dispose = function () {
}
dispose() {
this._callbacks = undefined;
this._contexts = undefined;
};
return CallbackList;
}());
var Emitter = /** @class */ (function () {
function Emitter(_options) {
}
}
class Emitter {
constructor(_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();
/**
* Allows the public to subscribe to events from this Emitter
*/
get event() {
if (!this._event) {
this._event = (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);
const result = Disposable.create(() => {
this._callbacks.remove(listener, thisArgs);
result.dispose = Emitter._noop;
if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {
this._options.onLastListenerRemove(this);
}
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
});
});
if (Array.isArray(disposables)) {
disposables.push(result);
}
return result;
};
}
return this._event;
}
/**

@@ -120,8 +105,8 @@ * To be kept private to fire an event to

*/
Emitter.prototype.fire = function (event) {
fire(event) {
if (this._callbacks) {
this._callbacks.invoke.call(this._callbacks, event);
}
};
Emitter.prototype.dispose = function () {
}
dispose() {
if (this._callbacks) {

@@ -131,9 +116,8 @@ this._callbacks.dispose();

}
};
Emitter._noop = function () {
// nada
};
return Emitter;
}());
}
}
Emitter._noop = () => {
// nada
};
exports.Emitter = Emitter;
//# sourceMappingURL=event.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var disposable = require("./disposable");
const disposable = require("./disposable");
exports.disposable = disposable;
var event = require("./event");
const event = require("./event");
exports.event = event;
var text = require("./text");
const text = require("./text");
exports.text = text;
var types = require("./types");
const types = require("./types");
exports.types = types;
var uri = require("./uri");
const uri = require("./uri");
exports.uri = uri;
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pluralize = function (single, count, plural) {
exports.pluralize = (single, count, plural) => {
if (count === 1)
return single;
return plural || single + "s";
return plural || `${single}s`;
};
//# sourceMappingURL=text.js.map

@@ -74,2 +74,4 @@ import { ILocation, IUriComponents } from './types';

isAbsolute(): boolean;
isFile(): boolean;
isJSONPointer(): boolean;
with(change: {

@@ -88,2 +90,3 @@ scheme?: string;

toJSON(): any;
toJSONPointer(): string;
}
"use strict";
// adapted from https://github.com/Microsoft/vscode-uri
Object.defineProperty(exports, "__esModule", { value: true });
var isWindows;
// @ts-ignore
const path_1 = require("./path");
let isWindows;
if (typeof process === 'object') {

@@ -9,3 +11,3 @@ isWindows = process.platform === 'win32';

else if (typeof navigator === 'object') {
var userAgent = navigator.userAgent;
const userAgent = navigator.userAgent;
isWindows = userAgent.indexOf('Windows') >= 0;

@@ -43,4 +45,4 @@ }

*/
var URI = /** @class */ (function () {
function URI() {
class URI {
constructor() {
this._scheme = URI._empty;

@@ -54,3 +56,3 @@ this._authority = URI._empty;

}
URI.isUri = function (thing) {
static isUri(thing) {
if (thing instanceof URI) {

@@ -67,7 +69,7 @@ return true;

typeof thing.scheme === 'string');
};
}
// ---- parse & validate ------------------------
URI.parse = function (value) {
var ret = new URI();
var data = URI._parseComponents(value);
static parse(value) {
const ret = new URI();
const data = URI._parseComponents(value);
ret._scheme = data.scheme;

@@ -80,5 +82,5 @@ ret._authority = decodeURIComponent(data.authority);

return ret;
};
URI.file = function (path) {
var ret = new URI();
}
static file(path) {
const ret = new URI();
ret._scheme = 'file';

@@ -94,3 +96,3 @@ // normalize to fwd-slashes on windows,

if (path[0] === URI._slash && path[0] === path[1]) {
var idx = path.indexOf(URI._slash, 2);
const idx = path.indexOf(URI._slash, 2);
if (idx === -1) {

@@ -107,2 +109,3 @@ ret._authority = path.substring(2);

}
ret._path = path_1.normalize(ret._path);
// Ensure that path starts with a slash

@@ -115,8 +118,8 @@ // or that it is at least a slash

return ret;
};
URI.from = function (components) {
}
static from(components) {
return new URI().with(components);
};
URI.revive = function (data) {
var result = new URI();
}
static revive(data) {
const result = new URI();
result._scheme = data.scheme || URI._empty;

@@ -131,5 +134,5 @@ result._authority = data.authority || URI._empty;

return result;
};
URI._parseComponents = function (value) {
var ret = {
}
static _parseComponents(value) {
const ret = {
scheme: URI._empty,

@@ -141,3 +144,3 @@ authority: URI._empty,

};
var match = URI._regexp.exec(value);
const match = URI._regexp.exec(value);
if (match) {

@@ -151,4 +154,4 @@ ret.scheme = match[2] || ret.scheme;

return ret;
};
URI._validate = function (ret) {
}
static _validate(ret) {
// scheme, https://tools.ietf.org/html/rfc3986#section-3.1

@@ -176,8 +179,8 @@ // ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )

}
};
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;
}
static _asFormatted(uri, skipEncoding) {
const encoder = !skipEncoding ? encodeURIComponent2 : encodeNoop;
const parts = [];
const { scheme, query, fragment } = uri;
let { authority, path } = uri;
if (scheme) {

@@ -191,3 +194,3 @@ parts.push(scheme, ':');

authority = authority.toLowerCase();
var idx = authority.indexOf(':');
const idx = authority.indexOf(':');
if (idx === -1) {

@@ -202,3 +205,3 @@ parts.push(encoder(authority));

// lower-case windows drive letters in /C:/fff or C:/fff
var m = URI._upperCaseDrive.exec(path);
const m = URI._upperCaseDrive.exec(path);
if (m) {

@@ -216,5 +219,5 @@ if (m[1]) {

// cannot be parsed back again
var lastIdx = 0;
let lastIdx = 0;
while (true) {
var idx = path.indexOf(URI._slash, lastIdx);
const idx = path.indexOf(URI._slash, lastIdx);
if (idx === -1) {

@@ -235,133 +238,116 @@ parts.push(encoder(path.substring(lastIdx)));

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 () {
}
/**
* scheme is the 'http' part of 'http://www.msft.com/some/path?query#fragment'.
* The part before the first colon.
*/
get scheme() {
if (this._scheme)
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 + this._path;
}
else if (URI._driveLetterPath.test(this._path)) {
// windows drive letter: file:///c:/far/boo
value = this._path[1].toLowerCase() + this._path.substr(2);
}
else {
// other path
value = this._path;
}
if (isWindows) {
value = value.replace(/\//g, '\\');
}
this._fsPath = value;
// if no scheme but have authority or path, we're working with a file
if (this.path)
return 'file';
return '';
}
/**
* 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 authority() {
return this._authority;
}
/**
* path is the '/some/path' part of 'http://www.msft.com/some/path?query#fragment'.
*/
get path() {
return this._path;
}
/**
* query is the 'query' part of 'http://www.msft.com/some/path?query#fragment'.
*/
get query() {
return this._query;
}
/**
* fragment is the 'fragment' part of 'http://www.msft.com/some/path?query#fragment'.
*/
get fragment() {
return this._fragment;
}
// ---- 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 fsPath() {
if (!this._fsPath) {
let value;
if (this._authority && this._path && this.scheme === 'file') {
// unc path: file://shares/c$/far/boo
value = `//${this._authority}${path_1.normalize(this._path)}`;
}
return this._fsPath;
},
enumerable: true,
configurable: true
});
Object.defineProperty(URI.prototype, "location", {
get: function () {
var res = {
hash: '',
host: '',
hostname: '',
href: '',
origin: '',
pathname: '',
port: '',
protocol: '',
search: '',
};
if (this.path) {
res.pathname = 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));
}
if (this.scheme) {
res.protocol = this.scheme + ":";
else {
// other path
value = path_1.normalize(this._path);
}
if (this.authority) {
res.host = this.authority;
var parts = this.authority.split(':');
res.hostname = parts[0];
res.port = parts[1];
if (isWindows) {
value = value.replace(/\//g, '\\');
}
if (this.query) {
res.search = "?" + this.query;
}
if (this.fragment) {
res.hash = "#" + this.fragment;
}
return res;
},
enumerable: true,
configurable: true
});
URI.prototype.isAbsolute = function () {
this._fsPath = value;
}
return this._fsPath;
}
get location() {
const res = {
hash: '',
host: '',
hostname: '',
href: '',
origin: '',
pathname: '',
port: '',
protocol: '',
search: '',
};
if (this.path) {
res.pathname = this.path;
}
if (this.scheme) {
res.protocol = `${this.scheme}:`;
}
if (this.authority) {
res.host = this.authority;
const parts = this.authority.split(':');
res.hostname = parts[0];
res.port = parts[1];
}
if (this.query) {
res.search = `?${this.query}`;
}
if (this.fragment) {
res.hash = `#${this.fragment}`;
}
return res;
}
isAbsolute() {
return this.scheme ? true : false;
};
}
isFile() {
return this.scheme === 'file';
}
isJSONPointer() {
return this.fragment !== '' && this.scheme === '' && this.authority === '' && this.path === '';
}
// ---- modify to new -------------------------
URI.prototype.with = function (change) {
with(change) {
if (!change) {
return this;
}
var scheme = change.scheme, authority = change.authority, path = change.path, query = change.query, fragment = change.fragment;
let { scheme, authority, path, query, fragment } = change;
if (scheme === void 0) {

@@ -404,3 +390,3 @@ scheme = this.scheme;

}
var ret = new URI();
const ret = new URI();
ret._scheme = scheme;

@@ -411,5 +397,8 @@ ret._authority = authority;

ret._fragment = fragment;
if (ret.isFile()) {
ret._path = path_1.normalize(ret._path);
}
URI._validate(ret);
return ret;
};
}
// ---- printing/externalize ---------------------------

@@ -420,4 +409,3 @@ /**

*/
URI.prototype.toString = function (skipEncoding) {
if (skipEncoding === void 0) { skipEncoding = false; }
toString(skipEncoding = false) {
if (!skipEncoding) {

@@ -433,5 +421,5 @@ if (!this._formatted) {

}
};
URI.prototype.toJSON = function () {
var res = {
}
toJSON() {
const res = {
fsPath: this.fsPath,

@@ -457,14 +445,16 @@ external: this.toString(),

return res;
};
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;
}());
}
toJSONPointer() {
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]:)/;
exports.URI = URI;
//# sourceMappingURL=uri.js.map
{
"name": "@stoplight/common",
"version": "0.0.11-2",
"version": "0.0.11-3",
"description": "Stoplight common type and interface definitions.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc