@hpcc-js/util 2.42.0 → 2.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +43 -43
- package/dist/index.js +2281 -2281
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/lib-es6/__package__.js +3 -3
- package/lib-es6/__package__.js.map +1 -1
- package/lib-es6/array.js +84 -84
- package/lib-es6/cache.js +60 -60
- package/lib-es6/debounce.js +85 -85
- package/lib-es6/dictionary.js +61 -61
- package/lib-es6/dispatch.js +101 -101
- package/lib-es6/esp.js +32 -32
- package/lib-es6/graph.js +348 -348
- package/lib-es6/graph2.js +603 -603
- package/lib-es6/hashSum.js +49 -49
- package/lib-es6/immutable.js +54 -54
- package/lib-es6/index.js +21 -21
- package/lib-es6/logging.js +177 -177
- package/lib-es6/math.js +90 -90
- package/lib-es6/object.js +121 -121
- package/lib-es6/observer.js +79 -79
- package/lib-es6/platform.js +17 -17
- package/lib-es6/saxParser.js +125 -125
- package/lib-es6/stack.js +41 -41
- package/lib-es6/stateful.js +170 -170
- package/lib-es6/string.js +22 -22
- package/lib-es6/url.js +32 -32
- package/package.json +7 -21
- package/src/__package__.ts +2 -2
- package/src/array.ts +98 -98
- package/src/cache.ts +65 -65
- package/src/debounce.ts +88 -88
- package/src/dictionary.ts +69 -69
- package/src/dispatch.ts +119 -119
- package/src/esp.ts +32 -32
- package/src/graph.ts +353 -353
- package/src/graph2.ts +661 -661
- package/src/hashSum.ts +55 -55
- package/src/immutable.ts +57 -57
- package/src/index.ts +21 -21
- package/src/logging.ts +211 -211
- package/src/math.ts +92 -92
- package/src/object.ts +117 -117
- package/src/observer.ts +91 -91
- package/src/platform.ts +20 -20
- package/src/saxParser.ts +135 -135
- package/src/stack.ts +41 -41
- package/src/stateful.ts +178 -178
- package/src/string.ts +21 -21
- package/src/url.ts +27 -27
- package/types/__package__.d.ts +3 -3
- package/types/__package__.d.ts.map +1 -1
- package/types/array.d.ts +13 -13
- package/types/cache.d.ts +20 -20
- package/types/debounce.d.ts +12 -12
- package/types/dictionary.d.ts +20 -20
- package/types/dispatch.d.ts +26 -26
- package/types/esp.d.ts +1 -1
- package/types/graph.d.ts +73 -73
- package/types/graph2.d.ts +111 -111
- package/types/hashSum.d.ts +1 -1
- package/types/immutable.d.ts +2 -2
- package/types/index.d.ts +21 -21
- package/types/logging.d.ts +57 -57
- package/types/math.d.ts +70 -70
- package/types/object.d.ts +48 -48
- package/types/observer.d.ts +18 -18
- package/types/platform.d.ts +5 -5
- package/types/saxParser.d.ts +28 -28
- package/types/stack.d.ts +28 -28
- package/types/stateful.d.ts +33 -33
- package/types/string.d.ts +2 -2
- package/types/url.d.ts +2 -2
- package/types-3.4/__package__.d.ts +2 -2
package/lib-es6/hashSum.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// Ported to TypeScript from: https://github.com/bevacqua/hash-sum
|
|
2
|
-
function pad(hash, len) {
|
|
3
|
-
while (hash.length < len) {
|
|
4
|
-
hash = "0" + hash;
|
|
5
|
-
}
|
|
6
|
-
return hash;
|
|
7
|
-
}
|
|
8
|
-
function fold(hash, text) {
|
|
9
|
-
if (text.length === 0) {
|
|
10
|
-
return hash;
|
|
11
|
-
}
|
|
12
|
-
for (var i = 0; i < text.length; ++i) {
|
|
13
|
-
var chr = text.charCodeAt(i);
|
|
14
|
-
hash = ((hash << 5) - hash) + chr;
|
|
15
|
-
hash |= 0;
|
|
16
|
-
}
|
|
17
|
-
return hash < 0 ? hash * -2 : hash;
|
|
18
|
-
}
|
|
19
|
-
function foldObject(hash, o, seen) {
|
|
20
|
-
if (typeof o.hashSum === "function") {
|
|
21
|
-
return o.hashSum();
|
|
22
|
-
}
|
|
23
|
-
return Object.keys(o).sort().reduce(function (input, key) {
|
|
24
|
-
return foldValue(input, o[key], key, seen);
|
|
25
|
-
}, hash);
|
|
26
|
-
}
|
|
27
|
-
function foldValue(input, value, key, seen) {
|
|
28
|
-
var hash = fold(fold(fold(input, key), toString(value)), typeof value);
|
|
29
|
-
if (value === null) {
|
|
30
|
-
return fold(hash, "null");
|
|
31
|
-
}
|
|
32
|
-
if (value === undefined) {
|
|
33
|
-
return fold(hash, "undefined");
|
|
34
|
-
}
|
|
35
|
-
if (typeof value === "object") {
|
|
36
|
-
if (seen.indexOf(value) !== -1) {
|
|
37
|
-
return fold(hash, "[Circular]" + key);
|
|
38
|
-
}
|
|
39
|
-
seen.push(value);
|
|
40
|
-
return foldObject(hash, value, seen);
|
|
41
|
-
}
|
|
42
|
-
return fold(hash, value.toString());
|
|
43
|
-
}
|
|
44
|
-
function toString(o) {
|
|
45
|
-
return Object.prototype.toString.call(o);
|
|
46
|
-
}
|
|
47
|
-
export function hashSum(o) {
|
|
48
|
-
return pad(foldValue(0, o, "", []).toString(16), 8);
|
|
49
|
-
}
|
|
1
|
+
// Ported to TypeScript from: https://github.com/bevacqua/hash-sum
|
|
2
|
+
function pad(hash, len) {
|
|
3
|
+
while (hash.length < len) {
|
|
4
|
+
hash = "0" + hash;
|
|
5
|
+
}
|
|
6
|
+
return hash;
|
|
7
|
+
}
|
|
8
|
+
function fold(hash, text) {
|
|
9
|
+
if (text.length === 0) {
|
|
10
|
+
return hash;
|
|
11
|
+
}
|
|
12
|
+
for (var i = 0; i < text.length; ++i) {
|
|
13
|
+
var chr = text.charCodeAt(i);
|
|
14
|
+
hash = ((hash << 5) - hash) + chr;
|
|
15
|
+
hash |= 0;
|
|
16
|
+
}
|
|
17
|
+
return hash < 0 ? hash * -2 : hash;
|
|
18
|
+
}
|
|
19
|
+
function foldObject(hash, o, seen) {
|
|
20
|
+
if (typeof o.hashSum === "function") {
|
|
21
|
+
return o.hashSum();
|
|
22
|
+
}
|
|
23
|
+
return Object.keys(o).sort().reduce(function (input, key) {
|
|
24
|
+
return foldValue(input, o[key], key, seen);
|
|
25
|
+
}, hash);
|
|
26
|
+
}
|
|
27
|
+
function foldValue(input, value, key, seen) {
|
|
28
|
+
var hash = fold(fold(fold(input, key), toString(value)), typeof value);
|
|
29
|
+
if (value === null) {
|
|
30
|
+
return fold(hash, "null");
|
|
31
|
+
}
|
|
32
|
+
if (value === undefined) {
|
|
33
|
+
return fold(hash, "undefined");
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === "object") {
|
|
36
|
+
if (seen.indexOf(value) !== -1) {
|
|
37
|
+
return fold(hash, "[Circular]" + key);
|
|
38
|
+
}
|
|
39
|
+
seen.push(value);
|
|
40
|
+
return foldObject(hash, value, seen);
|
|
41
|
+
}
|
|
42
|
+
return fold(hash, value.toString());
|
|
43
|
+
}
|
|
44
|
+
function toString(o) {
|
|
45
|
+
return Object.prototype.toString.call(o);
|
|
46
|
+
}
|
|
47
|
+
export function hashSum(o) {
|
|
48
|
+
return pad(foldValue(0, o, "", []).toString(16), 8);
|
|
49
|
+
}
|
|
50
50
|
//# sourceMappingURL=hashSum.js.map
|
package/lib-es6/immutable.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
var isArray = Array.isArray;
|
|
2
|
-
var keyList = Object.keys;
|
|
3
|
-
var hasProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
export function deepEquals(a, b) {
|
|
5
|
-
if (a === b)
|
|
6
|
-
return true;
|
|
7
|
-
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
8
|
-
var arrA = isArray(a);
|
|
9
|
-
var arrB = isArray(b);
|
|
10
|
-
var i = void 0;
|
|
11
|
-
var length_1;
|
|
12
|
-
var key = void 0;
|
|
13
|
-
if (arrA && arrB) {
|
|
14
|
-
length_1 = a.length;
|
|
15
|
-
if (length_1 !== b.length)
|
|
16
|
-
return false;
|
|
17
|
-
for (i = length_1; i-- !== 0;)
|
|
18
|
-
if (!deepEquals(a[i], b[i]))
|
|
19
|
-
return false;
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
if (arrA !== arrB)
|
|
23
|
-
return false;
|
|
24
|
-
var dateA = a instanceof Date;
|
|
25
|
-
var dateB = b instanceof Date;
|
|
26
|
-
if (dateA !== dateB)
|
|
27
|
-
return false;
|
|
28
|
-
if (dateA && dateB)
|
|
29
|
-
return a.getTime() === b.getTime();
|
|
30
|
-
var regexpA = a instanceof RegExp;
|
|
31
|
-
var regexpB = b instanceof RegExp;
|
|
32
|
-
if (regexpA !== regexpB)
|
|
33
|
-
return false;
|
|
34
|
-
if (regexpA && regexpB)
|
|
35
|
-
return a.toString() === b.toString();
|
|
36
|
-
var keys = keyList(a);
|
|
37
|
-
length_1 = keys.length;
|
|
38
|
-
if (length_1 !== keyList(b).length)
|
|
39
|
-
return false;
|
|
40
|
-
for (i = length_1; i-- !== 0;)
|
|
41
|
-
if (!hasProp.call(b, keys[i]))
|
|
42
|
-
return false;
|
|
43
|
-
for (i = length_1; i-- !== 0;) {
|
|
44
|
-
key = keys[i];
|
|
45
|
-
if (!deepEquals(a[key], b[key]))
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
return a !== a && b !== b;
|
|
51
|
-
}
|
|
52
|
-
export function update(origItem, newItem) {
|
|
53
|
-
return deepEquals(origItem, newItem) ? origItem : newItem;
|
|
54
|
-
}
|
|
1
|
+
var isArray = Array.isArray;
|
|
2
|
+
var keyList = Object.keys;
|
|
3
|
+
var hasProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
export function deepEquals(a, b) {
|
|
5
|
+
if (a === b)
|
|
6
|
+
return true;
|
|
7
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
8
|
+
var arrA = isArray(a);
|
|
9
|
+
var arrB = isArray(b);
|
|
10
|
+
var i = void 0;
|
|
11
|
+
var length_1;
|
|
12
|
+
var key = void 0;
|
|
13
|
+
if (arrA && arrB) {
|
|
14
|
+
length_1 = a.length;
|
|
15
|
+
if (length_1 !== b.length)
|
|
16
|
+
return false;
|
|
17
|
+
for (i = length_1; i-- !== 0;)
|
|
18
|
+
if (!deepEquals(a[i], b[i]))
|
|
19
|
+
return false;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (arrA !== arrB)
|
|
23
|
+
return false;
|
|
24
|
+
var dateA = a instanceof Date;
|
|
25
|
+
var dateB = b instanceof Date;
|
|
26
|
+
if (dateA !== dateB)
|
|
27
|
+
return false;
|
|
28
|
+
if (dateA && dateB)
|
|
29
|
+
return a.getTime() === b.getTime();
|
|
30
|
+
var regexpA = a instanceof RegExp;
|
|
31
|
+
var regexpB = b instanceof RegExp;
|
|
32
|
+
if (regexpA !== regexpB)
|
|
33
|
+
return false;
|
|
34
|
+
if (regexpA && regexpB)
|
|
35
|
+
return a.toString() === b.toString();
|
|
36
|
+
var keys = keyList(a);
|
|
37
|
+
length_1 = keys.length;
|
|
38
|
+
if (length_1 !== keyList(b).length)
|
|
39
|
+
return false;
|
|
40
|
+
for (i = length_1; i-- !== 0;)
|
|
41
|
+
if (!hasProp.call(b, keys[i]))
|
|
42
|
+
return false;
|
|
43
|
+
for (i = length_1; i-- !== 0;) {
|
|
44
|
+
key = keys[i];
|
|
45
|
+
if (!deepEquals(a[key], b[key]))
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return a !== a && b !== b;
|
|
51
|
+
}
|
|
52
|
+
export function update(origItem, newItem) {
|
|
53
|
+
return deepEquals(origItem, newItem) ? origItem : newItem;
|
|
54
|
+
}
|
|
55
55
|
//# sourceMappingURL=immutable.js.map
|
package/lib-es6/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export * from "./__package__";
|
|
2
|
-
export * from "./array";
|
|
3
|
-
export * from "./cache";
|
|
4
|
-
export * from "./debounce";
|
|
5
|
-
export * from "./dictionary";
|
|
6
|
-
export * from "./esp";
|
|
7
|
-
export * from "./graph";
|
|
8
|
-
export * from "./graph2";
|
|
9
|
-
export * from "./hashSum";
|
|
10
|
-
export * from "./immutable";
|
|
11
|
-
export * from "./logging";
|
|
12
|
-
export * from "./math";
|
|
13
|
-
export * from "./object";
|
|
14
|
-
export * from "./observer";
|
|
15
|
-
export * from "./dispatch";
|
|
16
|
-
export * from "./platform";
|
|
17
|
-
export * from "./saxParser";
|
|
18
|
-
export * from "./stack";
|
|
19
|
-
export * from "./stateful";
|
|
20
|
-
export * from "./string";
|
|
21
|
-
export * from "./url";
|
|
1
|
+
export * from "./__package__";
|
|
2
|
+
export * from "./array";
|
|
3
|
+
export * from "./cache";
|
|
4
|
+
export * from "./debounce";
|
|
5
|
+
export * from "./dictionary";
|
|
6
|
+
export * from "./esp";
|
|
7
|
+
export * from "./graph";
|
|
8
|
+
export * from "./graph2";
|
|
9
|
+
export * from "./hashSum";
|
|
10
|
+
export * from "./immutable";
|
|
11
|
+
export * from "./logging";
|
|
12
|
+
export * from "./math";
|
|
13
|
+
export * from "./object";
|
|
14
|
+
export * from "./observer";
|
|
15
|
+
export * from "./dispatch";
|
|
16
|
+
export * from "./platform";
|
|
17
|
+
export * from "./saxParser";
|
|
18
|
+
export * from "./stack";
|
|
19
|
+
export * from "./stateful";
|
|
20
|
+
export * from "./string";
|
|
21
|
+
export * from "./url";
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/lib-es6/logging.js
CHANGED
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
import { isNode } from "./platform";
|
|
2
|
-
import { Stack } from "./stack";
|
|
3
|
-
export var Level;
|
|
4
|
-
(function (Level) {
|
|
5
|
-
Level[Level["debug"] = 0] = "debug";
|
|
6
|
-
Level[Level["info"] = 1] = "info";
|
|
7
|
-
Level[Level["notice"] = 2] = "notice";
|
|
8
|
-
Level[Level["warning"] = 3] = "warning";
|
|
9
|
-
Level[Level["error"] = 4] = "error";
|
|
10
|
-
Level[Level["critical"] = 5] = "critical";
|
|
11
|
-
Level[Level["alert"] = 6] = "alert";
|
|
12
|
-
Level[Level["emergency"] = 7] = "emergency";
|
|
13
|
-
})(Level || (Level = {}));
|
|
14
|
-
var colours = {
|
|
15
|
-
debug: "cyan",
|
|
16
|
-
info: "green",
|
|
17
|
-
notice: "grey",
|
|
18
|
-
warning: "blue",
|
|
19
|
-
error: "red",
|
|
20
|
-
critical: "magenta",
|
|
21
|
-
alert: "magenta",
|
|
22
|
-
emergency: "magenta"
|
|
23
|
-
};
|
|
24
|
-
var ConsoleWriter = /** @class */ (function () {
|
|
25
|
-
function ConsoleWriter() {
|
|
26
|
-
}
|
|
27
|
-
ConsoleWriter.prototype.write = function (dateTime, level, id, msg) {
|
|
28
|
-
if (isNode) {
|
|
29
|
-
console.log("[".concat(dateTime, "] ").concat(Level[level].toUpperCase(), " ").concat(id, ": ").concat(msg));
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
console.log("[".concat(dateTime, "] %c").concat(Level[level].toUpperCase(), "%c ").concat(id, ": ").concat(msg), "color:".concat(colours[Level[level]]), "");
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
return ConsoleWriter;
|
|
36
|
-
}());
|
|
37
|
-
var Logging = /** @class */ (function () {
|
|
38
|
-
function Logging() {
|
|
39
|
-
this._levelStack = new Stack();
|
|
40
|
-
this._level = Level.info;
|
|
41
|
-
this._filter = "";
|
|
42
|
-
this._writer = new ConsoleWriter();
|
|
43
|
-
}
|
|
44
|
-
Logging.Instance = function () {
|
|
45
|
-
return this._instance || (this._instance = new this());
|
|
46
|
-
};
|
|
47
|
-
Logging.prototype.stringify = function (obj) {
|
|
48
|
-
var cache = [];
|
|
49
|
-
return JSON.stringify(obj, function (_key, value) {
|
|
50
|
-
if (typeof value === "object" && value !== null) {
|
|
51
|
-
if (cache.indexOf(value) !== -1) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
cache.push(value);
|
|
55
|
-
}
|
|
56
|
-
return value;
|
|
57
|
-
}, 2);
|
|
58
|
-
};
|
|
59
|
-
Logging.prototype.writer = function (_) {
|
|
60
|
-
if (_ === void 0)
|
|
61
|
-
return this._writer;
|
|
62
|
-
this._writer = _;
|
|
63
|
-
return this;
|
|
64
|
-
};
|
|
65
|
-
Logging.prototype.log = function (level, id, msg) {
|
|
66
|
-
if (level < this._level)
|
|
67
|
-
return;
|
|
68
|
-
if (this._filter && this._filter !== id)
|
|
69
|
-
return;
|
|
70
|
-
var dateTime = new Date().toISOString();
|
|
71
|
-
if (this._writer.rawWrite) {
|
|
72
|
-
this._writer.rawWrite(dateTime, level, id, msg);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
if (typeof msg !== "string") {
|
|
76
|
-
msg = this.stringify(msg);
|
|
77
|
-
}
|
|
78
|
-
if (this._writer.write) {
|
|
79
|
-
this._writer.write(dateTime, level, id, msg);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
Logging.prototype.debug = function (id, msg) {
|
|
84
|
-
this.log(Level.debug, id, msg);
|
|
85
|
-
};
|
|
86
|
-
Logging.prototype.info = function (id, msg) {
|
|
87
|
-
this.log(Level.info, id, msg);
|
|
88
|
-
};
|
|
89
|
-
Logging.prototype.notice = function (id, msg) {
|
|
90
|
-
this.log(Level.notice, id, msg);
|
|
91
|
-
};
|
|
92
|
-
Logging.prototype.warning = function (id, msg) {
|
|
93
|
-
this.log(Level.warning, id, msg);
|
|
94
|
-
};
|
|
95
|
-
Logging.prototype.error = function (id, msg) {
|
|
96
|
-
this.log(Level.error, id, msg);
|
|
97
|
-
};
|
|
98
|
-
Logging.prototype.critical = function (id, msg) {
|
|
99
|
-
this.log(Level.critical, id, msg);
|
|
100
|
-
};
|
|
101
|
-
Logging.prototype.alert = function (id, msg) {
|
|
102
|
-
this.log(Level.alert, id, msg);
|
|
103
|
-
};
|
|
104
|
-
Logging.prototype.emergency = function (id, msg) {
|
|
105
|
-
this.log(Level.emergency, id, msg);
|
|
106
|
-
};
|
|
107
|
-
Logging.prototype.level = function (_) {
|
|
108
|
-
if (_ === void 0)
|
|
109
|
-
return this._level;
|
|
110
|
-
this._level = _;
|
|
111
|
-
return this;
|
|
112
|
-
};
|
|
113
|
-
Logging.prototype.pushLevel = function (_) {
|
|
114
|
-
this._levelStack.push(this._level);
|
|
115
|
-
this._level = _;
|
|
116
|
-
return this;
|
|
117
|
-
};
|
|
118
|
-
Logging.prototype.popLevel = function () {
|
|
119
|
-
this._level = this._levelStack.pop();
|
|
120
|
-
return this;
|
|
121
|
-
};
|
|
122
|
-
Logging.prototype.filter = function (_) {
|
|
123
|
-
if (_ === void 0)
|
|
124
|
-
return this._filter;
|
|
125
|
-
this._filter = _;
|
|
126
|
-
return this;
|
|
127
|
-
};
|
|
128
|
-
return Logging;
|
|
129
|
-
}());
|
|
130
|
-
export { Logging };
|
|
131
|
-
export var logger = Logging.Instance();
|
|
132
|
-
var ScopedLogging = /** @class */ (function () {
|
|
133
|
-
function ScopedLogging(scopeID) {
|
|
134
|
-
this._scopeID = scopeID;
|
|
135
|
-
}
|
|
136
|
-
ScopedLogging.prototype.debug = function (msg) {
|
|
137
|
-
logger.debug(this._scopeID, msg);
|
|
138
|
-
};
|
|
139
|
-
ScopedLogging.prototype.info = function (msg) {
|
|
140
|
-
logger.info(this._scopeID, msg);
|
|
141
|
-
};
|
|
142
|
-
ScopedLogging.prototype.notice = function (msg) {
|
|
143
|
-
logger.notice(this._scopeID, msg);
|
|
144
|
-
};
|
|
145
|
-
ScopedLogging.prototype.warning = function (msg) {
|
|
146
|
-
logger.warning(this._scopeID, msg);
|
|
147
|
-
};
|
|
148
|
-
ScopedLogging.prototype.error = function (msg) {
|
|
149
|
-
logger.error(this._scopeID, msg);
|
|
150
|
-
};
|
|
151
|
-
ScopedLogging.prototype.critical = function (msg) {
|
|
152
|
-
logger.critical(this._scopeID, msg);
|
|
153
|
-
};
|
|
154
|
-
ScopedLogging.prototype.alert = function (msg) {
|
|
155
|
-
logger.alert(this._scopeID, msg);
|
|
156
|
-
};
|
|
157
|
-
ScopedLogging.prototype.emergency = function (msg) {
|
|
158
|
-
logger.emergency(this._scopeID, msg);
|
|
159
|
-
};
|
|
160
|
-
ScopedLogging.prototype.pushLevel = function (_) {
|
|
161
|
-
logger.pushLevel(_);
|
|
162
|
-
return this;
|
|
163
|
-
};
|
|
164
|
-
ScopedLogging.prototype.popLevel = function () {
|
|
165
|
-
logger.popLevel();
|
|
166
|
-
return this;
|
|
167
|
-
};
|
|
168
|
-
return ScopedLogging;
|
|
169
|
-
}());
|
|
170
|
-
export { ScopedLogging };
|
|
171
|
-
export function scopedLogger(scopeID, filter) {
|
|
172
|
-
if (filter === void 0) { filter = false; }
|
|
173
|
-
if (filter) {
|
|
174
|
-
logger.filter(scopeID);
|
|
175
|
-
}
|
|
176
|
-
return new ScopedLogging(scopeID);
|
|
177
|
-
}
|
|
1
|
+
import { isNode } from "./platform";
|
|
2
|
+
import { Stack } from "./stack";
|
|
3
|
+
export var Level;
|
|
4
|
+
(function (Level) {
|
|
5
|
+
Level[Level["debug"] = 0] = "debug";
|
|
6
|
+
Level[Level["info"] = 1] = "info";
|
|
7
|
+
Level[Level["notice"] = 2] = "notice";
|
|
8
|
+
Level[Level["warning"] = 3] = "warning";
|
|
9
|
+
Level[Level["error"] = 4] = "error";
|
|
10
|
+
Level[Level["critical"] = 5] = "critical";
|
|
11
|
+
Level[Level["alert"] = 6] = "alert";
|
|
12
|
+
Level[Level["emergency"] = 7] = "emergency";
|
|
13
|
+
})(Level || (Level = {}));
|
|
14
|
+
var colours = {
|
|
15
|
+
debug: "cyan",
|
|
16
|
+
info: "green",
|
|
17
|
+
notice: "grey",
|
|
18
|
+
warning: "blue",
|
|
19
|
+
error: "red",
|
|
20
|
+
critical: "magenta",
|
|
21
|
+
alert: "magenta",
|
|
22
|
+
emergency: "magenta"
|
|
23
|
+
};
|
|
24
|
+
var ConsoleWriter = /** @class */ (function () {
|
|
25
|
+
function ConsoleWriter() {
|
|
26
|
+
}
|
|
27
|
+
ConsoleWriter.prototype.write = function (dateTime, level, id, msg) {
|
|
28
|
+
if (isNode) {
|
|
29
|
+
console.log("[".concat(dateTime, "] ").concat(Level[level].toUpperCase(), " ").concat(id, ": ").concat(msg));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log("[".concat(dateTime, "] %c").concat(Level[level].toUpperCase(), "%c ").concat(id, ": ").concat(msg), "color:".concat(colours[Level[level]]), "");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return ConsoleWriter;
|
|
36
|
+
}());
|
|
37
|
+
var Logging = /** @class */ (function () {
|
|
38
|
+
function Logging() {
|
|
39
|
+
this._levelStack = new Stack();
|
|
40
|
+
this._level = Level.info;
|
|
41
|
+
this._filter = "";
|
|
42
|
+
this._writer = new ConsoleWriter();
|
|
43
|
+
}
|
|
44
|
+
Logging.Instance = function () {
|
|
45
|
+
return this._instance || (this._instance = new this());
|
|
46
|
+
};
|
|
47
|
+
Logging.prototype.stringify = function (obj) {
|
|
48
|
+
var cache = [];
|
|
49
|
+
return JSON.stringify(obj, function (_key, value) {
|
|
50
|
+
if (typeof value === "object" && value !== null) {
|
|
51
|
+
if (cache.indexOf(value) !== -1) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
cache.push(value);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}, 2);
|
|
58
|
+
};
|
|
59
|
+
Logging.prototype.writer = function (_) {
|
|
60
|
+
if (_ === void 0)
|
|
61
|
+
return this._writer;
|
|
62
|
+
this._writer = _;
|
|
63
|
+
return this;
|
|
64
|
+
};
|
|
65
|
+
Logging.prototype.log = function (level, id, msg) {
|
|
66
|
+
if (level < this._level)
|
|
67
|
+
return;
|
|
68
|
+
if (this._filter && this._filter !== id)
|
|
69
|
+
return;
|
|
70
|
+
var dateTime = new Date().toISOString();
|
|
71
|
+
if (this._writer.rawWrite) {
|
|
72
|
+
this._writer.rawWrite(dateTime, level, id, msg);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (typeof msg !== "string") {
|
|
76
|
+
msg = this.stringify(msg);
|
|
77
|
+
}
|
|
78
|
+
if (this._writer.write) {
|
|
79
|
+
this._writer.write(dateTime, level, id, msg);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
Logging.prototype.debug = function (id, msg) {
|
|
84
|
+
this.log(Level.debug, id, msg);
|
|
85
|
+
};
|
|
86
|
+
Logging.prototype.info = function (id, msg) {
|
|
87
|
+
this.log(Level.info, id, msg);
|
|
88
|
+
};
|
|
89
|
+
Logging.prototype.notice = function (id, msg) {
|
|
90
|
+
this.log(Level.notice, id, msg);
|
|
91
|
+
};
|
|
92
|
+
Logging.prototype.warning = function (id, msg) {
|
|
93
|
+
this.log(Level.warning, id, msg);
|
|
94
|
+
};
|
|
95
|
+
Logging.prototype.error = function (id, msg) {
|
|
96
|
+
this.log(Level.error, id, msg);
|
|
97
|
+
};
|
|
98
|
+
Logging.prototype.critical = function (id, msg) {
|
|
99
|
+
this.log(Level.critical, id, msg);
|
|
100
|
+
};
|
|
101
|
+
Logging.prototype.alert = function (id, msg) {
|
|
102
|
+
this.log(Level.alert, id, msg);
|
|
103
|
+
};
|
|
104
|
+
Logging.prototype.emergency = function (id, msg) {
|
|
105
|
+
this.log(Level.emergency, id, msg);
|
|
106
|
+
};
|
|
107
|
+
Logging.prototype.level = function (_) {
|
|
108
|
+
if (_ === void 0)
|
|
109
|
+
return this._level;
|
|
110
|
+
this._level = _;
|
|
111
|
+
return this;
|
|
112
|
+
};
|
|
113
|
+
Logging.prototype.pushLevel = function (_) {
|
|
114
|
+
this._levelStack.push(this._level);
|
|
115
|
+
this._level = _;
|
|
116
|
+
return this;
|
|
117
|
+
};
|
|
118
|
+
Logging.prototype.popLevel = function () {
|
|
119
|
+
this._level = this._levelStack.pop();
|
|
120
|
+
return this;
|
|
121
|
+
};
|
|
122
|
+
Logging.prototype.filter = function (_) {
|
|
123
|
+
if (_ === void 0)
|
|
124
|
+
return this._filter;
|
|
125
|
+
this._filter = _;
|
|
126
|
+
return this;
|
|
127
|
+
};
|
|
128
|
+
return Logging;
|
|
129
|
+
}());
|
|
130
|
+
export { Logging };
|
|
131
|
+
export var logger = Logging.Instance();
|
|
132
|
+
var ScopedLogging = /** @class */ (function () {
|
|
133
|
+
function ScopedLogging(scopeID) {
|
|
134
|
+
this._scopeID = scopeID;
|
|
135
|
+
}
|
|
136
|
+
ScopedLogging.prototype.debug = function (msg) {
|
|
137
|
+
logger.debug(this._scopeID, msg);
|
|
138
|
+
};
|
|
139
|
+
ScopedLogging.prototype.info = function (msg) {
|
|
140
|
+
logger.info(this._scopeID, msg);
|
|
141
|
+
};
|
|
142
|
+
ScopedLogging.prototype.notice = function (msg) {
|
|
143
|
+
logger.notice(this._scopeID, msg);
|
|
144
|
+
};
|
|
145
|
+
ScopedLogging.prototype.warning = function (msg) {
|
|
146
|
+
logger.warning(this._scopeID, msg);
|
|
147
|
+
};
|
|
148
|
+
ScopedLogging.prototype.error = function (msg) {
|
|
149
|
+
logger.error(this._scopeID, msg);
|
|
150
|
+
};
|
|
151
|
+
ScopedLogging.prototype.critical = function (msg) {
|
|
152
|
+
logger.critical(this._scopeID, msg);
|
|
153
|
+
};
|
|
154
|
+
ScopedLogging.prototype.alert = function (msg) {
|
|
155
|
+
logger.alert(this._scopeID, msg);
|
|
156
|
+
};
|
|
157
|
+
ScopedLogging.prototype.emergency = function (msg) {
|
|
158
|
+
logger.emergency(this._scopeID, msg);
|
|
159
|
+
};
|
|
160
|
+
ScopedLogging.prototype.pushLevel = function (_) {
|
|
161
|
+
logger.pushLevel(_);
|
|
162
|
+
return this;
|
|
163
|
+
};
|
|
164
|
+
ScopedLogging.prototype.popLevel = function () {
|
|
165
|
+
logger.popLevel();
|
|
166
|
+
return this;
|
|
167
|
+
};
|
|
168
|
+
return ScopedLogging;
|
|
169
|
+
}());
|
|
170
|
+
export { ScopedLogging };
|
|
171
|
+
export function scopedLogger(scopeID, filter) {
|
|
172
|
+
if (filter === void 0) { filter = false; }
|
|
173
|
+
if (filter) {
|
|
174
|
+
logger.filter(scopeID);
|
|
175
|
+
}
|
|
176
|
+
return new ScopedLogging(scopeID);
|
|
177
|
+
}
|
|
178
178
|
//# sourceMappingURL=logging.js.map
|