@hpcc-js/util 2.46.1 → 2.47.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 +2373 -2281
  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/cache.js +60 -60
  9. package/lib-es6/debounce.js +85 -85
  10. package/lib-es6/dictionary.js +61 -61
  11. package/lib-es6/dispatch.js +101 -101
  12. package/lib-es6/esp.js +32 -32
  13. package/lib-es6/graph.js +348 -348
  14. package/lib-es6/graph2.js +603 -603
  15. package/lib-es6/hashSum.js +49 -49
  16. package/lib-es6/immutable.js +144 -54
  17. package/lib-es6/immutable.js.map +1 -1
  18. package/lib-es6/index.js +21 -21
  19. package/lib-es6/logging.js +178 -177
  20. package/lib-es6/logging.js.map +1 -1
  21. package/lib-es6/math.js +90 -90
  22. package/lib-es6/object.js +121 -121
  23. package/lib-es6/observer.js +79 -79
  24. package/lib-es6/platform.js +17 -17
  25. package/lib-es6/saxParser.js +125 -125
  26. package/lib-es6/stack.js +41 -41
  27. package/lib-es6/stateful.js +170 -170
  28. package/lib-es6/string.js +22 -22
  29. package/lib-es6/url.js +32 -32
  30. package/package.json +3 -3
  31. package/src/__package__.ts +2 -2
  32. package/src/array.ts +98 -98
  33. package/src/cache.ts +65 -65
  34. package/src/debounce.ts +88 -88
  35. package/src/dictionary.ts +69 -69
  36. package/src/dispatch.ts +119 -119
  37. package/src/esp.ts +32 -32
  38. package/src/graph.ts +353 -353
  39. package/src/graph2.ts +661 -661
  40. package/src/hashSum.ts +55 -55
  41. package/src/immutable.ts +156 -57
  42. package/src/index.ts +21 -21
  43. package/src/logging.ts +212 -211
  44. package/src/math.ts +92 -92
  45. package/src/object.ts +117 -117
  46. package/src/observer.ts +91 -91
  47. package/src/platform.ts +20 -20
  48. package/src/saxParser.ts +135 -135
  49. package/src/stack.ts +41 -41
  50. package/src/stateful.ts +178 -178
  51. package/src/string.ts +21 -21
  52. package/src/url.ts +27 -27
  53. package/types/__package__.d.ts +3 -3
  54. package/types/array.d.ts +13 -13
  55. package/types/cache.d.ts +20 -20
  56. package/types/debounce.d.ts +12 -12
  57. package/types/dictionary.d.ts +20 -20
  58. package/types/dispatch.d.ts +26 -26
  59. package/types/dispatch.d.ts.map +1 -1
  60. package/types/esp.d.ts +1 -1
  61. package/types/graph.d.ts +73 -73
  62. package/types/graph2.d.ts +111 -111
  63. package/types/hashSum.d.ts +1 -1
  64. package/types/immutable.d.ts +3 -2
  65. package/types/immutable.d.ts.map +1 -1
  66. package/types/index.d.ts +21 -21
  67. package/types/logging.d.ts +57 -57
  68. package/types/logging.d.ts.map +1 -1
  69. package/types/math.d.ts +70 -70
  70. package/types/object.d.ts +48 -48
  71. package/types/observer.d.ts +18 -18
  72. package/types/platform.d.ts +5 -5
  73. package/types/saxParser.d.ts +28 -28
  74. package/types/stack.d.ts +28 -28
  75. package/types/stateful.d.ts +33 -33
  76. package/types/string.d.ts +2 -2
  77. package/types/url.d.ts +2 -2
  78. package/types-3.4/__package__.d.ts +2 -2
  79. package/types-3.4/immutable.d.ts +1 -0
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
+ }