@hpcc-js/util 2.45.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.
Files changed (79) hide show
  1. package/LICENSE +43 -43
  2. package/dist/index.js +2290 -2289
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/lib-es6/__package__.js +3 -3
  7. package/lib-es6/array.js +84 -84
  8. package/lib-es6/array.js.map +1 -1
  9. package/lib-es6/cache.js +60 -60
  10. package/lib-es6/debounce.js +85 -85
  11. package/lib-es6/dictionary.js +61 -61
  12. package/lib-es6/dispatch.js +101 -101
  13. package/lib-es6/esp.js +32 -32
  14. package/lib-es6/graph.js +348 -348
  15. package/lib-es6/graph.js.map +1 -1
  16. package/lib-es6/graph2.js +603 -603
  17. package/lib-es6/graph2.js.map +1 -1
  18. package/lib-es6/hashSum.js +49 -49
  19. package/lib-es6/immutable.js +54 -54
  20. package/lib-es6/index.js +21 -21
  21. package/lib-es6/logging.js +177 -177
  22. package/lib-es6/logging.js.map +1 -1
  23. package/lib-es6/math.js +90 -90
  24. package/lib-es6/object.js +121 -121
  25. package/lib-es6/object.js.map +1 -1
  26. package/lib-es6/observer.js +79 -79
  27. package/lib-es6/platform.js +17 -17
  28. package/lib-es6/saxParser.js +125 -125
  29. package/lib-es6/stack.js +41 -41
  30. package/lib-es6/stateful.js +170 -170
  31. package/lib-es6/string.js +22 -22
  32. package/lib-es6/url.js +32 -32
  33. package/lib-es6/url.js.map +1 -1
  34. package/package.json +6 -21
  35. package/src/__package__.ts +2 -2
  36. package/src/array.ts +98 -98
  37. package/src/cache.ts +65 -65
  38. package/src/debounce.ts +88 -88
  39. package/src/dictionary.ts +69 -69
  40. package/src/dispatch.ts +119 -119
  41. package/src/esp.ts +32 -32
  42. package/src/graph.ts +353 -353
  43. package/src/graph2.ts +661 -661
  44. package/src/hashSum.ts +55 -55
  45. package/src/immutable.ts +57 -57
  46. package/src/index.ts +21 -21
  47. package/src/logging.ts +211 -211
  48. package/src/math.ts +92 -92
  49. package/src/object.ts +117 -117
  50. package/src/observer.ts +91 -91
  51. package/src/platform.ts +20 -20
  52. package/src/saxParser.ts +135 -135
  53. package/src/stack.ts +41 -41
  54. package/src/stateful.ts +178 -178
  55. package/src/string.ts +21 -21
  56. package/src/url.ts +27 -27
  57. package/types/__package__.d.ts +3 -3
  58. package/types/array.d.ts +13 -13
  59. package/types/cache.d.ts +20 -20
  60. package/types/debounce.d.ts +12 -12
  61. package/types/dictionary.d.ts +20 -20
  62. package/types/dispatch.d.ts +26 -26
  63. package/types/esp.d.ts +1 -1
  64. package/types/graph.d.ts +73 -73
  65. package/types/graph2.d.ts +111 -111
  66. package/types/hashSum.d.ts +1 -1
  67. package/types/immutable.d.ts +2 -2
  68. package/types/index.d.ts +21 -21
  69. package/types/logging.d.ts +57 -57
  70. package/types/math.d.ts +70 -70
  71. package/types/object.d.ts +48 -48
  72. package/types/observer.d.ts +18 -18
  73. package/types/platform.d.ts +5 -5
  74. package/types/saxParser.d.ts +28 -28
  75. package/types/stack.d.ts +28 -28
  76. package/types/stateful.d.ts +33 -33
  77. package/types/string.d.ts +2 -2
  78. package/types/url.d.ts +2 -2
  79. package/types-3.4/__package__.d.ts +2 -2
