@hpcc-js/util
Advanced tools
Comparing version 0.0.42 to 0.0.43
106
lib/array.js
@@ -1,67 +0,53 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
// Based on: https://tc39.github.io/ecma262/#sec-array.prototype.find | ||
export function find(o, predicate) { | ||
// 1. Let O be ? ToObject(this value). | ||
if (o == null) { | ||
throw new TypeError('"o" is null or not defined'); | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
// 2. Let len be ? ToLength(? Get(O, "length")). | ||
// tslint:disable-next-line:no-bitwise | ||
var len = o.length >>> 0; | ||
// 3. If IsCallable(predicate) is false, throw a TypeError exception. | ||
if (typeof predicate !== "function") { | ||
throw new TypeError("predicate must be a function"); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Based on: https://tc39.github.io/ecma262/#sec-array.prototype.find | ||
function find(o, predicate) { | ||
// 1. Let O be ? ToObject(this value). | ||
if (o == null) { | ||
throw new TypeError('"o" is null or not defined'); | ||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined. | ||
var thisArg = arguments[1]; | ||
// 5. Let k be 0. | ||
var k = 0; | ||
// 6. Repeat, while k < len | ||
while (k < len) { | ||
// a. Let Pk be ! ToString(k). | ||
// b. Let kValue be ? Get(O, Pk). | ||
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). | ||
// d. If testResult is true, return kValue. | ||
var kValue = o[k]; | ||
if (predicate.call(thisArg, kValue, k, o)) { | ||
return kValue; | ||
} | ||
// 2. Let len be ? ToLength(? Get(O, "length")). | ||
// tslint:disable-next-line:no-bitwise | ||
var len = o.length >>> 0; | ||
// 3. If IsCallable(predicate) is false, throw a TypeError exception. | ||
if (typeof predicate !== "function") { | ||
throw new TypeError("predicate must be a function"); | ||
// e. Increase k by 1. | ||
k++; | ||
} | ||
// 7. Return undefined. | ||
return undefined; | ||
} | ||
export function compare(before, after) { | ||
var retVal = { | ||
unchanged: [], | ||
removed: [], | ||
added: after.slice(0) | ||
}; | ||
for (var _i = 0, before_1 = before; _i < before_1.length; _i++) { | ||
var row = before_1[_i]; | ||
var otherIdx = retVal.added.indexOf(row); | ||
if (otherIdx >= 0) { | ||
retVal.unchanged.push(row); | ||
retVal.added.splice(otherIdx, 1); | ||
} | ||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined. | ||
var thisArg = arguments[1]; | ||
// 5. Let k be 0. | ||
var k = 0; | ||
// 6. Repeat, while k < len | ||
while (k < len) { | ||
// a. Let Pk be ! ToString(k). | ||
// b. Let kValue be ? Get(O, Pk). | ||
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). | ||
// d. If testResult is true, return kValue. | ||
var kValue = o[k]; | ||
if (predicate.call(thisArg, kValue, k, o)) { | ||
return kValue; | ||
} | ||
// e. Increase k by 1. | ||
k++; | ||
else { | ||
retVal.removed.push(row); | ||
} | ||
// 7. Return undefined. | ||
return undefined; | ||
} | ||
exports.find = find; | ||
function compare(before, after) { | ||
var retVal = { | ||
unchanged: [], | ||
removed: [], | ||
added: after.slice(0) | ||
}; | ||
for (var _i = 0, before_1 = before; _i < before_1.length; _i++) { | ||
var row = before_1[_i]; | ||
var otherIdx = retVal.added.indexOf(row); | ||
if (otherIdx >= 0) { | ||
retVal.unchanged.push(row); | ||
retVal.added.splice(otherIdx, 1); | ||
} | ||
else { | ||
retVal.removed.push(row); | ||
} | ||
} | ||
return retVal; | ||
} | ||
exports.compare = compare; | ||
}); | ||
return retVal; | ||
} | ||
//# sourceMappingURL=array.js.map |
124
lib/cache.js
@@ -1,73 +0,61 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import * as tslib_1 from "tslib"; | ||
import { hashSum } from "./hashSum"; | ||
var Cache = /** @class */ (function () { | ||
function Cache(calcID) { | ||
this._cache = {}; | ||
this._calcID = calcID; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "tslib", "./hashSum"], factory); | ||
Cache.hash = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return hashSum(tslib_1.__assign({}, args)); | ||
}; | ||
Cache.prototype.has = function (espObj) { | ||
return this._calcID(espObj) in this._cache; | ||
}; | ||
Cache.prototype.set = function (obj) { | ||
this._cache[this._calcID(obj)] = obj; | ||
return obj; | ||
}; | ||
Cache.prototype.get = function (espObj, factory) { | ||
var retVal = this._cache[this._calcID(espObj)]; | ||
if (!retVal) { | ||
return factory ? this.set(factory()) : null; | ||
} | ||
return retVal; | ||
}; | ||
return Cache; | ||
}()); | ||
export { Cache }; | ||
var AsyncCache = /** @class */ (function () { | ||
function AsyncCache(calcID) { | ||
this._cache = {}; | ||
this._calcID = calcID; | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var hashSum_1 = require("./hashSum"); | ||
var Cache = /** @class */ (function () { | ||
function Cache(calcID) { | ||
this._cache = {}; | ||
this._calcID = calcID; | ||
AsyncCache.hash = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
Cache.hash = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return hashSum_1.hashSum(tslib_1.__assign({}, args)); | ||
}; | ||
Cache.prototype.has = function (espObj) { | ||
return this._calcID(espObj) in this._cache; | ||
}; | ||
Cache.prototype.set = function (obj) { | ||
this._cache[this._calcID(obj)] = obj; | ||
return obj; | ||
}; | ||
Cache.prototype.get = function (espObj, factory) { | ||
var retVal = this._cache[this._calcID(espObj)]; | ||
if (!retVal) { | ||
return factory ? this.set(factory()) : null; | ||
} | ||
return retVal; | ||
}; | ||
return Cache; | ||
}()); | ||
exports.Cache = Cache; | ||
var AsyncCache = /** @class */ (function () { | ||
function AsyncCache(calcID) { | ||
this._cache = {}; | ||
this._calcID = calcID; | ||
return hashSum(tslib_1.__assign({}, args)); | ||
}; | ||
AsyncCache.prototype.has = function (espObj) { | ||
return this._calcID(espObj) in this._cache; | ||
}; | ||
AsyncCache.prototype.set = function (espObj, obj) { | ||
this._cache[this._calcID(espObj)] = obj; | ||
return obj; | ||
}; | ||
AsyncCache.prototype.get = function (espObj, factory) { | ||
var retVal = this._cache[this._calcID(espObj)]; | ||
if (!retVal) { | ||
return factory ? this.set(espObj, factory()) : Promise.resolve(null); | ||
} | ||
AsyncCache.hash = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return hashSum_1.hashSum(tslib_1.__assign({}, args)); | ||
}; | ||
AsyncCache.prototype.has = function (espObj) { | ||
return this._calcID(espObj) in this._cache; | ||
}; | ||
AsyncCache.prototype.set = function (espObj, obj) { | ||
this._cache[this._calcID(espObj)] = obj; | ||
return obj; | ||
}; | ||
AsyncCache.prototype.get = function (espObj, factory) { | ||
var retVal = this._cache[this._calcID(espObj)]; | ||
if (!retVal) { | ||
return factory ? this.set(espObj, factory()) : Promise.resolve(null); | ||
} | ||
return retVal; | ||
}; | ||
return AsyncCache; | ||
}()); | ||
exports.AsyncCache = AsyncCache; | ||
}); | ||
return retVal; | ||
}; | ||
return AsyncCache; | ||
}()); | ||
export { AsyncCache }; | ||
//# sourceMappingURL=cache.js.map |
@@ -1,42 +0,29 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function debounce(fn, timeout) { | ||
var promise = null; | ||
var clockStart; | ||
return function () { | ||
var params = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
params[_i] = arguments[_i]; | ||
export function debounce(fn, timeout) { | ||
var promise = null; | ||
var clockStart; | ||
return function () { | ||
var params = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
params[_i] = arguments[_i]; | ||
} | ||
if (promise) | ||
return promise; | ||
promise = fn.apply(void 0, params).then(function (response) { | ||
if (timeout === undefined) { | ||
promise = null; | ||
} | ||
if (promise) | ||
return promise; | ||
promise = fn.apply(void 0, params).then(function (response) { | ||
if (timeout === undefined) { | ||
else { | ||
setTimeout(function () { | ||
promise = null; | ||
} | ||
else { | ||
setTimeout(function () { | ||
promise = null; | ||
}, Math.max(timeout - (Date.now() - clockStart), 0)); | ||
} | ||
return response; | ||
}).catch(function (e) { | ||
promise = null; | ||
throw e; | ||
}); | ||
clockStart = Date.now(); | ||
return promise; | ||
}; | ||
} | ||
exports.debounce = debounce; | ||
}); | ||
}, Math.max(timeout - (Date.now() - clockStart), 0)); | ||
} | ||
return response; | ||
}).catch(function (e) { | ||
promise = null; | ||
throw e; | ||
}); | ||
clockStart = Date.now(); | ||
return promise; | ||
}; | ||
} | ||
//# sourceMappingURL=debounce.js.map |
@@ -1,53 +0,41 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Dictionary = /** @class */ (function () { | ||
function Dictionary(attrs) { | ||
this.store = {}; | ||
if (attrs) { | ||
for (var key in attrs) { | ||
this.set(key, attrs[key]); | ||
} | ||
var Dictionary = /** @class */ (function () { | ||
function Dictionary(attrs) { | ||
this.store = {}; | ||
if (attrs) { | ||
for (var key in attrs) { | ||
this.set(key, attrs[key]); | ||
} | ||
} | ||
Dictionary.prototype.set = function (key, value) { | ||
var retVal = this.store[key]; | ||
this.store[key] = value; | ||
return retVal; | ||
}; | ||
Dictionary.prototype.get = function (key) { | ||
return this.store[key]; | ||
}; | ||
Dictionary.prototype.has = function (key) { | ||
return this.store[key] !== undefined; | ||
}; | ||
Dictionary.prototype.remove = function (key) { | ||
delete this.store[key]; | ||
}; | ||
Dictionary.prototype.keys = function () { | ||
var retVal = []; | ||
for (var key in this.store) { | ||
retVal.push(key); | ||
} | ||
return retVal; | ||
}; | ||
Dictionary.prototype.values = function () { | ||
var retVal = []; | ||
for (var key in this.store) { | ||
retVal.push(this.store[key]); | ||
} | ||
return retVal; | ||
}; | ||
return Dictionary; | ||
}()); | ||
exports.Dictionary = Dictionary; | ||
}); | ||
} | ||
Dictionary.prototype.set = function (key, value) { | ||
var retVal = this.store[key]; | ||
this.store[key] = value; | ||
return retVal; | ||
}; | ||
Dictionary.prototype.get = function (key) { | ||
return this.store[key]; | ||
}; | ||
Dictionary.prototype.has = function (key) { | ||
return this.store[key] !== undefined; | ||
}; | ||
Dictionary.prototype.remove = function (key) { | ||
delete this.store[key]; | ||
}; | ||
Dictionary.prototype.keys = function () { | ||
var retVal = []; | ||
for (var key in this.store) { | ||
retVal.push(key); | ||
} | ||
return retVal; | ||
}; | ||
Dictionary.prototype.values = function () { | ||
var retVal = []; | ||
for (var key in this.store) { | ||
retVal.push(this.store[key]); | ||
} | ||
return retVal; | ||
}; | ||
return Dictionary; | ||
}()); | ||
export { Dictionary }; | ||
//# sourceMappingURL=dictionary.js.map |
@@ -1,46 +0,33 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
export function espTime2Seconds(duration) { | ||
if (!duration) { | ||
return 0; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function espTime2Seconds(duration) { | ||
if (!duration) { | ||
return 0; | ||
else { | ||
if (!isNaN(Number(duration))) { | ||
return Number(duration); | ||
} | ||
else { | ||
if (!isNaN(Number(duration))) { | ||
return Number(duration); | ||
} | ||
} | ||
// GH: <n>ns or <m>ms or <s>s or [<d> days ][<h>:][<m>:]<s>[.<ms>] | ||
var nsIndex = duration.indexOf("ns"); | ||
if (nsIndex !== -1) { | ||
return parseFloat(duration.substr(0, nsIndex)) / 1000000000; | ||
} | ||
var msIndex = duration.indexOf("ms"); | ||
if (msIndex !== -1) { | ||
return parseFloat(duration.substr(0, msIndex)) / 1000; | ||
} | ||
var sIndex = duration.indexOf("s"); | ||
if (sIndex !== -1 && duration.indexOf("days") === -1) { | ||
return parseFloat(duration.substr(0, sIndex)); | ||
} | ||
var dayTimeParts = duration.split(" days "); | ||
var days = dayTimeParts.length > 1 ? parseFloat(dayTimeParts[0]) : 0.0; | ||
var time = dayTimeParts.length > 1 ? dayTimeParts[1] : dayTimeParts[0]; | ||
var secs = 0.0; | ||
var timeParts = time.split(":").reverse(); | ||
for (var j = 0; j < timeParts.length; ++j) { | ||
secs += parseFloat(timeParts[j]) * Math.pow(60, j); | ||
} | ||
return (days * 24 * 60 * 60) + secs; | ||
} | ||
exports.espTime2Seconds = espTime2Seconds; | ||
}); | ||
// GH: <n>ns or <m>ms or <s>s or [<d> days ][<h>:][<m>:]<s>[.<ms>] | ||
var nsIndex = duration.indexOf("ns"); | ||
if (nsIndex !== -1) { | ||
return parseFloat(duration.substr(0, nsIndex)) / 1000000000; | ||
} | ||
var msIndex = duration.indexOf("ms"); | ||
if (msIndex !== -1) { | ||
return parseFloat(duration.substr(0, msIndex)) / 1000; | ||
} | ||
var sIndex = duration.indexOf("s"); | ||
if (sIndex !== -1 && duration.indexOf("days") === -1) { | ||
return parseFloat(duration.substr(0, sIndex)); | ||
} | ||
var dayTimeParts = duration.split(" days "); | ||
var days = dayTimeParts.length > 1 ? parseFloat(dayTimeParts[0]) : 0.0; | ||
var time = dayTimeParts.length > 1 ? dayTimeParts[1] : dayTimeParts[0]; | ||
var secs = 0.0; | ||
var timeParts = time.split(":").reverse(); | ||
for (var j = 0; j < timeParts.length; ++j) { | ||
secs += parseFloat(timeParts[j]) * Math.pow(60, j); | ||
} | ||
return (days * 24 * 60 * 60) + secs; | ||
} | ||
//# sourceMappingURL=esp.js.map |
734
lib/graph.js
@@ -1,385 +0,373 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import * as tslib_1 from "tslib"; | ||
import { Dictionary } from "./dictionary"; | ||
var ATTR_DEFINITION = "definition"; | ||
var GraphItem = /** @class */ (function () { | ||
function GraphItem(graph, parent, id, attrs) { | ||
this._graph = graph; | ||
this._parent = parent; | ||
this._id = id; | ||
this._attrs = new Dictionary(attrs); | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "tslib", "./dictionary"], factory); | ||
GraphItem.prototype.className = function () { | ||
return this.constructor.name; | ||
}; | ||
GraphItem.prototype.id = function () { | ||
return this._id; | ||
}; | ||
GraphItem.prototype.attrs = function () { | ||
return this._attrs; | ||
}; | ||
GraphItem.prototype.parent = function () { | ||
return this._parent; | ||
}; | ||
GraphItem.prototype.hasECLDefinition = function () { | ||
return this._attrs.get(ATTR_DEFINITION) !== undefined; | ||
}; | ||
GraphItem.prototype.getECLDefinition = function () { | ||
var match = /([a-z]:\\(?:[-\w\.\d]+\\)*(?:[-\w\.\d]+)?|(?:\/[\w\.\-]+)+)\((\d*),(\d*)\)/.exec(this._attrs.get(ATTR_DEFINITION)); | ||
if (match) { | ||
var _file = match[1], _row = match[2], _col = match[3]; | ||
_file.replace("/./", "/"); | ||
return { | ||
id: this.id(), | ||
file: _file, | ||
line: +_row, | ||
column: +_col | ||
}; | ||
} | ||
throw new Error("Bad definition: " + this._attrs.get(ATTR_DEFINITION)); | ||
}; | ||
return GraphItem; | ||
}()); | ||
var Subgraph = /** @class */ (function (_super) { | ||
tslib_1.__extends(Subgraph, _super); | ||
function Subgraph(graph, parent, id, attrs) { | ||
if (attrs === void 0) { attrs = {}; } | ||
var _this = _super.call(this, graph, parent, id, attrs) || this; | ||
_this._subgraphs = new Dictionary(); | ||
_this._vertices = new Dictionary(); | ||
_this._edges = new Dictionary(); | ||
if (parent) { | ||
parent.addSubgraph(_this); | ||
} | ||
return _this; | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var dictionary_1 = require("./dictionary"); | ||
var ATTR_DEFINITION = "definition"; | ||
var GraphItem = /** @class */ (function () { | ||
function GraphItem(graph, parent, id, attrs) { | ||
this._graph = graph; | ||
this._parent = parent; | ||
this._id = id; | ||
this._attrs = new dictionary_1.Dictionary(attrs); | ||
Subgraph.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._parent) { | ||
this._parent.removeSubgraph(this); | ||
} | ||
GraphItem.prototype.className = function () { | ||
return this.constructor.name; | ||
}; | ||
GraphItem.prototype.id = function () { | ||
return this._id; | ||
}; | ||
GraphItem.prototype.attrs = function () { | ||
return this._attrs; | ||
}; | ||
GraphItem.prototype.parent = function () { | ||
return this._parent; | ||
}; | ||
GraphItem.prototype.hasECLDefinition = function () { | ||
return this._attrs.get(ATTR_DEFINITION) !== undefined; | ||
}; | ||
GraphItem.prototype.getECLDefinition = function () { | ||
var match = /([a-z]:\\(?:[-\w\.\d]+\\)*(?:[-\w\.\d]+)?|(?:\/[\w\.\-]+)+)\((\d*),(\d*)\)/.exec(this._attrs.get(ATTR_DEFINITION)); | ||
if (match) { | ||
var _file = match[1], _row = match[2], _col = match[3]; | ||
_file.replace("/./", "/"); | ||
return { | ||
id: this.id(), | ||
file: _file, | ||
line: +_row, | ||
column: +_col | ||
}; | ||
} | ||
throw new Error("Bad definition: " + this._attrs.get(ATTR_DEFINITION)); | ||
}; | ||
return GraphItem; | ||
}()); | ||
var Subgraph = /** @class */ (function (_super) { | ||
tslib_1.__extends(Subgraph, _super); | ||
function Subgraph(graph, parent, id, attrs) { | ||
if (attrs === void 0) { attrs = {}; } | ||
var _this = _super.call(this, graph, parent, id, attrs) || this; | ||
_this._subgraphs = new dictionary_1.Dictionary(); | ||
_this._vertices = new dictionary_1.Dictionary(); | ||
_this._edges = new dictionary_1.Dictionary(); | ||
if (parent) { | ||
parent.addSubgraph(_this); | ||
} | ||
return _this; | ||
this._edges.values().forEach(function (edge) { return _this._graph.destroyEdge(edge); }); | ||
this._vertices.values().forEach(function (vertex) { return _this._graph.destroyVertex(vertex); }); | ||
this._subgraphs.values().forEach(function (subgraph) { return _this._graph.destroySubgraph(subgraph); }); | ||
}; | ||
Subgraph.prototype.remove = function () { | ||
this._graph.destroySubgraph(this); | ||
}; | ||
Subgraph.prototype.createSubgraph = function (id, attrs) { | ||
return this._graph.createSubgraph(this, id, attrs); | ||
}; | ||
Subgraph.prototype.addSubgraph = function (subgraph) { | ||
if (this._subgraphs.has(subgraph.id())) { | ||
throw new Error("Subgraph already exists"); | ||
} | ||
Subgraph.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._parent) { | ||
this._parent.removeSubgraph(this); | ||
} | ||
this._edges.values().forEach(function (edge) { return _this._graph.destroyEdge(edge); }); | ||
this._vertices.values().forEach(function (vertex) { return _this._graph.destroyVertex(vertex); }); | ||
this._subgraphs.values().forEach(function (subgraph) { return _this._graph.destroySubgraph(subgraph); }); | ||
}; | ||
Subgraph.prototype.remove = function () { | ||
this._graph.destroySubgraph(this); | ||
}; | ||
Subgraph.prototype.createSubgraph = function (id, attrs) { | ||
return this._graph.createSubgraph(this, id, attrs); | ||
}; | ||
Subgraph.prototype.addSubgraph = function (subgraph) { | ||
if (this._subgraphs.has(subgraph.id())) { | ||
throw new Error("Subgraph already exists"); | ||
} | ||
this._subgraphs.set(subgraph.id(), subgraph); | ||
}; | ||
Subgraph.prototype.removeSubgraph = function (subgraph) { | ||
if (!this._subgraphs.has(subgraph.id())) { | ||
throw new Error("Subgraph does not exist"); | ||
} | ||
this._subgraphs.remove(subgraph.id()); | ||
}; | ||
Subgraph.prototype.createVertex = function (id, label, attrs) { | ||
return this._graph.createVertex(this, id, label, attrs); | ||
}; | ||
Subgraph.prototype.addVertex = function (vertex) { | ||
if (this._vertices.has(vertex.id())) { | ||
throw new Error("Vertex already exists"); | ||
} | ||
this._vertices.set(vertex.id(), vertex); | ||
}; | ||
Subgraph.prototype.removeVertex = function (vertex) { | ||
if (!this._vertices.has(vertex.id())) { | ||
throw new Error("Vertex does not exist"); | ||
} | ||
this._vertices.remove(vertex.id()); | ||
}; | ||
Subgraph.prototype.createEdge = function (id, sourceID, targetID, attrs) { | ||
return this._graph.createEdge(this, id, sourceID, targetID, attrs); | ||
}; | ||
Subgraph.prototype.addEdge = function (edge) { | ||
if (this._edges.has(edge.id())) { | ||
throw new Error("Edge already exists"); | ||
} | ||
this._edges.set(edge.id(), edge); | ||
}; | ||
Subgraph.prototype.removeEdge = function (edge) { | ||
if (!this._edges.has(edge.id())) { | ||
throw new Error("Edge does not exist"); | ||
} | ||
this._edges.remove(edge.id()); | ||
}; | ||
Subgraph.prototype.add = function (item) { | ||
if (item instanceof Subgraph) { | ||
this.addSubgraph(item); | ||
} | ||
else if (item instanceof Vertex) { | ||
this.addVertex(item); | ||
} | ||
else { | ||
this.addEdge(item); | ||
} | ||
}; | ||
Subgraph.prototype.subgraphs = function () { | ||
return this._subgraphs.values(); | ||
}; | ||
Subgraph.prototype.vertices = function () { | ||
return this._vertices.values(); | ||
}; | ||
Subgraph.prototype.edges = function () { | ||
return this._edges.values(); | ||
}; | ||
Subgraph.prototype.getNearestDefinition = function (backwards) { | ||
if (backwards === void 0) { backwards = false; } | ||
// Todo - order is incorrect... | ||
if (this.hasECLDefinition()) { | ||
return this.getECLDefinition(); | ||
} | ||
var vertices = this.vertices(); | ||
if (backwards) { | ||
vertices = vertices.reverse(); | ||
} | ||
var retVal = null; | ||
vertices.some(function (vertex) { | ||
retVal = vertex.getNearestDefinition(backwards); | ||
if (retVal) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
return retVal; | ||
}; | ||
return Subgraph; | ||
}(GraphItem)); | ||
var Vertex = /** @class */ (function (_super) { | ||
tslib_1.__extends(Vertex, _super); | ||
function Vertex(graph, parent, id, label, attrs) { | ||
var _this = _super.call(this, graph, parent, id, attrs) || this; | ||
_this.inEdges = []; | ||
_this.outEdges = []; | ||
_this._label = label; | ||
parent.addVertex(_this); | ||
return _this; | ||
this._subgraphs.set(subgraph.id(), subgraph); | ||
}; | ||
Subgraph.prototype.removeSubgraph = function (subgraph) { | ||
if (!this._subgraphs.has(subgraph.id())) { | ||
throw new Error("Subgraph does not exist"); | ||
} | ||
Vertex.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._parent) { | ||
this._parent.removeVertex(this); | ||
this._subgraphs.remove(subgraph.id()); | ||
}; | ||
Subgraph.prototype.createVertex = function (id, label, attrs) { | ||
return this._graph.createVertex(this, id, label, attrs); | ||
}; | ||
Subgraph.prototype.addVertex = function (vertex) { | ||
if (this._vertices.has(vertex.id())) { | ||
throw new Error("Vertex already exists"); | ||
} | ||
this._vertices.set(vertex.id(), vertex); | ||
}; | ||
Subgraph.prototype.removeVertex = function (vertex) { | ||
if (!this._vertices.has(vertex.id())) { | ||
throw new Error("Vertex does not exist"); | ||
} | ||
this._vertices.remove(vertex.id()); | ||
}; | ||
Subgraph.prototype.createEdge = function (id, sourceID, targetID, attrs) { | ||
return this._graph.createEdge(this, id, sourceID, targetID, attrs); | ||
}; | ||
Subgraph.prototype.addEdge = function (edge) { | ||
if (this._edges.has(edge.id())) { | ||
throw new Error("Edge already exists"); | ||
} | ||
this._edges.set(edge.id(), edge); | ||
}; | ||
Subgraph.prototype.removeEdge = function (edge) { | ||
if (!this._edges.has(edge.id())) { | ||
throw new Error("Edge does not exist"); | ||
} | ||
this._edges.remove(edge.id()); | ||
}; | ||
Subgraph.prototype.add = function (item) { | ||
if (item instanceof Subgraph) { | ||
this.addSubgraph(item); | ||
} | ||
else if (item instanceof Vertex) { | ||
this.addVertex(item); | ||
} | ||
else { | ||
this.addEdge(item); | ||
} | ||
}; | ||
Subgraph.prototype.subgraphs = function () { | ||
return this._subgraphs.values(); | ||
}; | ||
Subgraph.prototype.vertices = function () { | ||
return this._vertices.values(); | ||
}; | ||
Subgraph.prototype.edges = function () { | ||
return this._edges.values(); | ||
}; | ||
Subgraph.prototype.getNearestDefinition = function (backwards) { | ||
if (backwards === void 0) { backwards = false; } | ||
// Todo - order is incorrect... | ||
if (this.hasECLDefinition()) { | ||
return this.getECLDefinition(); | ||
} | ||
var vertices = this.vertices(); | ||
if (backwards) { | ||
vertices = vertices.reverse(); | ||
} | ||
var retVal = null; | ||
vertices.some(function (vertex) { | ||
retVal = vertex.getNearestDefinition(backwards); | ||
if (retVal) { | ||
return true; | ||
} | ||
this.inEdges.forEach(function (edge) { return _this._graph.destroyEdge(edge); }); | ||
this.outEdges.forEach(function (edge) { return _this._graph.destroyEdge(edge); }); | ||
}; | ||
Vertex.prototype.label = function () { | ||
return this._label; | ||
}; | ||
Vertex.prototype.addInEdge = function (edge) { | ||
this.inEdges.push(edge); | ||
}; | ||
Vertex.prototype.removeInEdge = function (edge) { | ||
var idx = this.inEdges.indexOf(edge); | ||
if (idx < 0) { | ||
throw new Error("In edge does not exist"); | ||
} | ||
this.inEdges.splice(idx, 1); | ||
}; | ||
Vertex.prototype.addOutEdge = function (edge) { | ||
this.outEdges.push(edge); | ||
}; | ||
Vertex.prototype.removeOutEdge = function (edge) { | ||
var idx = this.outEdges.indexOf(edge); | ||
if (idx < 0) { | ||
throw new Error("Out edge does not exist"); | ||
} | ||
this.outEdges.splice(idx, 1); | ||
}; | ||
Vertex.prototype.getNearestDefinition = function (backwards) { | ||
if (backwards === void 0) { backwards = true; } | ||
if (this.hasECLDefinition()) { | ||
return this.getECLDefinition(); | ||
} | ||
var retVal = null; | ||
this.inEdges.some(function (edge) { | ||
retVal = edge.getNearestDefinition(backwards); | ||
if (retVal) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
return retVal; | ||
}; | ||
return Vertex; | ||
}(GraphItem)); | ||
var Edge = /** @class */ (function (_super) { | ||
tslib_1.__extends(Edge, _super); | ||
function Edge(graph, parent, id, source, target, attrs) { | ||
var _this = _super.call(this, graph, parent, id, attrs) || this; | ||
if (!source) { | ||
throw new Error("Missing source vertex"); | ||
} | ||
if (!target) { | ||
throw new Error("Missing target vertex"); | ||
} | ||
parent.addEdge(_this); | ||
_this.source = source; | ||
_this.source.addOutEdge(_this); | ||
_this.target = target; | ||
_this.target.addInEdge(_this); | ||
return _this; | ||
return false; | ||
}); | ||
return retVal; | ||
}; | ||
return Subgraph; | ||
}(GraphItem)); | ||
var Vertex = /** @class */ (function (_super) { | ||
tslib_1.__extends(Vertex, _super); | ||
function Vertex(graph, parent, id, label, attrs) { | ||
var _this = _super.call(this, graph, parent, id, attrs) || this; | ||
_this.inEdges = []; | ||
_this.outEdges = []; | ||
_this._label = label; | ||
parent.addVertex(_this); | ||
return _this; | ||
} | ||
Vertex.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._parent) { | ||
this._parent.removeVertex(this); | ||
} | ||
Edge.prototype.sourceID = function () { | ||
return this.source.id(); | ||
}; | ||
Edge.prototype.targetID = function () { | ||
return this.target.id(); | ||
}; | ||
Edge.prototype.destroy = function () { | ||
if (this._parent) { | ||
this._parent.removeEdge(this); | ||
this.inEdges.forEach(function (edge) { return _this._graph.destroyEdge(edge); }); | ||
this.outEdges.forEach(function (edge) { return _this._graph.destroyEdge(edge); }); | ||
}; | ||
Vertex.prototype.label = function () { | ||
return this._label; | ||
}; | ||
Vertex.prototype.addInEdge = function (edge) { | ||
this.inEdges.push(edge); | ||
}; | ||
Vertex.prototype.removeInEdge = function (edge) { | ||
var idx = this.inEdges.indexOf(edge); | ||
if (idx < 0) { | ||
throw new Error("In edge does not exist"); | ||
} | ||
this.inEdges.splice(idx, 1); | ||
}; | ||
Vertex.prototype.addOutEdge = function (edge) { | ||
this.outEdges.push(edge); | ||
}; | ||
Vertex.prototype.removeOutEdge = function (edge) { | ||
var idx = this.outEdges.indexOf(edge); | ||
if (idx < 0) { | ||
throw new Error("Out edge does not exist"); | ||
} | ||
this.outEdges.splice(idx, 1); | ||
}; | ||
Vertex.prototype.getNearestDefinition = function (backwards) { | ||
if (backwards === void 0) { backwards = true; } | ||
if (this.hasECLDefinition()) { | ||
return this.getECLDefinition(); | ||
} | ||
var retVal = null; | ||
this.inEdges.some(function (edge) { | ||
retVal = edge.getNearestDefinition(backwards); | ||
if (retVal) { | ||
return true; | ||
} | ||
this.source.removeOutEdge(this); | ||
this.target.removeInEdge(this); | ||
}; | ||
Edge.prototype.getNearestDefinition = function (backwards) { | ||
if (backwards === void 0) { backwards = false; } | ||
if (this.hasECLDefinition()) { | ||
return this.getECLDefinition(); | ||
} | ||
return this.source.getNearestDefinition(backwards); | ||
}; | ||
return Edge; | ||
}(Subgraph)); | ||
var Graph = /** @class */ (function () { | ||
function Graph(id, attrs) { | ||
this._allSubgraphs = new dictionary_1.Dictionary(); | ||
this._allVertices = new dictionary_1.Dictionary(); | ||
this._allEdges = new dictionary_1.Dictionary(); | ||
this._attrs = new dictionary_1.Dictionary(); | ||
this._root = new Subgraph(this, null, id, attrs); | ||
this._allSubgraphs.set(id, this._root); | ||
return false; | ||
}); | ||
return retVal; | ||
}; | ||
return Vertex; | ||
}(GraphItem)); | ||
var Edge = /** @class */ (function (_super) { | ||
tslib_1.__extends(Edge, _super); | ||
function Edge(graph, parent, id, source, target, attrs) { | ||
var _this = _super.call(this, graph, parent, id, attrs) || this; | ||
if (!source) { | ||
throw new Error("Missing source vertex"); | ||
} | ||
Graph.prototype.className = function () { | ||
return "Graph"; | ||
}; | ||
Graph.prototype.id = function () { | ||
return this._root.id(); | ||
}; | ||
Graph.prototype.attrs = function () { | ||
return this._attrs; | ||
}; | ||
Graph.prototype.parent = function () { | ||
return null; | ||
}; | ||
Graph.prototype.remove = function () { | ||
// Do nothing --- | ||
}; | ||
Graph.prototype.subgraphs = function () { | ||
return this._root.subgraphs(); | ||
}; | ||
Graph.prototype.vertices = function () { | ||
return this._root.vertices(); | ||
}; | ||
Graph.prototype.edges = function () { | ||
return this._root.edges(); | ||
}; | ||
Graph.prototype.createSubgraph = function (parent, id, attrs) { | ||
if (this._allSubgraphs.has(id)) { | ||
throw new Error("Subgraph already exists"); | ||
} | ||
var retVal = new Subgraph(this, this._allSubgraphs.get(parent.id()), id, attrs); | ||
this._allSubgraphs.set(id, retVal); | ||
return retVal; | ||
}; | ||
Graph.prototype.destroySubgraph = function (_subgraph) { | ||
var subgraph = this._allSubgraphs.get(_subgraph.id()); | ||
if (!subgraph) { | ||
throw new Error("Subgraph does not exist"); | ||
} | ||
this._allSubgraphs.remove(subgraph.id()); | ||
subgraph.destroy(); | ||
}; | ||
Graph.prototype.createVertex = function (parent, id, label, attrs) { | ||
if (this._allVertices.has(id)) { | ||
throw new Error("Vertex already exists"); | ||
} | ||
var retVal = new Vertex(this, this._allSubgraphs.get(parent.id()), id, label, attrs); | ||
this._allVertices.set(id, retVal); | ||
return retVal; | ||
}; | ||
Graph.prototype.destroyVertex = function (_vertex) { | ||
var vertex = this._allVertices.get(_vertex.id()); | ||
if (!vertex) { | ||
throw new Error("Vertex does not exist"); | ||
} | ||
this._allVertices.remove(vertex.id()); | ||
vertex.destroy(); | ||
}; | ||
Graph.prototype.createEdge = function (parent, id, sourceID, targetID, attrs) { | ||
if (this._allEdges.has(id)) { | ||
throw new Error("Edge already exists"); | ||
} | ||
var retVal = new Edge(this, this._allSubgraphs.get(parent.id()), id, this._allVertices.get(sourceID), this._allVertices.get(targetID), attrs); | ||
this._allEdges.set(id, retVal); | ||
return retVal; | ||
}; | ||
Graph.prototype.destroyEdge = function (_edge) { | ||
var edge = this._allEdges.get(_edge.id()); | ||
if (!edge) { | ||
throw new Error("Edge does not exist"); | ||
} | ||
this._allEdges.remove(edge.id()); | ||
edge.destroy(); | ||
}; | ||
Graph.prototype.allSubgraph = function (id) { | ||
return this._allSubgraphs.get(id); | ||
}; | ||
Graph.prototype.allSubgraphs = function () { | ||
var _this = this; | ||
return this._allSubgraphs.values().filter(function (subgraph) { return subgraph !== _this._root; }); | ||
}; | ||
Graph.prototype.allVertex = function (id) { | ||
return this._allVertices.get(id); | ||
}; | ||
Graph.prototype.allVertices = function () { | ||
return this._allVertices.values(); | ||
}; | ||
Graph.prototype.allEdge = function (id) { | ||
return this._allEdges.get(id); | ||
}; | ||
Graph.prototype.allEdges = function () { | ||
return this._allEdges.values(); | ||
}; | ||
Graph.prototype.getNearestDefinition = function (backwards) { | ||
if (backwards === void 0) { backwards = false; } | ||
return this._root.getNearestDefinition(backwards); | ||
}; | ||
Graph.prototype.breakpointLocations = function (path) { | ||
var retVal = []; | ||
for (var _i = 0, _a = this._allVertices.values(); _i < _a.length; _i++) { | ||
var vertex = _a[_i]; | ||
if (vertex.hasECLDefinition()) { | ||
var definition = vertex.getECLDefinition(); | ||
if (definition && !path || path === definition.file) { | ||
retVal.push(definition); | ||
} | ||
if (!target) { | ||
throw new Error("Missing target vertex"); | ||
} | ||
parent.addEdge(_this); | ||
_this.source = source; | ||
_this.source.addOutEdge(_this); | ||
_this.target = target; | ||
_this.target.addInEdge(_this); | ||
return _this; | ||
} | ||
Edge.prototype.sourceID = function () { | ||
return this.source.id(); | ||
}; | ||
Edge.prototype.targetID = function () { | ||
return this.target.id(); | ||
}; | ||
Edge.prototype.destroy = function () { | ||
if (this._parent) { | ||
this._parent.removeEdge(this); | ||
} | ||
this.source.removeOutEdge(this); | ||
this.target.removeInEdge(this); | ||
}; | ||
Edge.prototype.getNearestDefinition = function (backwards) { | ||
if (backwards === void 0) { backwards = false; } | ||
if (this.hasECLDefinition()) { | ||
return this.getECLDefinition(); | ||
} | ||
return this.source.getNearestDefinition(backwards); | ||
}; | ||
return Edge; | ||
}(Subgraph)); | ||
var Graph = /** @class */ (function () { | ||
function Graph(id, attrs) { | ||
this._allSubgraphs = new Dictionary(); | ||
this._allVertices = new Dictionary(); | ||
this._allEdges = new Dictionary(); | ||
this._attrs = new Dictionary(); | ||
this._root = new Subgraph(this, null, id, attrs); | ||
this._allSubgraphs.set(id, this._root); | ||
} | ||
Graph.prototype.className = function () { | ||
return "Graph"; | ||
}; | ||
Graph.prototype.id = function () { | ||
return this._root.id(); | ||
}; | ||
Graph.prototype.attrs = function () { | ||
return this._attrs; | ||
}; | ||
Graph.prototype.parent = function () { | ||
return null; | ||
}; | ||
Graph.prototype.remove = function () { | ||
// Do nothing --- | ||
}; | ||
Graph.prototype.subgraphs = function () { | ||
return this._root.subgraphs(); | ||
}; | ||
Graph.prototype.vertices = function () { | ||
return this._root.vertices(); | ||
}; | ||
Graph.prototype.edges = function () { | ||
return this._root.edges(); | ||
}; | ||
Graph.prototype.createSubgraph = function (parent, id, attrs) { | ||
if (this._allSubgraphs.has(id)) { | ||
throw new Error("Subgraph already exists"); | ||
} | ||
var retVal = new Subgraph(this, this._allSubgraphs.get(parent.id()), id, attrs); | ||
this._allSubgraphs.set(id, retVal); | ||
return retVal; | ||
}; | ||
Graph.prototype.destroySubgraph = function (_subgraph) { | ||
var subgraph = this._allSubgraphs.get(_subgraph.id()); | ||
if (!subgraph) { | ||
throw new Error("Subgraph does not exist"); | ||
} | ||
this._allSubgraphs.remove(subgraph.id()); | ||
subgraph.destroy(); | ||
}; | ||
Graph.prototype.createVertex = function (parent, id, label, attrs) { | ||
if (this._allVertices.has(id)) { | ||
throw new Error("Vertex already exists"); | ||
} | ||
var retVal = new Vertex(this, this._allSubgraphs.get(parent.id()), id, label, attrs); | ||
this._allVertices.set(id, retVal); | ||
return retVal; | ||
}; | ||
Graph.prototype.destroyVertex = function (_vertex) { | ||
var vertex = this._allVertices.get(_vertex.id()); | ||
if (!vertex) { | ||
throw new Error("Vertex does not exist"); | ||
} | ||
this._allVertices.remove(vertex.id()); | ||
vertex.destroy(); | ||
}; | ||
Graph.prototype.createEdge = function (parent, id, sourceID, targetID, attrs) { | ||
if (this._allEdges.has(id)) { | ||
throw new Error("Edge already exists"); | ||
} | ||
var retVal = new Edge(this, this._allSubgraphs.get(parent.id()), id, this._allVertices.get(sourceID), this._allVertices.get(targetID), attrs); | ||
this._allEdges.set(id, retVal); | ||
return retVal; | ||
}; | ||
Graph.prototype.destroyEdge = function (_edge) { | ||
var edge = this._allEdges.get(_edge.id()); | ||
if (!edge) { | ||
throw new Error("Edge does not exist"); | ||
} | ||
this._allEdges.remove(edge.id()); | ||
edge.destroy(); | ||
}; | ||
Graph.prototype.allSubgraph = function (id) { | ||
return this._allSubgraphs.get(id); | ||
}; | ||
Graph.prototype.allSubgraphs = function () { | ||
var _this = this; | ||
return this._allSubgraphs.values().filter(function (subgraph) { return subgraph !== _this._root; }); | ||
}; | ||
Graph.prototype.allVertex = function (id) { | ||
return this._allVertices.get(id); | ||
}; | ||
Graph.prototype.allVertices = function () { | ||
return this._allVertices.values(); | ||
}; | ||
Graph.prototype.allEdge = function (id) { | ||
return this._allEdges.get(id); | ||
}; | ||
Graph.prototype.allEdges = function () { | ||
return this._allEdges.values(); | ||
}; | ||
Graph.prototype.getNearestDefinition = function (backwards) { | ||
if (backwards === void 0) { backwards = false; } | ||
return this._root.getNearestDefinition(backwards); | ||
}; | ||
Graph.prototype.breakpointLocations = function (path) { | ||
var retVal = []; | ||
for (var _i = 0, _a = this._allVertices.values(); _i < _a.length; _i++) { | ||
var vertex = _a[_i]; | ||
if (vertex.hasECLDefinition()) { | ||
var definition = vertex.getECLDefinition(); | ||
if (definition && !path || path === definition.file) { | ||
retVal.push(definition); | ||
} | ||
} | ||
return retVal.sort(function (l, r) { | ||
return l.line - r.line; | ||
}); | ||
}; | ||
return Graph; | ||
}()); | ||
exports.Graph = Graph; | ||
}); | ||
} | ||
return retVal.sort(function (l, r) { | ||
return l.line - r.line; | ||
}); | ||
}; | ||
return Graph; | ||
}()); | ||
export { Graph }; | ||
//# sourceMappingURL=graph.js.map |
// Ported to TypeScript from: https://github.com/bevacqua/hash-sum | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
function pad(hash, len) { | ||
while (hash.length < len) { | ||
hash = "0" + hash; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function pad(hash, len) { | ||
while (hash.length < len) { | ||
hash = "0" + hash; | ||
} | ||
return hash; | ||
} | ||
function fold(hash, text) { | ||
if (text.length === 0) { | ||
return hash; | ||
} | ||
function fold(hash, text) { | ||
if (text.length === 0) { | ||
return hash; | ||
} | ||
for (var i = 0; i < text.length; ++i) { | ||
var chr = text.charCodeAt(i); | ||
// tslint:disable:no-bitwise | ||
hash = ((hash << 5) - hash) + chr; | ||
hash |= 0; | ||
// tslint:enable:no-bitwise | ||
} | ||
return hash < 0 ? hash * -2 : hash; | ||
for (var i = 0; i < text.length; ++i) { | ||
var chr = text.charCodeAt(i); | ||
// tslint:disable:no-bitwise | ||
hash = ((hash << 5) - hash) + chr; | ||
hash |= 0; | ||
// tslint:enable:no-bitwise | ||
} | ||
function foldObject(hash, o, seen) { | ||
return Object.keys(o).sort().reduce(function (input, key) { | ||
return foldValue(input, o[key], key, seen); | ||
}, hash); | ||
return hash < 0 ? hash * -2 : hash; | ||
} | ||
function foldObject(hash, o, seen) { | ||
return Object.keys(o).sort().reduce(function (input, key) { | ||
return foldValue(input, o[key], key, seen); | ||
}, hash); | ||
} | ||
function foldValue(input, value, key, seen) { | ||
var hash = fold(fold(fold(input, key), toString(value)), typeof value); | ||
if (value === null) { | ||
return fold(hash, "null"); | ||
} | ||
function foldValue(input, value, key, seen) { | ||
var hash = fold(fold(fold(input, key), toString(value)), typeof value); | ||
if (value === null) { | ||
return fold(hash, "null"); | ||
if (value === undefined) { | ||
return fold(hash, "undefined"); | ||
} | ||
if (typeof value === "object") { | ||
if (seen.indexOf(value) !== -1) { | ||
return fold(hash, "[Circular]" + key); | ||
} | ||
if (value === undefined) { | ||
return fold(hash, "undefined"); | ||
} | ||
if (typeof value === "object") { | ||
if (seen.indexOf(value) !== -1) { | ||
return fold(hash, "[Circular]" + key); | ||
} | ||
seen.push(value); | ||
return foldObject(hash, value, seen); | ||
} | ||
return fold(hash, value.toString()); | ||
seen.push(value); | ||
return foldObject(hash, value, seen); | ||
} | ||
function toString(o) { | ||
return Object.prototype.toString.call(o); | ||
} | ||
function hashSum(o) { | ||
return pad(foldValue(0, o, "", []).toString(16), 8); | ||
} | ||
exports.hashSum = hashSum; | ||
}); | ||
return fold(hash, value.toString()); | ||
} | ||
function toString(o) { | ||
return Object.prototype.toString.call(o); | ||
} | ||
export function hashSum(o) { | ||
return pad(foldValue(0, o, "", []).toString(16), 8); | ||
} | ||
//# sourceMappingURL=hashSum.js.map |
@@ -18,2 +18,3 @@ export * from "./array"; | ||
export * from "./url"; | ||
import "es6-promise/auto"; | ||
export * from "tslib"; |
@@ -1,33 +0,21 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "tslib", "./array", "./cache", "./debounce", "./dictionary", "./esp", "./graph", "./hashSum", "./loader", "./logging", "./object", "./observer", "./platform", "./saxParser", "./stack", "./stateful", "./string", "./url", "tslib"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./array"), exports); | ||
tslib_1.__exportStar(require("./cache"), exports); | ||
tslib_1.__exportStar(require("./debounce"), exports); | ||
tslib_1.__exportStar(require("./dictionary"), exports); | ||
tslib_1.__exportStar(require("./esp"), exports); | ||
tslib_1.__exportStar(require("./graph"), exports); | ||
tslib_1.__exportStar(require("./hashSum"), exports); | ||
tslib_1.__exportStar(require("./loader"), exports); | ||
tslib_1.__exportStar(require("./logging"), exports); | ||
tslib_1.__exportStar(require("./object"), exports); | ||
tslib_1.__exportStar(require("./observer"), exports); | ||
tslib_1.__exportStar(require("./platform"), exports); | ||
tslib_1.__exportStar(require("./saxParser"), exports); | ||
tslib_1.__exportStar(require("./stack"), exports); | ||
tslib_1.__exportStar(require("./stateful"), exports); | ||
tslib_1.__exportStar(require("./string"), exports); | ||
tslib_1.__exportStar(require("./url"), exports); | ||
// Third Party --- | ||
tslib_1.__exportStar(require("tslib"), exports); | ||
}); | ||
export * from "./array"; | ||
export * from "./cache"; | ||
export * from "./debounce"; | ||
export * from "./dictionary"; | ||
export * from "./esp"; | ||
export * from "./graph"; | ||
export * from "./hashSum"; | ||
export * from "./loader"; | ||
export * from "./logging"; | ||
export * from "./object"; | ||
export * from "./observer"; | ||
export * from "./platform"; | ||
export * from "./saxParser"; | ||
export * from "./stack"; | ||
export * from "./stateful"; | ||
export * from "./string"; | ||
export * from "./url"; | ||
// Third Party --- | ||
import "es6-promise/auto"; | ||
export * from "tslib"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,39 +0,26 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./logging"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var logging_1 = require("./logging"); | ||
var logger = logging_1.scopedLogger("loader"); | ||
function dynamicImport(packageStr) { | ||
return new Promise(function (resolve, reject) { | ||
if (require) { | ||
try { | ||
require([packageStr], function () { | ||
var packages = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
packages[_i] = arguments[_i]; | ||
} | ||
resolve(packages[0]); | ||
}); | ||
} | ||
catch (_a) { | ||
logger.error("require([" + packageStr + "], ...) failed"); | ||
reject("require([" + packageStr + "], ...) failed"); | ||
} | ||
import { scopedLogger } from "./logging"; | ||
var logger = scopedLogger("loader"); | ||
export function dynamicImport(packageStr) { | ||
return new Promise(function (resolve, reject) { | ||
if (require) { | ||
try { | ||
require([packageStr], function () { | ||
var packages = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
packages[_i] = arguments[_i]; | ||
} | ||
resolve(packages[0]); | ||
}); | ||
} | ||
else { | ||
logger.error("\"require\" is needed for dynamic loader."); | ||
reject("\"require\" is needed for dynamic loader."); | ||
catch (_a) { | ||
logger.error("require([" + packageStr + "], ...) failed"); | ||
reject("require([" + packageStr + "], ...) failed"); | ||
} | ||
}); | ||
} | ||
exports.dynamicImport = dynamicImport; | ||
}); | ||
} | ||
else { | ||
logger.error("\"require\" is needed for dynamic loader."); | ||
reject("\"require\" is needed for dynamic loader."); | ||
} | ||
}); | ||
} | ||
//# sourceMappingURL=loader.js.map |
@@ -1,185 +0,172 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import { isNode } from "./platform"; | ||
import { Stack } from "./stack"; | ||
export var Level; | ||
(function (Level) { | ||
Level[Level["debug"] = 0] = "debug"; | ||
Level[Level["info"] = 1] = "info"; | ||
Level[Level["notice"] = 2] = "notice"; | ||
Level[Level["warning"] = 3] = "warning"; | ||
Level[Level["error"] = 4] = "error"; | ||
Level[Level["critical"] = 5] = "critical"; | ||
Level[Level["alert"] = 6] = "alert"; | ||
Level[Level["emergency"] = 7] = "emergency"; | ||
})(Level || (Level = {})); | ||
var colours = { | ||
debug: "cyan", | ||
info: "green", | ||
notice: "grey", | ||
warning: "blue", | ||
error: "red", | ||
critical: "magenta", | ||
alert: "magenta", | ||
emergency: "magenta" | ||
}; | ||
var ConsoleWriter = /** @class */ (function () { | ||
function ConsoleWriter() { | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./platform", "./stack"], factory); | ||
ConsoleWriter.prototype.write = function (dateTime, level, id, msg) { | ||
if (isNode) { | ||
// tslint:disable-next-line:no-console | ||
console.log("[" + dateTime + "] " + Level[level].toUpperCase() + " " + id + ": " + msg); | ||
} | ||
else { | ||
// tslint:disable-next-line:no-console | ||
console.log("[" + dateTime + "] %c" + Level[level].toUpperCase() + "%c " + id + ": " + msg, "color:" + colours[Level[level]], ""); | ||
} | ||
}; | ||
return ConsoleWriter; | ||
}()); | ||
var Logging = /** @class */ (function () { | ||
function Logging() { | ||
this._levelStack = new Stack(); | ||
this._level = Level.info; | ||
this._filter = ""; | ||
this._writer = new ConsoleWriter(); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var platform_1 = require("./platform"); | ||
var stack_1 = require("./stack"); | ||
var Level; | ||
(function (Level) { | ||
Level[Level["debug"] = 0] = "debug"; | ||
Level[Level["info"] = 1] = "info"; | ||
Level[Level["notice"] = 2] = "notice"; | ||
Level[Level["warning"] = 3] = "warning"; | ||
Level[Level["error"] = 4] = "error"; | ||
Level[Level["critical"] = 5] = "critical"; | ||
Level[Level["alert"] = 6] = "alert"; | ||
Level[Level["emergency"] = 7] = "emergency"; | ||
})(Level = exports.Level || (exports.Level = {})); | ||
var colours = { | ||
debug: "cyan", | ||
info: "green", | ||
notice: "grey", | ||
warning: "blue", | ||
error: "red", | ||
critical: "magenta", | ||
alert: "magenta", | ||
emergency: "magenta" | ||
Logging.Instance = function () { | ||
return this._instance || (this._instance = new this()); | ||
}; | ||
var ConsoleWriter = /** @class */ (function () { | ||
function ConsoleWriter() { | ||
} | ||
ConsoleWriter.prototype.write = function (dateTime, level, id, msg) { | ||
if (platform_1.isNode) { | ||
// tslint:disable-next-line:no-console | ||
console.log("[" + dateTime + "] " + Level[level].toUpperCase() + " " + id + ": " + msg); | ||
} | ||
else { | ||
// tslint:disable-next-line:no-console | ||
console.log("[" + dateTime + "] %c" + Level[level].toUpperCase() + "%c " + id + ": " + msg, "color:" + colours[Level[level]], ""); | ||
} | ||
}; | ||
return ConsoleWriter; | ||
}()); | ||
var Logging = /** @class */ (function () { | ||
function Logging() { | ||
this._levelStack = new stack_1.Stack(); | ||
this._level = Level.info; | ||
this._filter = ""; | ||
this._writer = new ConsoleWriter(); | ||
} | ||
Logging.Instance = function () { | ||
return this._instance || (this._instance = new this()); | ||
}; | ||
Logging.prototype.stringify = function (obj) { | ||
var cache = []; | ||
return JSON.stringify(obj, function (_key, value) { | ||
if (typeof value === "object" && value !== null) { | ||
if (cache.indexOf(value) !== -1) { | ||
return; | ||
} | ||
cache.push(value); | ||
Logging.prototype.stringify = function (obj) { | ||
var cache = []; | ||
return JSON.stringify(obj, function (_key, value) { | ||
if (typeof value === "object" && value !== null) { | ||
if (cache.indexOf(value) !== -1) { | ||
return; | ||
} | ||
return value; | ||
}, 2); | ||
}; | ||
Logging.prototype.writer = function (_) { | ||
if (_ === void 0) | ||
return this._writer; | ||
this._writer = _; | ||
return this; | ||
}; | ||
Logging.prototype.log = function (level, id, msg) { | ||
if (level < this._level) | ||
return; | ||
if (this._filter && this._filter !== id) | ||
return; | ||
if (typeof msg !== "string") { | ||
msg = this.stringify(msg); | ||
cache.push(value); | ||
} | ||
this._writer.write(new Date().toISOString(), level, id, msg); | ||
}; | ||
Logging.prototype.debug = function (id, msg) { | ||
this.log(Level.debug, id, msg); | ||
}; | ||
Logging.prototype.info = function (id, msg) { | ||
this.log(Level.info, id, msg); | ||
}; | ||
Logging.prototype.notice = function (id, msg) { | ||
this.log(Level.notice, id, msg); | ||
}; | ||
Logging.prototype.warning = function (id, msg) { | ||
this.log(Level.warning, id, msg); | ||
}; | ||
Logging.prototype.error = function (id, msg) { | ||
this.log(Level.error, id, msg); | ||
}; | ||
Logging.prototype.critical = function (id, msg) { | ||
this.log(Level.critical, id, msg); | ||
}; | ||
Logging.prototype.alert = function (id, msg) { | ||
this.log(Level.alert, id, msg); | ||
}; | ||
Logging.prototype.emergency = function (id, msg) { | ||
this.log(Level.emergency, id, msg); | ||
}; | ||
Logging.prototype.level = function (_) { | ||
if (_ === void 0) | ||
return this._level; | ||
this._level = _; | ||
return this; | ||
}; | ||
Logging.prototype.pushLevel = function (_) { | ||
this._levelStack.push(this._level); | ||
this._level = _; | ||
return this; | ||
}; | ||
Logging.prototype.popLevel = function () { | ||
this._level = this._levelStack.pop(); | ||
return this; | ||
}; | ||
Logging.prototype.filter = function (_) { | ||
if (_ === void 0) | ||
return this._filter; | ||
this._filter = _; | ||
return this; | ||
}; | ||
return Logging; | ||
}()); | ||
exports.Logging = Logging; | ||
exports.logger = Logging.Instance(); | ||
var ScopedLogging = /** @class */ (function () { | ||
function ScopedLogging(scopeID) { | ||
this._scopeID = scopeID; | ||
return value; | ||
}, 2); | ||
}; | ||
Logging.prototype.writer = function (_) { | ||
if (_ === void 0) | ||
return this._writer; | ||
this._writer = _; | ||
return this; | ||
}; | ||
Logging.prototype.log = function (level, id, msg) { | ||
if (level < this._level) | ||
return; | ||
if (this._filter && this._filter !== id) | ||
return; | ||
if (typeof msg !== "string") { | ||
msg = this.stringify(msg); | ||
} | ||
ScopedLogging.prototype.debug = function (msg) { | ||
exports.logger.debug(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.info = function (msg) { | ||
exports.logger.info(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.notice = function (msg) { | ||
exports.logger.notice(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.warning = function (msg) { | ||
exports.logger.warning(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.error = function (msg) { | ||
exports.logger.error(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.critical = function (msg) { | ||
exports.logger.critical(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.alert = function (msg) { | ||
exports.logger.alert(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.emergency = function (msg) { | ||
exports.logger.emergency(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.pushLevel = function (_) { | ||
exports.logger.pushLevel(_); | ||
return this; | ||
}; | ||
ScopedLogging.prototype.popLevel = function () { | ||
exports.logger.popLevel(); | ||
return this; | ||
}; | ||
return ScopedLogging; | ||
}()); | ||
exports.ScopedLogging = ScopedLogging; | ||
function scopedLogger(scopeID, filter) { | ||
if (filter === void 0) { filter = true; } | ||
if (filter) { | ||
exports.logger.filter(scopeID); | ||
} | ||
return new ScopedLogging(scopeID); | ||
this._writer.write(new Date().toISOString(), level, id, msg); | ||
}; | ||
Logging.prototype.debug = function (id, msg) { | ||
this.log(Level.debug, id, msg); | ||
}; | ||
Logging.prototype.info = function (id, msg) { | ||
this.log(Level.info, id, msg); | ||
}; | ||
Logging.prototype.notice = function (id, msg) { | ||
this.log(Level.notice, id, msg); | ||
}; | ||
Logging.prototype.warning = function (id, msg) { | ||
this.log(Level.warning, id, msg); | ||
}; | ||
Logging.prototype.error = function (id, msg) { | ||
this.log(Level.error, id, msg); | ||
}; | ||
Logging.prototype.critical = function (id, msg) { | ||
this.log(Level.critical, id, msg); | ||
}; | ||
Logging.prototype.alert = function (id, msg) { | ||
this.log(Level.alert, id, msg); | ||
}; | ||
Logging.prototype.emergency = function (id, msg) { | ||
this.log(Level.emergency, id, msg); | ||
}; | ||
Logging.prototype.level = function (_) { | ||
if (_ === void 0) | ||
return this._level; | ||
this._level = _; | ||
return this; | ||
}; | ||
Logging.prototype.pushLevel = function (_) { | ||
this._levelStack.push(this._level); | ||
this._level = _; | ||
return this; | ||
}; | ||
Logging.prototype.popLevel = function () { | ||
this._level = this._levelStack.pop(); | ||
return this; | ||
}; | ||
Logging.prototype.filter = function (_) { | ||
if (_ === void 0) | ||
return this._filter; | ||
this._filter = _; | ||
return this; | ||
}; | ||
return Logging; | ||
}()); | ||
export { Logging }; | ||
export var logger = Logging.Instance(); | ||
var ScopedLogging = /** @class */ (function () { | ||
function ScopedLogging(scopeID) { | ||
this._scopeID = scopeID; | ||
} | ||
exports.scopedLogger = scopedLogger; | ||
}); | ||
ScopedLogging.prototype.debug = function (msg) { | ||
logger.debug(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.info = function (msg) { | ||
logger.info(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.notice = function (msg) { | ||
logger.notice(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.warning = function (msg) { | ||
logger.warning(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.error = function (msg) { | ||
logger.error(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.critical = function (msg) { | ||
logger.critical(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.alert = function (msg) { | ||
logger.alert(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.emergency = function (msg) { | ||
logger.emergency(this._scopeID, msg); | ||
}; | ||
ScopedLogging.prototype.pushLevel = function (_) { | ||
logger.pushLevel(_); | ||
return this; | ||
}; | ||
ScopedLogging.prototype.popLevel = function () { | ||
logger.popLevel(); | ||
return this; | ||
}; | ||
return ScopedLogging; | ||
}()); | ||
export { ScopedLogging }; | ||
export function scopedLogger(scopeID, filter) { | ||
if (filter === void 0) { filter = true; } | ||
if (filter) { | ||
logger.filter(scopeID); | ||
} | ||
return new ScopedLogging(scopeID); | ||
} | ||
//# sourceMappingURL=logging.js.map |
@@ -1,119 +0,102 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* inner - return inner property of Object | ||
* Usage: inner("some.prop.to.locate", obj); | ||
* | ||
* @param prop - property to locate | ||
* @param obj - object to locate property in | ||
*/ | ||
function inner(prop, obj) { | ||
if (prop === void 0 || obj === void 0) | ||
return void 0; | ||
for (var _i = 0, _a = prop.split("."); _i < _a.length; _i++) { | ||
var item = _a[_i]; | ||
if (!obj.hasOwnProperty(item)) { | ||
return undefined; | ||
} | ||
obj = obj[item]; | ||
/** | ||
* inner - return inner property of Object | ||
* Usage: inner("some.prop.to.locate", obj); | ||
* | ||
* @param prop - property to locate | ||
* @param obj - object to locate property in | ||
*/ | ||
export function inner(prop, obj) { | ||
if (prop === void 0 || obj === void 0) | ||
return void 0; | ||
for (var _i = 0, _a = prop.split("."); _i < _a.length; _i++) { | ||
var item = _a[_i]; | ||
if (!obj.hasOwnProperty(item)) { | ||
return undefined; | ||
} | ||
return obj; | ||
obj = obj[item]; | ||
} | ||
exports.inner = inner; | ||
/** | ||
* exists - return true if inner property of Object exists | ||
* Usage: exists("some.prop.to.locate", obj); | ||
* | ||
* @param prop - property to locate | ||
* @param obj - object to locate property in | ||
*/ | ||
function exists(prop, obj) { | ||
return inner(prop, obj) !== undefined; | ||
} | ||
exports.exists = exists; | ||
function _mixin(dest, source) { | ||
var empty = {}; | ||
for (var key in source) { | ||
var s = source[key]; | ||
if (s instanceof Array) { | ||
// TODO: Do we need to support arrays? | ||
} | ||
else if (typeof s === "object") { | ||
s = deepMixin(dest[key], s); | ||
} | ||
if (!(key in dest) || (dest[key] !== s && (!(key in empty) || empty[key] !== s))) { | ||
dest[key] = s; | ||
} | ||
return obj; | ||
} | ||
/** | ||
* exists - return true if inner property of Object exists | ||
* Usage: exists("some.prop.to.locate", obj); | ||
* | ||
* @param prop - property to locate | ||
* @param obj - object to locate property in | ||
*/ | ||
export function exists(prop, obj) { | ||
return inner(prop, obj) !== undefined; | ||
} | ||
function _mixin(dest, source) { | ||
var empty = {}; | ||
for (var key in source) { | ||
var s = source[key]; | ||
if (s instanceof Array) { | ||
// TODO: Do we need to support arrays? | ||
} | ||
return dest; | ||
} | ||
/** | ||
* deepMixin - combine several objects from right to left | ||
* Usage: deepMixin({a: "a"}, {b: "b"}); | ||
* | ||
* @param dest - target object to mix into. | ||
* @param sources - objects to mix in | ||
*/ | ||
function deepMixin(dest) { | ||
if (dest === void 0) { dest = {}; } | ||
var sources = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
sources[_i - 1] = arguments[_i]; | ||
else if (typeof s === "object") { | ||
s = deepMixin(dest[key], s); | ||
} | ||
if (typeof dest !== "object") | ||
throw new Error("Destination \"" + dest + "\" must be an object."); | ||
for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) { | ||
var source = sources_1[_a]; | ||
_mixin(dest, source); | ||
if (!(key in dest) || (dest[key] !== s && (!(key in empty) || empty[key] !== s))) { | ||
dest[key] = s; | ||
} | ||
return dest; | ||
} | ||
exports.deepMixin = deepMixin; | ||
/** | ||
* deepMixinT - combine several objects of Partial<T> from right to left | ||
* Usage: deepMixinT<MyInterface>({a: "a"}, {b: "b"}); | ||
* | ||
* Note: Only provided as a convenience, so user gets auto completion based on destination type. | ||
* | ||
* @param dest - target object to mix into. | ||
* @param sources - objects to mix in | ||
*/ | ||
function deepMixinT(dest) { | ||
if (dest === void 0) { dest = {}; } | ||
var sources = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
sources[_i - 1] = arguments[_i]; | ||
} | ||
return deepMixin.apply(void 0, [dest].concat(sources)); | ||
return dest; | ||
} | ||
/** | ||
* deepMixin - combine several objects from right to left | ||
* Usage: deepMixin({a: "a"}, {b: "b"}); | ||
* | ||
* @param dest - target object to mix into. | ||
* @param sources - objects to mix in | ||
*/ | ||
export function deepMixin(dest) { | ||
if (dest === void 0) { dest = {}; } | ||
var sources = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
sources[_i - 1] = arguments[_i]; | ||
} | ||
exports.deepMixinT = deepMixinT; | ||
/** | ||
* safeStingify - JSONsimilar to .stringify, except ignores circular references. | ||
* Usage: safeStingify(object); | ||
* | ||
* @param obj - any object. | ||
*/ | ||
function safeStringify(obj) { | ||
var cache = []; | ||
return JSON.stringify(obj, function (key, value) { | ||
if (typeof value === "object" && value !== null) { | ||
if (cache.indexOf(value) !== -1) { | ||
return; | ||
} | ||
cache.push(value); | ||
if (typeof dest !== "object") | ||
throw new Error("Destination \"" + dest + "\" must be an object."); | ||
for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) { | ||
var source = sources_1[_a]; | ||
_mixin(dest, source); | ||
} | ||
return dest; | ||
} | ||
/** | ||
* deepMixinT - combine several objects of Partial<T> from right to left | ||
* Usage: deepMixinT<MyInterface>({a: "a"}, {b: "b"}); | ||
* | ||
* Note: Only provided as a convenience, so user gets auto completion based on destination type. | ||
* | ||
* @param dest - target object to mix into. | ||
* @param sources - objects to mix in | ||
*/ | ||
export function deepMixinT(dest) { | ||
if (dest === void 0) { dest = {}; } | ||
var sources = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
sources[_i - 1] = arguments[_i]; | ||
} | ||
return deepMixin.apply(void 0, [dest].concat(sources)); | ||
} | ||
/** | ||
* safeStingify - JSONsimilar to .stringify, except ignores circular references. | ||
* Usage: safeStingify(object); | ||
* | ||
* @param obj - any object. | ||
*/ | ||
export function safeStringify(obj) { | ||
var cache = []; | ||
return JSON.stringify(obj, function (key, value) { | ||
if (typeof value === "object" && value !== null) { | ||
if (cache.indexOf(value) !== -1) { | ||
return; | ||
} | ||
return value; | ||
}); | ||
} | ||
exports.safeStringify = safeStringify; | ||
}); | ||
cache.push(value); | ||
} | ||
return value; | ||
}); | ||
} | ||
//# sourceMappingURL=object.js.map |
@@ -11,3 +11,2 @@ /** | ||
export declare class Observable<T extends EventID> { | ||
private _knownEvents; | ||
private _eventObservers; | ||
@@ -14,0 +13,0 @@ constructor(...events: T[]); |
@@ -1,93 +0,80 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
var ObserverHandle = /** @class */ (function () { | ||
function ObserverHandle(eventTarget, eventID, callback) { | ||
this.eventTarget = eventTarget; | ||
this.eventID = eventID; | ||
this.callback = callback; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
ObserverHandle.prototype.release = function () { | ||
this.eventTarget.removeObserver(this.eventID, this.callback); | ||
}; | ||
ObserverHandle.prototype.unwatch = function () { | ||
this.release(); | ||
}; | ||
return ObserverHandle; | ||
}()); | ||
var Observable = /** @class */ (function () { | ||
function Observable() { | ||
var events = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
events[_i] = arguments[_i]; | ||
} | ||
this._eventObservers = {}; | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ObserverHandle = /** @class */ (function () { | ||
function ObserverHandle(eventTarget, eventID, callback) { | ||
this.eventTarget = eventTarget; | ||
this.eventID = eventID; | ||
this.callback = callback; | ||
Observable.prototype.addObserver = function (eventID, callback) { | ||
var eventObservers = this._eventObservers[eventID]; | ||
if (!eventObservers) { | ||
eventObservers = []; | ||
this._eventObservers[eventID] = eventObservers; | ||
} | ||
ObserverHandle.prototype.release = function () { | ||
this.eventTarget.removeObserver(this.eventID, this.callback); | ||
}; | ||
ObserverHandle.prototype.unwatch = function () { | ||
this.release(); | ||
}; | ||
return ObserverHandle; | ||
}()); | ||
var Observable = /** @class */ (function () { | ||
function Observable() { | ||
var events = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
events[_i] = arguments[_i]; | ||
eventObservers.push(callback); | ||
return new ObserverHandle(this, eventID, callback); | ||
}; | ||
Observable.prototype.removeObserver = function (eventID, callback) { | ||
var eventObservers = this._eventObservers[eventID]; | ||
if (eventObservers) { | ||
for (var i = eventObservers.length - 1; i >= 0; --i) { | ||
if (eventObservers[i] === callback) { | ||
eventObservers.splice(i, 1); | ||
} | ||
} | ||
this._eventObservers = {}; | ||
this._knownEvents = events; | ||
} | ||
Observable.prototype.addObserver = function (eventID, callback) { | ||
var eventObservers = this._eventObservers[eventID]; | ||
if (!eventObservers) { | ||
eventObservers = []; | ||
this._eventObservers[eventID] = eventObservers; | ||
return this; | ||
}; | ||
Observable.prototype.dispatchEvent = function (eventID) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
var eventObservers = this._eventObservers[eventID]; | ||
if (eventObservers) { | ||
for (var _a = 0, eventObservers_1 = eventObservers; _a < eventObservers_1.length; _a++) { | ||
var observer = eventObservers_1[_a]; | ||
observer.apply(void 0, args); | ||
} | ||
eventObservers.push(callback); | ||
return new ObserverHandle(this, eventID, callback); | ||
}; | ||
Observable.prototype.removeObserver = function (eventID, callback) { | ||
var eventObservers = this._eventObservers[eventID]; | ||
if (eventObservers) { | ||
for (var i = eventObservers.length - 1; i >= 0; --i) { | ||
if (eventObservers[i] === callback) { | ||
eventObservers.splice(i, 1); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
Observable.prototype._hasObserver = function (eventID) { | ||
var eventObservers = this._eventObservers[eventID]; | ||
for (var observer in eventObservers) { | ||
if (eventObservers[observer]) { | ||
return true; | ||
} | ||
return this; | ||
}; | ||
Observable.prototype.dispatchEvent = function (eventID) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
return false; | ||
}; | ||
Observable.prototype.hasObserver = function (_eventID) { | ||
if (_eventID !== void 0) { | ||
return this._hasObserver(_eventID); | ||
} | ||
for (var eventID in this._eventObservers) { | ||
if (this._hasObserver(eventID)) { | ||
return true; | ||
} | ||
var eventObservers = this._eventObservers[eventID]; | ||
if (eventObservers) { | ||
for (var _a = 0, eventObservers_1 = eventObservers; _a < eventObservers_1.length; _a++) { | ||
var observer = eventObservers_1[_a]; | ||
observer.apply(void 0, args); | ||
} | ||
} | ||
return this; | ||
}; | ||
Observable.prototype._hasObserver = function (eventID) { | ||
var eventObservers = this._eventObservers[eventID]; | ||
for (var observer in eventObservers) { | ||
if (eventObservers[observer]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
Observable.prototype.hasObserver = function (_eventID) { | ||
if (_eventID !== void 0) { | ||
return this._hasObserver(_eventID); | ||
} | ||
for (var eventID in this._eventObservers) { | ||
if (this._hasObserver(eventID)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
return Observable; | ||
}()); | ||
exports.Observable = Observable; | ||
}); | ||
} | ||
return false; | ||
}; | ||
return Observable; | ||
}()); | ||
export { Observable }; | ||
//# sourceMappingURL=observer.js.map |
@@ -1,17 +0,5 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.root = new Function("try{return global;}catch(e){return window;}")(); | ||
exports.isBrowser = new Function("try{return this===window;}catch(e){return false;}"); | ||
exports.isNode = new Function("try{return this===global;}catch(e){return false;}"); | ||
exports.isTravis = new Function("try{return process.env.TRAVIS;}catch(e){return false;}"); | ||
}); | ||
export var root = new Function("try{return global;}catch(e){return window;}")(); | ||
export var isBrowser = new Function("try{return this===window;}catch(e){return false;}"); | ||
export var isNode = new Function("try{return this===global;}catch(e){return false;}"); | ||
export var isTravis = new Function("try{return process.env.TRAVIS;}catch(e){return false;}"); | ||
//# sourceMappingURL=platform.js.map |
@@ -1,139 +0,126 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import * as tslib_1 from "tslib"; | ||
import { Stack } from "./stack"; | ||
var XMLNode = /** @class */ (function () { | ||
function XMLNode(name) { | ||
this.name = ""; | ||
this.$ = {}; | ||
this._children = []; | ||
this.content = ""; | ||
this.name = name; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "tslib", "./stack"], factory); | ||
XMLNode.prototype.appendAttribute = function (key, val) { | ||
this.$[key] = val; | ||
}; | ||
XMLNode.prototype.appendContent = function (content) { | ||
this.content += content; | ||
}; | ||
XMLNode.prototype.appendChild = function (child) { | ||
this._children.push(child); | ||
}; | ||
XMLNode.prototype.children = function (tag) { | ||
if (tag === undefined) { | ||
return this._children; | ||
} | ||
return this._children.filter(function (xmlNode) { | ||
return xmlNode.name === tag; | ||
}); | ||
}; | ||
return XMLNode; | ||
}()); | ||
export { XMLNode }; | ||
var SAXStackParser = /** @class */ (function () { | ||
function SAXStackParser() { | ||
this.stack = new Stack(); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var stack_1 = require("./stack"); | ||
var XMLNode = /** @class */ (function () { | ||
function XMLNode(name) { | ||
this.name = ""; | ||
this.$ = {}; | ||
this._children = []; | ||
this.content = ""; | ||
this.name = name; | ||
} | ||
XMLNode.prototype.appendAttribute = function (key, val) { | ||
this.$[key] = val; | ||
}; | ||
XMLNode.prototype.appendContent = function (content) { | ||
this.content += content; | ||
}; | ||
XMLNode.prototype.appendChild = function (child) { | ||
this._children.push(child); | ||
}; | ||
XMLNode.prototype.children = function (tag) { | ||
if (tag === undefined) { | ||
return this._children; | ||
SAXStackParser.prototype.walkDoc = function (node) { | ||
var xmlNode = this._startXMLNode(node); | ||
if (node.attributes) { | ||
for (var i = 0; i < node.attributes.length; ++i) { | ||
var attribute = node.attributes.item(i); | ||
this.attributes(attribute.nodeName, attribute.nodeValue); | ||
} | ||
return this._children.filter(function (xmlNode) { | ||
return xmlNode.name === tag; | ||
}); | ||
}; | ||
return XMLNode; | ||
}()); | ||
exports.XMLNode = XMLNode; | ||
var SAXStackParser = /** @class */ (function () { | ||
function SAXStackParser() { | ||
this.stack = new stack_1.Stack(); | ||
} | ||
SAXStackParser.prototype.walkDoc = function (node) { | ||
var xmlNode = this._startXMLNode(node); | ||
if (node.attributes) { | ||
for (var i = 0; i < node.attributes.length; ++i) { | ||
var attribute = node.attributes.item(i); | ||
this.attributes(attribute.nodeName, attribute.nodeValue); | ||
this.startXMLNode(xmlNode); | ||
if (node.childNodes) { | ||
for (var i = 0; i < node.childNodes.length; ++i) { | ||
var childNode = node.childNodes.item(i); | ||
if (childNode.nodeType === childNode.TEXT_NODE) { | ||
this.characters(childNode.nodeValue); | ||
} | ||
} | ||
this.startXMLNode(xmlNode); | ||
if (node.childNodes) { | ||
for (var i = 0; i < node.childNodes.length; ++i) { | ||
var childNode = node.childNodes.item(i); | ||
if (childNode.nodeType === childNode.TEXT_NODE) { | ||
this.characters(childNode.nodeValue); | ||
} | ||
else { | ||
this.walkDoc(childNode); | ||
} | ||
else { | ||
this.walkDoc(childNode); | ||
} | ||
} | ||
this.endXMLNode(this.stack.pop()); | ||
}; | ||
SAXStackParser.prototype._startXMLNode = function (node) { | ||
var newNode = new XMLNode(node.nodeName); | ||
if (!this.stack.depth()) { | ||
this.root = newNode; | ||
} | ||
else { | ||
this.stack.top().appendChild(newNode); | ||
} | ||
return this.stack.push(newNode); | ||
}; | ||
SAXStackParser.prototype.parse = function (xml) { | ||
var domParser = new DOMParser(); | ||
var doc = domParser.parseFromString(xml, "application/xml"); | ||
this.startDocument(); | ||
this.walkDoc(doc); | ||
this.endDocument(); | ||
}; | ||
// Callbacks --- | ||
SAXStackParser.prototype.startDocument = function () { | ||
}; | ||
SAXStackParser.prototype.endDocument = function () { | ||
}; | ||
SAXStackParser.prototype.startXMLNode = function (node) { | ||
}; | ||
SAXStackParser.prototype.endXMLNode = function (node) { | ||
}; | ||
SAXStackParser.prototype.attributes = function (key, val) { | ||
this.stack.top().appendAttribute(key, val); | ||
}; | ||
SAXStackParser.prototype.characters = function (text) { | ||
this.stack.top().appendContent(text); | ||
}; | ||
return SAXStackParser; | ||
}()); | ||
exports.SAXStackParser = SAXStackParser; | ||
var XML2JSONParser = /** @class */ (function (_super) { | ||
tslib_1.__extends(XML2JSONParser, _super); | ||
function XML2JSONParser() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
XML2JSONParser.prototype.startXMLNode = function (node) { | ||
_super.prototype.startXMLNode.call(this, node); | ||
switch (node.name) { | ||
case "xs:element": | ||
break; | ||
case "xs:simpleType": | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
XML2JSONParser.prototype.endXMLNode = function (node) { | ||
switch (node.name) { | ||
case "xs:element": | ||
break; | ||
case "xs:simpleType": | ||
break; | ||
default: | ||
break; | ||
} | ||
_super.prototype.endXMLNode.call(this, node); | ||
}; | ||
return XML2JSONParser; | ||
}(SAXStackParser)); | ||
function xml2json(xml) { | ||
var saxParser = new XML2JSONParser(); | ||
saxParser.parse(xml); | ||
return saxParser.root; | ||
this.endXMLNode(this.stack.pop()); | ||
}; | ||
SAXStackParser.prototype._startXMLNode = function (node) { | ||
var newNode = new XMLNode(node.nodeName); | ||
if (!this.stack.depth()) { | ||
this.root = newNode; | ||
} | ||
else { | ||
this.stack.top().appendChild(newNode); | ||
} | ||
return this.stack.push(newNode); | ||
}; | ||
SAXStackParser.prototype.parse = function (xml) { | ||
var domParser = new DOMParser(); | ||
var doc = domParser.parseFromString(xml, "application/xml"); | ||
this.startDocument(); | ||
this.walkDoc(doc); | ||
this.endDocument(); | ||
}; | ||
// Callbacks --- | ||
SAXStackParser.prototype.startDocument = function () { | ||
}; | ||
SAXStackParser.prototype.endDocument = function () { | ||
}; | ||
SAXStackParser.prototype.startXMLNode = function (node) { | ||
}; | ||
SAXStackParser.prototype.endXMLNode = function (node) { | ||
}; | ||
SAXStackParser.prototype.attributes = function (key, val) { | ||
this.stack.top().appendAttribute(key, val); | ||
}; | ||
SAXStackParser.prototype.characters = function (text) { | ||
this.stack.top().appendContent(text); | ||
}; | ||
return SAXStackParser; | ||
}()); | ||
export { SAXStackParser }; | ||
var XML2JSONParser = /** @class */ (function (_super) { | ||
tslib_1.__extends(XML2JSONParser, _super); | ||
function XML2JSONParser() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
exports.xml2json = xml2json; | ||
}); | ||
XML2JSONParser.prototype.startXMLNode = function (node) { | ||
_super.prototype.startXMLNode.call(this, node); | ||
switch (node.name) { | ||
case "xs:element": | ||
break; | ||
case "xs:simpleType": | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
XML2JSONParser.prototype.endXMLNode = function (node) { | ||
switch (node.name) { | ||
case "xs:element": | ||
break; | ||
case "xs:simpleType": | ||
break; | ||
default: | ||
break; | ||
} | ||
_super.prototype.endXMLNode.call(this, node); | ||
}; | ||
return XML2JSONParser; | ||
}(SAXStackParser)); | ||
export function xml2json(xml) { | ||
var saxParser = new XML2JSONParser(); | ||
saxParser.parse(xml); | ||
return saxParser.root; | ||
} | ||
//# sourceMappingURL=saxParser.js.map |
@@ -1,54 +0,42 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
/** | ||
* A generic Stack | ||
*/ | ||
var Stack = /** @class */ (function () { | ||
function Stack() { | ||
this.stack = []; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* A generic Stack | ||
* Push element onto the stack | ||
* | ||
* @param e - element to push | ||
*/ | ||
var Stack = /** @class */ (function () { | ||
function Stack() { | ||
this.stack = []; | ||
} | ||
/** | ||
* Push element onto the stack | ||
* | ||
* @param e - element to push | ||
*/ | ||
Stack.prototype.push = function (e) { | ||
this.stack.push(e); | ||
return e; | ||
}; | ||
/** | ||
* Pop element off the stack | ||
*/ | ||
Stack.prototype.pop = function () { | ||
return this.stack.pop(); | ||
}; | ||
/** | ||
* Top item on the stack | ||
* | ||
* @returns Top element on the stack | ||
*/ | ||
Stack.prototype.top = function () { | ||
return this.stack.length ? this.stack[this.stack.length - 1] : undefined; | ||
}; | ||
/** | ||
* Depth of stack | ||
* | ||
* @returns Depth | ||
*/ | ||
Stack.prototype.depth = function () { | ||
return this.stack.length; | ||
}; | ||
return Stack; | ||
}()); | ||
exports.Stack = Stack; | ||
}); | ||
Stack.prototype.push = function (e) { | ||
this.stack.push(e); | ||
return e; | ||
}; | ||
/** | ||
* Pop element off the stack | ||
*/ | ||
Stack.prototype.pop = function () { | ||
return this.stack.pop(); | ||
}; | ||
/** | ||
* Top item on the stack | ||
* | ||
* @returns Top element on the stack | ||
*/ | ||
Stack.prototype.top = function () { | ||
return this.stack.length ? this.stack[this.stack.length - 1] : undefined; | ||
}; | ||
/** | ||
* Depth of stack | ||
* | ||
* @returns Depth | ||
*/ | ||
Stack.prototype.depth = function () { | ||
return this.stack.length; | ||
}; | ||
return Stack; | ||
}()); | ||
export { Stack }; | ||
//# sourceMappingURL=stack.js.map |
@@ -1,185 +0,173 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import * as tslib_1 from "tslib"; | ||
import { hashSum } from "./hashSum"; | ||
import { Observable } from "./observer"; | ||
var StateObject = /** @class */ (function () { | ||
function StateObject() { | ||
this._espState = {}; | ||
this._espStateCache = {}; | ||
this._events = new Observable(); | ||
this._monitorTickCount = 0; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "tslib", "./hashSum", "./observer"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var hashSum_1 = require("./hashSum"); | ||
var observer_1 = require("./observer"); | ||
var StateObject = /** @class */ (function () { | ||
function StateObject() { | ||
this._espState = {}; | ||
this._espStateCache = {}; | ||
this._events = new observer_1.Observable(); | ||
this._monitorTickCount = 0; | ||
StateObject.prototype.clear = function (newVals) { | ||
this._espState = {}; | ||
this._espStateCache = {}; | ||
if (newVals !== void 0) { | ||
this.set(newVals); | ||
} | ||
StateObject.prototype.clear = function (newVals) { | ||
this._espState = {}; | ||
this._espStateCache = {}; | ||
if (newVals !== void 0) { | ||
this.set(newVals); | ||
this._monitorTickCount = 0; | ||
}; | ||
StateObject.prototype.get = function (key, defValue) { | ||
if (key === void 0) { | ||
return this._espState; | ||
} | ||
return this.has(key) ? this._espState[key] : defValue; | ||
}; | ||
StateObject.prototype.set = function (keyOrNewVals, newVal, batchMode) { | ||
if (batchMode === void 0) { batchMode = false; } | ||
if (typeof keyOrNewVals === "string") { | ||
return this.setSingle(keyOrNewVals, newVal, batchMode); | ||
} | ||
return this.setAll(keyOrNewVals); | ||
}; | ||
StateObject.prototype.setSingle = function (key, newVal, batchMode) { | ||
var oldCacheVal = this._espStateCache[key]; | ||
var newCacheVal = hashSum(newVal); | ||
if (oldCacheVal !== newCacheVal) { | ||
this._espStateCache[key] = newCacheVal; | ||
var oldVal = this._espState[key]; | ||
this._espState[key] = newVal; | ||
var changedInfo = { id: key, oldValue: oldVal, newValue: newVal }; | ||
if (!batchMode) { | ||
this._events.dispatchEvent("propChanged", changedInfo); | ||
this._events.dispatchEvent("changed", [changedInfo]); | ||
} | ||
this._monitorTickCount = 0; | ||
}; | ||
StateObject.prototype.get = function (key, defValue) { | ||
if (key === void 0) { | ||
return this._espState; | ||
} | ||
return this.has(key) ? this._espState[key] : defValue; | ||
}; | ||
StateObject.prototype.set = function (keyOrNewVals, newVal, batchMode) { | ||
if (batchMode === void 0) { batchMode = false; } | ||
if (typeof keyOrNewVals === "string") { | ||
return this.setSingle(keyOrNewVals, newVal, batchMode); | ||
} | ||
return this.setAll(keyOrNewVals); | ||
}; | ||
StateObject.prototype.setSingle = function (key, newVal, batchMode) { | ||
var oldCacheVal = this._espStateCache[key]; | ||
var newCacheVal = hashSum_1.hashSum(newVal); | ||
if (oldCacheVal !== newCacheVal) { | ||
this._espStateCache[key] = newCacheVal; | ||
var oldVal = this._espState[key]; | ||
this._espState[key] = newVal; | ||
var changedInfo = { id: key, oldValue: oldVal, newValue: newVal }; | ||
if (!batchMode) { | ||
this._events.dispatchEvent("propChanged", changedInfo); | ||
this._events.dispatchEvent("changed", [changedInfo]); | ||
return changedInfo; | ||
} | ||
return null; | ||
}; | ||
StateObject.prototype.setAll = function (_) { | ||
var changed = []; | ||
for (var key in _) { | ||
if (_.hasOwnProperty(key)) { | ||
var changedInfo = this.setSingle(key, _[key], true); | ||
if (changedInfo) { | ||
changed.push(changedInfo); | ||
} | ||
return changedInfo; | ||
} | ||
return null; | ||
}; | ||
StateObject.prototype.setAll = function (_) { | ||
var changed = []; | ||
for (var key in _) { | ||
if (_.hasOwnProperty(key)) { | ||
var changedInfo = this.setSingle(key, _[key], true); | ||
if (changedInfo) { | ||
changed.push(changedInfo); | ||
} | ||
} | ||
} | ||
if (changed.length) { | ||
for (var _i = 0, changed_1 = changed; _i < changed_1.length; _i++) { | ||
var changeInfo = changed_1[_i]; | ||
this._events.dispatchEvent(("propChanged"), changeInfo); | ||
} | ||
if (changed.length) { | ||
for (var _i = 0, changed_1 = changed; _i < changed_1.length; _i++) { | ||
var changeInfo = changed_1[_i]; | ||
this._events.dispatchEvent(("propChanged"), changeInfo); | ||
this._events.dispatchEvent(("changed"), changed); | ||
} | ||
return changed; | ||
}; | ||
StateObject.prototype.has = function (key) { | ||
return this._espState[key] !== void 0; | ||
}; | ||
StateObject.prototype.addObserver = function (eventID, propIDOrCallback, callback) { | ||
if (this.isCallback(propIDOrCallback)) { | ||
if (eventID !== "changed") | ||
throw new Error("Invalid eventID: " + eventID); | ||
return this._events.addObserver(eventID, propIDOrCallback); | ||
} | ||
else { | ||
if (eventID !== "propChanged") | ||
throw new Error("Invalid eventID: " + eventID); | ||
return this._events.addObserver(eventID, function (changeInfo) { | ||
if (changeInfo.id === propIDOrCallback) { | ||
callback(changeInfo); | ||
} | ||
this._events.dispatchEvent(("changed"), changed); | ||
}); | ||
} | ||
}; | ||
StateObject.prototype.on = function (eventID, propIDOrCallback, callback) { | ||
if (this.isCallback(propIDOrCallback)) { | ||
switch (eventID) { | ||
case "changed": | ||
this._events.addObserver(eventID, propIDOrCallback); | ||
default: | ||
} | ||
return changed; | ||
}; | ||
StateObject.prototype.has = function (key) { | ||
return this._espState[key] !== void 0; | ||
}; | ||
StateObject.prototype.addObserver = function (eventID, propIDOrCallback, callback) { | ||
if (this.isCallback(propIDOrCallback)) { | ||
if (eventID !== "changed") | ||
throw new Error("Invalid eventID: " + eventID); | ||
return this._events.addObserver(eventID, propIDOrCallback); | ||
} | ||
else { | ||
switch (eventID) { | ||
case "propChanged": | ||
this._events.addObserver(eventID, function (changeInfo) { | ||
if (changeInfo.id === propIDOrCallback) { | ||
callback(changeInfo); | ||
} | ||
}); | ||
default: | ||
} | ||
else { | ||
if (eventID !== "propChanged") | ||
throw new Error("Invalid eventID: " + eventID); | ||
return this._events.addObserver(eventID, function (changeInfo) { | ||
if (changeInfo.id === propIDOrCallback) { | ||
callback(changeInfo); | ||
} | ||
}); | ||
} | ||
}; | ||
StateObject.prototype.on = function (eventID, propIDOrCallback, callback) { | ||
if (this.isCallback(propIDOrCallback)) { | ||
switch (eventID) { | ||
case "changed": | ||
this._events.addObserver(eventID, propIDOrCallback); | ||
default: | ||
} | ||
return this; | ||
}; | ||
StateObject.prototype.isCallback = function (propIDOrCallback) { | ||
return (typeof propIDOrCallback === "function"); | ||
}; | ||
StateObject.prototype.hasEventListener = function () { | ||
return this._events.hasObserver(); | ||
}; | ||
// Monitoring --- | ||
StateObject.prototype.refresh = function (full) { | ||
if (full === void 0) { full = false; } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.resolve()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, this]; | ||
} | ||
} | ||
else { | ||
switch (eventID) { | ||
case "propChanged": | ||
this._events.addObserver(eventID, function (changeInfo) { | ||
if (changeInfo.id === propIDOrCallback) { | ||
callback(changeInfo); | ||
} | ||
}); | ||
default: | ||
} | ||
} | ||
return this; | ||
}; | ||
StateObject.prototype.isCallback = function (propIDOrCallback) { | ||
return (typeof propIDOrCallback === "function"); | ||
}; | ||
StateObject.prototype.hasEventListener = function () { | ||
return this._events.hasObserver(); | ||
}; | ||
// Monitoring --- | ||
StateObject.prototype.refresh = function (full) { | ||
if (full === void 0) { full = false; } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.resolve()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, this]; | ||
} | ||
}); | ||
}); | ||
}; | ||
StateObject.prototype._monitor = function () { | ||
var _this = this; | ||
if (this._monitorHandle) { | ||
this._monitorTickCount = 0; | ||
return; | ||
} | ||
this._monitorHandle = setTimeout(function () { | ||
var refreshPromise = _this.hasEventListener() ? _this.refresh(true) : Promise.resolve(); | ||
refreshPromise.then(function () { | ||
_this._monitor(); | ||
}); | ||
delete _this._monitorHandle; | ||
}, this._monitorTimeoutDuraction()); | ||
}; | ||
StateObject.prototype._monitorTimeoutDuraction = function () { | ||
++this._monitorTickCount; | ||
if (this._monitorTickCount <= 1) { | ||
return 0; | ||
} | ||
return 30000; | ||
}; | ||
StateObject.prototype.watch = function (callback, triggerChange) { | ||
var _this = this; | ||
if (triggerChange === void 0) { triggerChange = true; } | ||
if (typeof callback !== "function") { | ||
throw new Error("Invalid Callback"); | ||
} | ||
if (triggerChange) { | ||
setTimeout(function () { | ||
var props = _this.get(); | ||
var changes = []; | ||
for (var key in props) { | ||
if (props.hasOwnProperty(props)) { | ||
changes.push({ id: key, newValue: props[key], oldValue: undefined }); | ||
} | ||
}); | ||
}; | ||
StateObject.prototype._monitor = function () { | ||
var _this = this; | ||
if (this._monitorHandle) { | ||
this._monitorTickCount = 0; | ||
return; | ||
} | ||
this._monitorHandle = setTimeout(function () { | ||
var refreshPromise = _this.hasEventListener() ? _this.refresh(true) : Promise.resolve(); | ||
refreshPromise.then(function () { | ||
_this._monitor(); | ||
}); | ||
delete _this._monitorHandle; | ||
}, this._monitorTimeoutDuraction()); | ||
}; | ||
StateObject.prototype._monitorTimeoutDuraction = function () { | ||
++this._monitorTickCount; | ||
if (this._monitorTickCount <= 1) { | ||
return 0; | ||
} | ||
return 30000; | ||
}; | ||
StateObject.prototype.watch = function (callback, triggerChange) { | ||
var _this = this; | ||
if (triggerChange === void 0) { triggerChange = true; } | ||
if (typeof callback !== "function") { | ||
throw new Error("Invalid Callback"); | ||
} | ||
if (triggerChange) { | ||
setTimeout(function () { | ||
var props = _this.get(); | ||
var changes = []; | ||
for (var key in props) { | ||
if (props.hasOwnProperty(props)) { | ||
changes.push({ id: key, newValue: props[key], oldValue: undefined }); | ||
} | ||
callback(changes); | ||
}, 0); | ||
} | ||
var retVal = this.addObserver("changed", callback); | ||
this._monitor(); | ||
return retVal; | ||
}; | ||
return StateObject; | ||
}()); | ||
exports.StateObject = StateObject; | ||
}); | ||
} | ||
callback(changes); | ||
}, 0); | ||
} | ||
var retVal = this.addObserver("changed", callback); | ||
this._monitor(); | ||
return retVal; | ||
}; | ||
return StateObject; | ||
}()); | ||
export { StateObject }; | ||
//# sourceMappingURL=stateful.js.map |
@@ -1,37 +0,23 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
export function trim(str, char) { | ||
if (typeof char !== "string") | ||
return str; | ||
if (char.length === 0) | ||
return str; | ||
while (str.indexOf(char) === 0) { | ||
str = str.substring(1); | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
while (endsWith(str, char)) { | ||
str = str.substring(0, str.length - 1); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function trim(str, char) { | ||
if (typeof char !== "string") | ||
return str; | ||
if (char.length === 0) | ||
return str; | ||
while (str.indexOf(char) === 0) { | ||
str = str.substring(1); | ||
} | ||
while (endsWith(str, char)) { | ||
str = str.substring(0, str.length - 1); | ||
} | ||
return str; | ||
return str; | ||
} | ||
export function endsWith(origString, searchString, position) { | ||
var subjectString = origString.toString(); | ||
if (typeof position !== "number" || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { | ||
position = subjectString.length; | ||
} | ||
exports.trim = trim; | ||
function endsWith(origString, searchString, position) { | ||
var subjectString = origString.toString(); | ||
if (typeof position !== "number" || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { | ||
position = subjectString.length; | ||
} | ||
position -= searchString.length; | ||
var lastIndex = subjectString.lastIndexOf(searchString, position); | ||
return lastIndex !== -1 && lastIndex === position; | ||
} | ||
exports.endsWith = endsWith; | ||
}); | ||
position -= searchString.length; | ||
var lastIndex = subjectString.lastIndexOf(searchString, position); | ||
return lastIndex !== -1 && lastIndex === position; | ||
} | ||
//# sourceMappingURL=string.js.map |
@@ -1,25 +0,12 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import { trim } from "./string"; | ||
export function join() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./string"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var string_1 = require("./string"); | ||
function join() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var partialUrl = args.length && args[0].length && args[0].charAt(0) === "/"; | ||
return (partialUrl ? "/" : "") + args.map(function (arg) { | ||
return string_1.trim(arg, "/"); | ||
}).join("/"); | ||
} | ||
exports.join = join; | ||
}); | ||
var partialUrl = args.length && args[0].length && args[0].charAt(0) === "/"; | ||
return (partialUrl ? "/" : "") + args.map(function (arg) { | ||
return trim(arg, "/"); | ||
}).join("/"); | ||
} | ||
//# sourceMappingURL=url.js.map |
{ | ||
"name": "@hpcc-js/util", | ||
"version": "0.0.42", | ||
"version": "0.0.43", | ||
"description": "hpcc-js - Utilities", | ||
"main": "lib/index.js", | ||
"module": "lib-es6/index.js", | ||
"main": "build/util.js", | ||
"module": "lib/index", | ||
"unpkg": "build/util.min.js", | ||
"types": "lib/index.d.ts", | ||
"unpkg": "dist/util.min.js", | ||
"files": [ | ||
"lib/*", | ||
"lib-es6/*", | ||
"src/*.css", | ||
"dist/*" | ||
"build/*", | ||
"lib/*" | ||
], | ||
"scripts": { | ||
"clean": "rimraf lib* && rimraf dist*", | ||
"build": "tsc", | ||
"build-es6": "tsc --module esnext --outDir ./lib-es6", | ||
"watch-es6": "tsc -w --module esnext --outDir ./lib-es6", | ||
"bundle": "node ./node_modules/@hpcc-js/bundle/lib/rollup", | ||
"watch-bundle": "node ./node_modules/@hpcc-js/bundle/lib/watch", | ||
"watch": "concurrently --kill-others \"npm run watch-es6\" \"npm run watch-bundle\"", | ||
"clean": "rimraf lib* && rimraf build", | ||
"compile": "tsc --module esnext --outDir ./lib", | ||
"compile-watch": "npm run compile -- -w", | ||
"compile-umd": "tsc", | ||
"bundle": "rollup -c", | ||
"bundle-watch": "npm run bundle -- -w", | ||
"minimize": "uglifyjs build/util.js -c -m -o build/util.min.js", | ||
"build": "npm run compile && npm run bundle", | ||
"watch": "concurrently --kill-others \"npm run compile-watch\" \"npm run bundle-watch\"", | ||
"lint": "tslint --project . src/**/*.ts", | ||
"docs": "typedoc --options tdoptions.json ." | ||
}, | ||
"dependencies": { | ||
"tslib": "1.8.0" | ||
}, | ||
"devDependencies": { | ||
"@hpcc-js/bundle": "^0.0.15", | ||
"@hpcc-js/bundle": "^0.0.16", | ||
"concurrently": "3.5.0", | ||
"es6-promise": "4.1.1", | ||
"rimraf": "2.6.1", | ||
"rollup": "0.51.3", | ||
"rollup-plugin-commonjs": "8.2.6", | ||
"rollup-plugin-node-resolve": "3.0.0", | ||
"tslib": "1.8.0", | ||
"tslint": "5.8.0", | ||
"typedoc": "0.7.1", | ||
"typescript": "2.5.2" | ||
"typescript": "2.6.1", | ||
"uglify-js": "3.1.8" | ||
}, | ||
@@ -35,0 +40,0 @@ "repository": { |
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
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
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
1
4
6
192767
12
56
4276
- Removedtslib@1.8.0
- Removedtslib@1.8.0(transitive)