package/src/saxParser.ts CHANGED
@@ -1,135 +1,135 @@
1
- import { StringAnyMap } from "./dictionary";
2
- import { Stack } from "./stack";
3
-
4
- export class XMLNode {
5
- name: string = "";
6
- $: StringAnyMap = {};
7
- protected _children: XMLNode[] = [];
8
- content: string = "";
9
-
10
- constructor(name: string) {
11
- this.name = name;
12
- }
13
-
14
- appendAttribute(key: string, val: string) {
15
- this.$[key] = val;
16
- }
17
-
18
- appendContent(content: string) {
19
- this.content += content;
20
- }
21
-
22
- appendChild(child: XMLNode) {
23
- this._children.push(child);
24
- }
25
-
26
- children(tag?: string): XMLNode[] {
27
- if (tag === undefined) {
28
- return this._children;
29
- }
30
- return this._children.filter((xmlNode) => {
31
- return xmlNode.name === tag;
32
- });
33
- }
34
- }
35
-
36
- export class SAXStackParser {
37
- root: XMLNode;
38
- stack: Stack<XMLNode> = new Stack<XMLNode>();
39
-
40
- constructor() {
41
- }
42
-
43
- private walkDoc(node: any) {
44
- const xmlNode = this._startXMLNode(node);
45
- if (node.attributes) {
46
- for (let i = 0; i < node.attributes.length; ++i) {
47
- const attribute = node.attributes.item(i);
48
- this.attributes(attribute.nodeName, attribute.nodeValue);
49
- }
50
- }
51
- this.startXMLNode(xmlNode);
52
- if (node.childNodes) {
53
- for (let i = 0; i < node.childNodes.length; ++i) {
54
- const childNode = node.childNodes.item(i);
55
- if (childNode.nodeType === childNode.TEXT_NODE) {
56
- this.characters(childNode.nodeValue!);
57
- } else {
58
- this.walkDoc(childNode);
59
- }
60
- }
61
- }
62
- this.endXMLNode(this.stack.pop()!);
63
- }
64
-
65
- private _startXMLNode(node: Node): XMLNode {
66
- const newNode = new XMLNode(node.nodeName);
67
- if (!this.stack.depth()) {
68
- this.root = newNode;
69
- } else {
70
- this.stack.top()!.appendChild(newNode);
71
- }
72
- return this.stack.push(newNode);
73
- }
74
-
75
- parse(xml: string) {
76
- const domParser = new DOMParser();
77
- const doc = domParser.parseFromString(xml, "application/xml");
78
- this.startDocument();
79
- this.walkDoc(doc);
80
- this.endDocument();
81
- }
82
-
83
- // Callbacks ---
84
- startDocument() {
85
- }
86
-
87
- endDocument() {
88
- }
89
-
90
- startXMLNode(node: XMLNode) {
91
- }
92
-
93
- endXMLNode(node: XMLNode) {
94
- }
95
-
96
- attributes(key: string, val: any) {
97
- this.stack.top()!.appendAttribute(key, val);
98
- }
99
-
100
- characters(text: string) {
101
- this.stack.top()!.appendContent(text);
102
- }
103
- }
104
-
105
- class XML2JSONParser extends SAXStackParser {
106
- startXMLNode(node: XMLNode) {
107
- super.startXMLNode(node);
108
- switch (node.name) {
109
- case "xs:element":
110
- break;
111
- case "xs:simpleType":
112
- break;
113
- default:
114
- break;
115
- }
116
- }
117
-
118
- endXMLNode(node: XMLNode) {
119
- switch (node.name) {
120
- case "xs:element":
121
- break;
122
- case "xs:simpleType":
123
- break;
124
- default:
125
- break;
126
- }
127
- super.endXMLNode(node);
128
- }
129
- }
130
-
131
- export function xml2json(xml: string): XMLNode {
132
- const saxParser = new XML2JSONParser();
133
- saxParser.parse(xml);
134
- return saxParser.root;
135
- }
1
+ import { StringAnyMap } from "./dictionary";
2
+ import { Stack } from "./stack";
3
+
4
+ export class XMLNode {
5
+ name: string = "";
6
+ $: StringAnyMap = {};
7
+ protected _children: XMLNode[] = [];
8
+ content: string = "";
9
+
10
+ constructor(name: string) {
11
+ this.name = name;
12
+ }
13
+
14
+ appendAttribute(key: string, val: string) {
15
+ this.$[key] = val;
16
+ }
17
+
18
+ appendContent(content: string) {
19
+ this.content += content;
20
+ }
21
+
22
+ appendChild(child: XMLNode) {
23
+ this._children.push(child);
24
+ }
25
+
26
+ children(tag?: string): XMLNode[] {
27
+ if (tag === undefined) {
28
+ return this._children;
29
+ }
30
+ return this._children.filter((xmlNode) => {
31
+ return xmlNode.name === tag;
32
+ });
33
+ }
34
+ }
35
+
36
+ export class SAXStackParser {
37
+ root: XMLNode;
38
+ stack: Stack<XMLNode> = new Stack<XMLNode>();
39
+
40
+ constructor() {
41
+ }
42
+
43
+ private walkDoc(node: any) {
44
+ const xmlNode = this._startXMLNode(node);
45
+ if (node.attributes) {
46
+ for (let i = 0; i < node.attributes.length; ++i) {
47
+ const attribute = node.attributes.item(i);
48
+ this.attributes(attribute.nodeName, attribute.nodeValue);
49
+ }
50
+ }
51
+ this.startXMLNode(xmlNode);
52
+ if (node.childNodes) {
53
+ for (let i = 0; i < node.childNodes.length; ++i) {
54
+ const childNode = node.childNodes.item(i);
55
+ if (childNode.nodeType === childNode.TEXT_NODE) {
56
+ this.characters(childNode.nodeValue!);
57
+ } else {
58
+ this.walkDoc(childNode);
59
+ }
60
+ }
61
+ }
62
+ this.endXMLNode(this.stack.pop()!);
63
+ }
64
+
65
+ private _startXMLNode(node: Node): XMLNode {
66
+ const newNode = new XMLNode(node.nodeName);
67
+ if (!this.stack.depth()) {
68
+ this.root = newNode;
69
+ } else {
70
+ this.stack.top()!.appendChild(newNode);
71
+ }
72
+ return this.stack.push(newNode);
73
+ }
74
+
75
+ parse(xml: string) {
76
+ const domParser = new DOMParser();
77
+ const doc = domParser.parseFromString(xml, "application/xml");
78
+ this.startDocument();
79
+ this.walkDoc(doc);
80
+ this.endDocument();
81
+ }
82
+
83
+ // Callbacks ---
84
+ startDocument() {
85
+ }
86
+
87
+ endDocument() {
88
+ }
89
+
90
+ startXMLNode(node: XMLNode) {
91
+ }
92
+
93
+ endXMLNode(node: XMLNode) {
94
+ }
95
+
96
+ attributes(key: string, val: any) {
97
+ this.stack.top()!.appendAttribute(key, val);
98
+ }
99
+
100
+ characters(text: string) {
101
+ this.stack.top()!.appendContent(text);
102
+ }
103
+ }
104
+
105
+ class XML2JSONParser extends SAXStackParser {
106
+ startXMLNode(node: XMLNode) {
107
+ super.startXMLNode(node);
108
+ switch (node.name) {
109
+ case "xs:element":
110
+ break;
111
+ case "xs:simpleType":
112
+ break;
113
+ default:
114
+ break;
115
+ }
116
+ }
117
+
118
+ endXMLNode(node: XMLNode) {
119
+ switch (node.name) {
120
+ case "xs:element":
121
+ break;
122
+ case "xs:simpleType":
123
+ break;
124
+ default:
125
+ break;
126
+ }
127
+ super.endXMLNode(node);
128
+ }
129
+ }
130
+
131
+ export function xml2json(xml: string): XMLNode {
132
+ const saxParser = new XML2JSONParser();
133
+ saxParser.parse(xml);
134
+ return saxParser.root;
135
+ }
package/src/stack.ts CHANGED
@@ -1,41 +1,41 @@
1
- /**
2
- * A generic Stack
3
- */
4
- export class Stack<T> {
5
- private stack: T[] = [];
6
-
7
- /**
8
- * Push element onto the stack
9
- *
10
- * @param e - element to push
11
- */
12
- push(e: T) {
13
- this.stack.push(e);
14
- return e;
15
- }
16
-
17
- /**
18
- * Pop element off the stack
19
- */
20
- pop(): T | undefined {
21
- return this.stack.pop();
22
- }
23
-
24
- /**
25
- * Top item on the stack
26
- *
27
- * @returns Top element on the stack
28
- */
29
- top(): T | undefined {
30
- return this.stack.length ? this.stack[this.stack.length - 1] : undefined;
31
- }
32
-
33
- /**
34
- * Depth of stack
35
- *
36
- * @returns Depth
37
- */
38
- depth(): number {
39
- return this.stack.length;
40
- }
41
- }
1
+ /**
2
+ * A generic Stack
3
+ */
4
+ export class Stack<T> {
5
+ private stack: T[] = [];
6
+
7
+ /**
8
+ * Push element onto the stack
9
+ *
10
+ * @param e - element to push
11
+ */
12
+ push(e: T) {
13
+ this.stack.push(e);
14
+ return e;
15
+ }
16
+
17
+ /**
18
+ * Pop element off the stack
19
+ */
20
+ pop(): T | undefined {
21
+ return this.stack.pop();
22
+ }
23
+
24
+ /**
25
+ * Top item on the stack
26
+ *
27
+ * @returns Top element on the stack
28
+ */
29
+ top(): T | undefined {
30
+ return this.stack.length ? this.stack[this.stack.length - 1] : undefined;
31
+ }
32
+
33
+ /**
34
+ * Depth of stack
35
+ *
36
+ * @returns Depth
37
+ */
38
+ depth(): number {
39
+ return this.stack.length;
40
+ }
41
+ }