@glutinum/cli 0.3.1 → 0.5.0

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 (171) hide show
  1. package/README.md +169 -1
  2. package/dist/Glutinum.Converter/FsharpAST.js +152 -20
  3. package/dist/Glutinum.Converter/FsharpAST.js.map +1 -1
  4. package/dist/Glutinum.Converter/Generate.js +17 -5
  5. package/dist/Glutinum.Converter/Generate.js.map +1 -1
  6. package/dist/Glutinum.Converter/GlueAST.js +97 -17
  7. package/dist/Glutinum.Converter/GlueAST.js.map +1 -1
  8. package/dist/Glutinum.Converter/Log.js +9 -5
  9. package/dist/Glutinum.Converter/Log.js.map +1 -1
  10. package/dist/Glutinum.Converter/Printer.js +486 -132
  11. package/dist/Glutinum.Converter/Printer.js.map +1 -1
  12. package/dist/Glutinum.Converter/Read.js +8 -5
  13. package/dist/Glutinum.Converter/Read.js.map +1 -1
  14. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +14 -6
  15. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js.map +1 -1
  16. package/dist/Glutinum.Converter/Reader/Declaration.js +50 -0
  17. package/dist/Glutinum.Converter/Reader/Declaration.js.map +1 -0
  18. package/dist/Glutinum.Converter/Reader/Documentation.js +119 -0
  19. package/dist/Glutinum.Converter/Reader/Documentation.js.map +1 -0
  20. package/dist/Glutinum.Converter/Reader/EnumDeclaration.js +13 -11
  21. package/dist/Glutinum.Converter/Reader/EnumDeclaration.js.map +1 -1
  22. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +42 -0
  23. package/dist/Glutinum.Converter/Reader/ExportAssignment.js.map +1 -0
  24. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +15 -5
  25. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js.map +1 -1
  26. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +4 -2
  27. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js.map +1 -1
  28. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +3 -3
  29. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js.map +1 -1
  30. package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +3 -3
  31. package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js.map +1 -1
  32. package/dist/Glutinum.Converter/Reader/Node.js +24 -10
  33. package/dist/Glutinum.Converter/Reader/Node.js.map +1 -1
  34. package/dist/Glutinum.Converter/Reader/Parameters.js +3 -3
  35. package/dist/Glutinum.Converter/Reader/Parameters.js.map +1 -1
  36. package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
  37. package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js.map +1 -1
  38. package/dist/Glutinum.Converter/Reader/TypeNode.js +151 -18
  39. package/dist/Glutinum.Converter/Reader/TypeNode.js.map +1 -1
  40. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +29 -20
  41. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js.map +1 -1
  42. package/dist/Glutinum.Converter/Reader/TypeParameters.js +2 -2
  43. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +102 -77
  44. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js.map +1 -1
  45. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +17 -11
  46. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js.map +1 -1
  47. package/dist/Glutinum.Converter/Reader/Utils.js +80 -5
  48. package/dist/Glutinum.Converter/Reader/Utils.js.map +1 -1
  49. package/dist/Glutinum.Converter/Reader/VariableStatement.js +14 -7
  50. package/dist/Glutinum.Converter/Reader/VariableStatement.js.map +1 -1
  51. package/dist/Glutinum.Converter/Transform.js +559 -193
  52. package/dist/Glutinum.Converter/Transform.js.map +1 -1
  53. package/dist/Glutinum.Converter/TypeScript.js +1 -1
  54. package/dist/Glutinum.Converter/Utils/Keywords.js +3 -3
  55. package/dist/Glutinum.Converter/Utils/List.js +62 -0
  56. package/dist/Glutinum.Converter/Utils/List.js.map +1 -0
  57. package/dist/Glutinum.Converter/Utils/Naming.js +73 -6
  58. package/dist/Glutinum.Converter/Utils/Naming.js.map +1 -1
  59. package/dist/Glutinum.Converter/Utils/String.js +6 -1
  60. package/dist/Glutinum.Converter/Utils/String.js.map +1 -1
  61. package/dist/Program.js +9 -10
  62. package/dist/Program.js.map +1 -1
  63. package/package.json +22 -3
  64. package/dist/Glutinum.Converter/Reader/NamedDeclaration.js +0 -34
  65. package/dist/Glutinum.Converter/Reader/NamedDeclaration.js.map +0 -1
  66. package/dist/Glutinum.Converter/Reader/Types.js +0 -16
  67. package/dist/Glutinum.Converter/Reader/Types.js.map +0 -1
  68. package/dist/fable_modules/fable-library.4.5.0/Array.d.ts +0 -120
  69. package/dist/fable_modules/fable-library.4.5.0/Array.js +0 -1204
  70. package/dist/fable_modules/fable-library.4.5.0/Async.d.ts +0 -32
  71. package/dist/fable_modules/fable-library.4.5.0/Async.js +0 -158
  72. package/dist/fable_modules/fable-library.4.5.0/AsyncBuilder.d.ts +0 -59
  73. package/dist/fable_modules/fable-library.4.5.0/AsyncBuilder.js +0 -183
  74. package/dist/fable_modules/fable-library.4.5.0/BigInt.d.ts +0 -115
  75. package/dist/fable_modules/fable-library.4.5.0/BigInt.js +0 -282
  76. package/dist/fable_modules/fable-library.4.5.0/BitConverter.d.ts +0 -27
  77. package/dist/fable_modules/fable-library.4.5.0/BitConverter.js +0 -138
  78. package/dist/fable_modules/fable-library.4.5.0/Boolean.d.ts +0 -3
  79. package/dist/fable_modules/fable-library.4.5.0/Boolean.js +0 -21
  80. package/dist/fable_modules/fable-library.4.5.0/CHANGELOG.md +0 -11
  81. package/dist/fable_modules/fable-library.4.5.0/Char.d.ts +0 -65
  82. package/dist/fable_modules/fable-library.4.5.0/Char.js +0 -169
  83. package/dist/fable_modules/fable-library.4.5.0/Choice.d.ts +0 -138
  84. package/dist/fable_modules/fable-library.4.5.0/Choice.js +0 -227
  85. package/dist/fable_modules/fable-library.4.5.0/Date.d.ts +0 -70
  86. package/dist/fable_modules/fable-library.4.5.0/Date.js +0 -451
  87. package/dist/fable_modules/fable-library.4.5.0/DateOffset.d.ts +0 -63
  88. package/dist/fable_modules/fable-library.4.5.0/DateOffset.js +0 -268
  89. package/dist/fable_modules/fable-library.4.5.0/DateOnly.d.ts +0 -18
  90. package/dist/fable_modules/fable-library.4.5.0/DateOnly.js +0 -124
  91. package/dist/fable_modules/fable-library.4.5.0/Decimal.d.ts +0 -45
  92. package/dist/fable_modules/fable-library.4.5.0/Decimal.js +0 -212
  93. package/dist/fable_modules/fable-library.4.5.0/Double.d.ts +0 -11
  94. package/dist/fable_modules/fable-library.4.5.0/Double.js +0 -46
  95. package/dist/fable_modules/fable-library.4.5.0/Encoding.d.ts +0 -12
  96. package/dist/fable_modules/fable-library.4.5.0/Encoding.js +0 -173
  97. package/dist/fable_modules/fable-library.4.5.0/Event.d.ts +0 -31
  98. package/dist/fable_modules/fable-library.4.5.0/Event.js +0 -93
  99. package/dist/fable_modules/fable-library.4.5.0/FSharp.Collections.d.ts +0 -7
  100. package/dist/fable_modules/fable-library.4.5.0/FSharp.Collections.js +0 -27
  101. package/dist/fable_modules/fable-library.4.5.0/FSharp.Core.d.ts +0 -17
  102. package/dist/fable_modules/fable-library.4.5.0/FSharp.Core.js +0 -69
  103. package/dist/fable_modules/fable-library.4.5.0/Global.d.ts +0 -24
  104. package/dist/fable_modules/fable-library.4.5.0/Global.js +0 -8
  105. package/dist/fable_modules/fable-library.4.5.0/Guid.d.ts +0 -10
  106. package/dist/fable_modules/fable-library.4.5.0/Guid.js +0 -142
  107. package/dist/fable_modules/fable-library.4.5.0/Int32.d.ts +0 -28
  108. package/dist/fable_modules/fable-library.4.5.0/Int32.js +0 -135
  109. package/dist/fable_modules/fable-library.4.5.0/List.d.ts +0 -143
  110. package/dist/fable_modules/fable-library.4.5.0/List.js +0 -1273
  111. package/dist/fable_modules/fable-library.4.5.0/Long.d.ts +0 -3
  112. package/dist/fable_modules/fable-library.4.5.0/Long.js +0 -46
  113. package/dist/fable_modules/fable-library.4.5.0/MailboxProcessor.d.ts +0 -25
  114. package/dist/fable_modules/fable-library.4.5.0/MailboxProcessor.js +0 -93
  115. package/dist/fable_modules/fable-library.4.5.0/Map.d.ts +0 -178
  116. package/dist/fable_modules/fable-library.4.5.0/Map.js +0 -1396
  117. package/dist/fable_modules/fable-library.4.5.0/MapUtil.d.ts +0 -10
  118. package/dist/fable_modules/fable-library.4.5.0/MapUtil.js +0 -112
  119. package/dist/fable_modules/fable-library.4.5.0/MutableMap.d.ts +0 -52
  120. package/dist/fable_modules/fable-library.4.5.0/MutableMap.js +0 -326
  121. package/dist/fable_modules/fable-library.4.5.0/MutableSet.d.ts +0 -39
  122. package/dist/fable_modules/fable-library.4.5.0/MutableSet.js +0 -232
  123. package/dist/fable_modules/fable-library.4.5.0/Native.d.ts +0 -2
  124. package/dist/fable_modules/fable-library.4.5.0/Native.js +0 -8
  125. package/dist/fable_modules/fable-library.4.5.0/Numeric.d.ts +0 -19
  126. package/dist/fable_modules/fable-library.4.5.0/Numeric.js +0 -71
  127. package/dist/fable_modules/fable-library.4.5.0/Observable.d.ts +0 -32
  128. package/dist/fable_modules/fable-library.4.5.0/Observable.js +0 -113
  129. package/dist/fable_modules/fable-library.4.5.0/Option.d.ts +0 -28
  130. package/dist/fable_modules/fable-library.4.5.0/Option.js +0 -96
  131. package/dist/fable_modules/fable-library.4.5.0/README.md +0 -3
  132. package/dist/fable_modules/fable-library.4.5.0/Random.d.ts +0 -37
  133. package/dist/fable_modules/fable-library.4.5.0/Random.js +0 -170
  134. package/dist/fable_modules/fable-library.4.5.0/Range.d.ts +0 -12
  135. package/dist/fable_modules/fable-library.4.5.0/Range.js +0 -45
  136. package/dist/fable_modules/fable-library.4.5.0/Reflection.d.ts +0 -119
  137. package/dist/fable_modules/fable-library.4.5.0/Reflection.js +0 -461
  138. package/dist/fable_modules/fable-library.4.5.0/RegExp.d.ts +0 -10
  139. package/dist/fable_modules/fable-library.4.5.0/RegExp.js +0 -132
  140. package/dist/fable_modules/fable-library.4.5.0/Seq.d.ts +0 -165
  141. package/dist/fable_modules/fable-library.4.5.0/Seq.js +0 -1379
  142. package/dist/fable_modules/fable-library.4.5.0/Seq2.d.ts +0 -18
  143. package/dist/fable_modules/fable-library.4.5.0/Seq2.js +0 -111
  144. package/dist/fable_modules/fable-library.4.5.0/Set.d.ts +0 -190
  145. package/dist/fable_modules/fable-library.4.5.0/Set.js +0 -1789
  146. package/dist/fable_modules/fable-library.4.5.0/String.d.ts +0 -49
  147. package/dist/fable_modules/fable-library.4.5.0/String.js +0 -540
  148. package/dist/fable_modules/fable-library.4.5.0/System.Collections.Generic.d.ts +0 -71
  149. package/dist/fable_modules/fable-library.4.5.0/System.Collections.Generic.js +0 -307
  150. package/dist/fable_modules/fable-library.4.5.0/System.Text.d.ts +0 -30
  151. package/dist/fable_modules/fable-library.4.5.0/System.Text.js +0 -110
  152. package/dist/fable_modules/fable-library.4.5.0/SystemException.d.ts +0 -5
  153. package/dist/fable_modules/fable-library.4.5.0/SystemException.js +0 -5
  154. package/dist/fable_modules/fable-library.4.5.0/TimeOnly.d.ts +0 -15
  155. package/dist/fable_modules/fable-library.4.5.0/TimeOnly.js +0 -122
  156. package/dist/fable_modules/fable-library.4.5.0/TimeSpan.d.ts +0 -34
  157. package/dist/fable_modules/fable-library.4.5.0/TimeSpan.js +0 -177
  158. package/dist/fable_modules/fable-library.4.5.0/Timer.d.ts +0 -19
  159. package/dist/fable_modules/fable-library.4.5.0/Timer.js +0 -67
  160. package/dist/fable_modules/fable-library.4.5.0/Types.d.ts +0 -58
  161. package/dist/fable_modules/fable-library.4.5.0/Types.js +0 -208
  162. package/dist/fable_modules/fable-library.4.5.0/Unicode.13.0.0.d.ts +0 -2
  163. package/dist/fable_modules/fable-library.4.5.0/Unicode.13.0.0.js +0 -4
  164. package/dist/fable_modules/fable-library.4.5.0/Uri.d.ts +0 -29
  165. package/dist/fable_modules/fable-library.4.5.0/Uri.js +0 -142
  166. package/dist/fable_modules/fable-library.4.5.0/Util.d.ts +0 -207
  167. package/dist/fable_modules/fable-library.4.5.0/Util.js +0 -781
  168. package/dist/fable_modules/fable-library.4.5.0/lib/big.d.ts +0 -5
  169. package/dist/fable_modules/fable-library.4.5.0/lib/big.js +0 -826
  170. package/dist/fable_modules/fable-library.4.5.0/package.json +0 -23
  171. package/dist/fable_modules/project_cracked.json +0 -1
@@ -1,781 +0,0 @@
1
- // tslint:disable:ban-types
2
- export function isArrayLike(x) {
3
- return Array.isArray(x) || ArrayBuffer.isView(x);
4
- }
5
- export function isIterable(x) {
6
- return x != null && typeof x === "object" && Symbol.iterator in x;
7
- }
8
- export function isEnumerable(x) {
9
- return x != null && typeof x.GetEnumerator === "function";
10
- }
11
- export function isComparer(x) {
12
- return x != null && typeof x.Compare === "function";
13
- }
14
- export function isComparable(x) {
15
- return x != null && typeof x.CompareTo === "function";
16
- }
17
- export function isEquatable(x) {
18
- return x != null && typeof x.Equals === "function";
19
- }
20
- export function isHashable(x) {
21
- return x != null && typeof x.GetHashCode === "function";
22
- }
23
- export function isDisposable(x) {
24
- return x != null && typeof x.Dispose === "function";
25
- }
26
- export function disposeSafe(x) {
27
- if (isDisposable(x)) {
28
- x.Dispose();
29
- }
30
- }
31
- export function defaultOf() {
32
- return null;
33
- }
34
- export function sameConstructor(x, y) {
35
- return Object.getPrototypeOf(x)?.constructor === Object.getPrototypeOf(y)?.constructor;
36
- }
37
- export class Enumerable {
38
- constructor(en) {
39
- this.en = en;
40
- }
41
- GetEnumerator() { return this.en; }
42
- "System.Collections.IEnumerable.GetEnumerator"() { return this.en; }
43
- [Symbol.iterator]() {
44
- return this;
45
- }
46
- next() {
47
- const hasNext = this.en["System.Collections.IEnumerator.MoveNext"]();
48
- const current = hasNext ? this.en["System.Collections.Generic.IEnumerator`1.get_Current"]() : undefined;
49
- return { done: !hasNext, value: current };
50
- }
51
- }
52
- export class Enumerator {
53
- constructor(iter) {
54
- this.iter = iter;
55
- this.current = defaultOf();
56
- }
57
- ["System.Collections.Generic.IEnumerator`1.get_Current"]() {
58
- return this.current;
59
- }
60
- ["System.Collections.IEnumerator.get_Current"]() {
61
- return this.current;
62
- }
63
- ["System.Collections.IEnumerator.MoveNext"]() {
64
- const cur = this.iter.next();
65
- this.current = cur.value;
66
- return !cur.done;
67
- }
68
- ["System.Collections.IEnumerator.Reset"]() {
69
- throw new Error("JS iterators cannot be reset");
70
- }
71
- Dispose() {
72
- return;
73
- }
74
- }
75
- export function toEnumerable(e) {
76
- if (isEnumerable(e)) {
77
- return e;
78
- }
79
- else {
80
- return new Enumerable(new Enumerator(e[Symbol.iterator]()));
81
- }
82
- }
83
- export function getEnumerator(e) {
84
- if (isEnumerable(e)) {
85
- return e.GetEnumerator();
86
- }
87
- else {
88
- return new Enumerator(e[Symbol.iterator]());
89
- }
90
- }
91
- export function toIterator(en) {
92
- return {
93
- next() {
94
- const hasNext = en["System.Collections.IEnumerator.MoveNext"]();
95
- const current = hasNext ? en["System.Collections.Generic.IEnumerator`1.get_Current"]() : undefined;
96
- return { done: !hasNext, value: current };
97
- },
98
- };
99
- }
100
- export function enumerableToIterator(e) {
101
- return toIterator(toEnumerable(e).GetEnumerator());
102
- }
103
- export class Comparer {
104
- constructor(f) {
105
- this.Compare = f || compare;
106
- }
107
- }
108
- export function comparerFromEqualityComparer(comparer) {
109
- // Sometimes IEqualityComparer also implements IComparer
110
- if (isComparer(comparer)) {
111
- return new Comparer(comparer.Compare);
112
- }
113
- else {
114
- return new Comparer((x, y) => {
115
- const xhash = comparer.GetHashCode(x);
116
- const yhash = comparer.GetHashCode(y);
117
- if (xhash === yhash) {
118
- return comparer.Equals(x, y) ? 0 : -1;
119
- }
120
- else {
121
- return xhash < yhash ? -1 : 1;
122
- }
123
- });
124
- }
125
- }
126
- export function assertEqual(actual, expected, msg) {
127
- if (!equals(actual, expected)) {
128
- throw Object.assign(new Error(msg || `Expected: ${expected} - Actual: ${actual}`), {
129
- actual,
130
- expected,
131
- });
132
- }
133
- }
134
- export function assertNotEqual(actual, expected, msg) {
135
- if (equals(actual, expected)) {
136
- throw Object.assign(new Error(msg || `Expected: ${expected} - Actual: ${actual}`), {
137
- actual,
138
- expected,
139
- });
140
- }
141
- }
142
- export class Lazy {
143
- constructor(factory) {
144
- this.factory = factory;
145
- this.isValueCreated = false;
146
- }
147
- get Value() {
148
- if (!this.isValueCreated) {
149
- this.createdValue = this.factory();
150
- this.isValueCreated = true;
151
- }
152
- return this.createdValue;
153
- }
154
- get IsValueCreated() {
155
- return this.isValueCreated;
156
- }
157
- }
158
- export function lazyFromValue(v) {
159
- return new Lazy(() => v);
160
- }
161
- export function padWithZeros(i, length) {
162
- let str = i.toString(10);
163
- while (str.length < length) {
164
- str = "0" + str;
165
- }
166
- return str;
167
- }
168
- export function padLeftAndRightWithZeros(i, lengthLeft, lengthRight) {
169
- let str = i.toString(10);
170
- while (str.length < lengthLeft) {
171
- str = "0" + str;
172
- }
173
- while (str.length < lengthRight) {
174
- str = str + "0";
175
- }
176
- return str;
177
- }
178
- export function dateOffset(date) {
179
- const date1 = date;
180
- return typeof date1.offset === "number"
181
- ? date1.offset
182
- : (date.kind === 1 /* DateKind.UTC */
183
- ? 0 : date.getTimezoneOffset() * -60000);
184
- }
185
- export function int16ToString(i, radix) {
186
- i = i < 0 && radix != null && radix !== 10 ? 0xFFFF + i + 1 : i;
187
- return i.toString(radix);
188
- }
189
- export function int32ToString(i, radix) {
190
- i = i < 0 && radix != null && radix !== 10 ? 0xFFFFFFFF + i + 1 : i;
191
- return i.toString(radix);
192
- }
193
- export function int64ToString(i, radix) {
194
- i = i < 0 && radix != null && radix !== 10 ? 0xffffffffffffffffn + i + 1n : i;
195
- return i.toString(radix);
196
- }
197
- export class ObjectRef {
198
- static id(o) {
199
- if (!ObjectRef.idMap.has(o)) {
200
- ObjectRef.idMap.set(o, ++ObjectRef.count);
201
- }
202
- return ObjectRef.idMap.get(o);
203
- }
204
- }
205
- ObjectRef.idMap = new WeakMap();
206
- ObjectRef.count = 0;
207
- export function stringHash(s) {
208
- let i = 0;
209
- let h = 5381;
210
- const len = s.length;
211
- while (i < len) {
212
- h = (h * 33) ^ s.charCodeAt(i++);
213
- }
214
- return h;
215
- }
216
- export function numberHash(x) {
217
- return x * 2654435761 | 0;
218
- }
219
- export function bigintHash(x) {
220
- return stringHash(x.toString(32));
221
- }
222
- // From https://stackoverflow.com/a/37449594
223
- export function combineHashCodes(hashes) {
224
- let h1 = 0;
225
- const len = hashes.length;
226
- for (let i = 0; i < len; i++) {
227
- const h2 = hashes[i];
228
- h1 = ((h1 << 5) + h1) ^ h2;
229
- }
230
- return h1;
231
- }
232
- export function physicalHash(x) {
233
- if (x == null) {
234
- return 0;
235
- }
236
- switch (typeof x) {
237
- case "boolean":
238
- return x ? 1 : 0;
239
- case "number":
240
- return numberHash(x);
241
- case "bigint":
242
- return bigintHash(x);
243
- case "string":
244
- return stringHash(x);
245
- default:
246
- return numberHash(ObjectRef.id(x));
247
- }
248
- }
249
- export function identityHash(x) {
250
- if (isHashable(x)) {
251
- return x.GetHashCode();
252
- }
253
- else {
254
- return physicalHash(x);
255
- }
256
- }
257
- export function dateHash(x) {
258
- return x.getTime();
259
- }
260
- export function arrayHash(x) {
261
- const len = x.length;
262
- const hashes = new Array(len);
263
- for (let i = 0; i < len; i++) {
264
- hashes[i] = structuralHash(x[i]);
265
- }
266
- return combineHashCodes(hashes);
267
- }
268
- export function structuralHash(x) {
269
- if (x == null) {
270
- return 0;
271
- }
272
- switch (typeof x) {
273
- case "boolean":
274
- return x ? 1 : 0;
275
- case "number":
276
- return numberHash(x);
277
- case "bigint":
278
- return bigintHash(x);
279
- case "string":
280
- return stringHash(x);
281
- default: {
282
- if (isHashable(x)) {
283
- return x.GetHashCode();
284
- }
285
- else if (isArrayLike(x)) {
286
- return arrayHash(x);
287
- }
288
- else if (x instanceof Date) {
289
- return dateHash(x);
290
- }
291
- else if (Object.getPrototypeOf(x)?.constructor === Object) {
292
- // TODO: check call-stack to prevent cyclic objects?
293
- const hashes = Object.values(x).map((v) => structuralHash(v));
294
- return combineHashCodes(hashes);
295
- }
296
- else {
297
- // Classes don't implement GetHashCode by default, but must use identity hashing
298
- return numberHash(ObjectRef.id(x));
299
- // return stringHash(String(x));
300
- }
301
- }
302
- }
303
- }
304
- // Intended for custom numeric types, like long or decimal
305
- export function fastStructuralHash(x) {
306
- return stringHash(String(x));
307
- }
308
- // Intended for declared types that may or may not implement GetHashCode
309
- export function safeHash(x) {
310
- // return x == null ? 0 : isHashable(x) ? x.GetHashCode() : numberHash(ObjectRef.id(x));
311
- return identityHash(x);
312
- }
313
- export function equalArraysWith(x, y, eq) {
314
- if (x == null) {
315
- return y == null;
316
- }
317
- if (y == null) {
318
- return false;
319
- }
320
- if (x.length !== y.length) {
321
- return false;
322
- }
323
- for (let i = 0; i < x.length; i++) {
324
- if (!eq(x[i], y[i])) {
325
- return false;
326
- }
327
- }
328
- return true;
329
- }
330
- export function equalArrays(x, y) {
331
- return equalArraysWith(x, y, equals);
332
- }
333
- function equalObjects(x, y) {
334
- const xKeys = Object.keys(x);
335
- const yKeys = Object.keys(y);
336
- if (xKeys.length !== yKeys.length) {
337
- return false;
338
- }
339
- xKeys.sort();
340
- yKeys.sort();
341
- for (let i = 0; i < xKeys.length; i++) {
342
- if (xKeys[i] !== yKeys[i] || !equals(x[xKeys[i]], y[yKeys[i]])) {
343
- return false;
344
- }
345
- }
346
- return true;
347
- }
348
- export function physicalEquality(x, y) {
349
- return x === y;
350
- }
351
- export function equals(x, y) {
352
- if (x === y) {
353
- return true;
354
- }
355
- else if (x == null) {
356
- return y == null;
357
- }
358
- else if (y == null) {
359
- return false;
360
- }
361
- else if (isEquatable(x)) {
362
- return x.Equals(y);
363
- }
364
- else if (isArrayLike(x)) {
365
- return isArrayLike(y) && equalArrays(x, y);
366
- }
367
- else if (typeof x !== "object") {
368
- return false;
369
- }
370
- else if (x instanceof Date) {
371
- return (y instanceof Date) && compareDates(x, y) === 0;
372
- }
373
- else {
374
- return Object.getPrototypeOf(x)?.constructor === Object && equalObjects(x, y);
375
- }
376
- }
377
- export function compareDates(x, y) {
378
- let xtime;
379
- let ytime;
380
- // DateTimeOffset and DateTime deals with equality differently.
381
- if ("offset" in x && "offset" in y) {
382
- xtime = x.getTime();
383
- ytime = y.getTime();
384
- }
385
- else {
386
- xtime = x.getTime() + dateOffset(x);
387
- ytime = y.getTime() + dateOffset(y);
388
- }
389
- return xtime === ytime ? 0 : (xtime < ytime ? -1 : 1);
390
- }
391
- export function comparePrimitives(x, y) {
392
- return x === y ? 0 : (x < y ? -1 : 1);
393
- }
394
- export function compareArraysWith(x, y, comp) {
395
- if (x == null) {
396
- return y == null ? 0 : 1;
397
- }
398
- if (y == null) {
399
- return -1;
400
- }
401
- if (x.length !== y.length) {
402
- return x.length < y.length ? -1 : 1;
403
- }
404
- for (let i = 0, j = 0; i < x.length; i++) {
405
- j = comp(x[i], y[i]);
406
- if (j !== 0) {
407
- return j;
408
- }
409
- }
410
- return 0;
411
- }
412
- export function compareArrays(x, y) {
413
- return compareArraysWith(x, y, compare);
414
- }
415
- function compareObjects(x, y) {
416
- const xKeys = Object.keys(x);
417
- const yKeys = Object.keys(y);
418
- if (xKeys.length !== yKeys.length) {
419
- return xKeys.length < yKeys.length ? -1 : 1;
420
- }
421
- xKeys.sort();
422
- yKeys.sort();
423
- for (let i = 0, j = 0; i < xKeys.length; i++) {
424
- const key = xKeys[i];
425
- if (key !== yKeys[i]) {
426
- return key < yKeys[i] ? -1 : 1;
427
- }
428
- else {
429
- j = compare(x[key], y[key]);
430
- if (j !== 0) {
431
- return j;
432
- }
433
- }
434
- }
435
- return 0;
436
- }
437
- export function compare(x, y) {
438
- if (x === y) {
439
- return 0;
440
- }
441
- else if (x == null) {
442
- return y == null ? 0 : -1;
443
- }
444
- else if (y == null) {
445
- return 1;
446
- }
447
- else if (isComparable(x)) {
448
- return x.CompareTo(y);
449
- }
450
- else if (isArrayLike(x)) {
451
- return isArrayLike(y) ? compareArrays(x, y) : -1;
452
- }
453
- else if (typeof x !== "object") {
454
- return x < y ? -1 : 1;
455
- }
456
- else if (x instanceof Date) {
457
- return y instanceof Date ? compareDates(x, y) : -1;
458
- }
459
- else {
460
- return Object.getPrototypeOf(x)?.constructor === Object ? compareObjects(x, y) : -1;
461
- }
462
- }
463
- export function min(comparer, x, y) {
464
- return comparer(x, y) < 0 ? x : y;
465
- }
466
- export function max(comparer, x, y) {
467
- return comparer(x, y) > 0 ? x : y;
468
- }
469
- export function clamp(comparer, value, min, max) {
470
- return (comparer(value, min) < 0) ? min : (comparer(value, max) > 0) ? max : value;
471
- }
472
- export function createAtom(value) {
473
- let atom = value;
474
- return (...args) => {
475
- if (args.length === 0) {
476
- return atom;
477
- }
478
- else {
479
- atom = args[0];
480
- }
481
- };
482
- }
483
- export function createObj(fields) {
484
- const obj = {};
485
- for (const kv of fields) {
486
- obj[kv[0]] = kv[1];
487
- }
488
- return obj;
489
- }
490
- export function jsOptions(mutator) {
491
- const opts = {};
492
- mutator(opts);
493
- return opts;
494
- }
495
- export function round(value, digits = 0) {
496
- const m = Math.pow(10, digits);
497
- const n = +(digits ? value * m : value).toFixed(8);
498
- const i = Math.floor(n);
499
- const f = n - i;
500
- const e = 1e-8;
501
- const r = (f > 0.5 - e && f < 0.5 + e) ? ((i % 2 === 0) ? i : i + 1) : Math.round(n);
502
- return digits ? r / m : r;
503
- }
504
- export function sign(x) {
505
- return x > 0 ? 1 : x < 0 ? -1 : 0;
506
- }
507
- export function unescapeDataString(s) {
508
- // https://stackoverflow.com/a/4458580/524236
509
- return decodeURIComponent((s).replace(/\+/g, "%20"));
510
- }
511
- export function escapeDataString(s) {
512
- return encodeURIComponent(s).replace(/!/g, "%21")
513
- .replace(/'/g, "%27")
514
- .replace(/\(/g, "%28")
515
- .replace(/\)/g, "%29")
516
- .replace(/\*/g, "%2A");
517
- }
518
- export function escapeUriString(s) {
519
- return encodeURI(s);
520
- }
521
- // ICollection.Clear and Count members can be called on Arrays
522
- // or Dictionaries so we need a runtime check (see #1120)
523
- export function count(col) {
524
- if (isArrayLike(col)) {
525
- return col.length;
526
- }
527
- else {
528
- let count = 0;
529
- for (const _ of col) {
530
- count++;
531
- }
532
- return count;
533
- }
534
- }
535
- export function clear(col) {
536
- if (isArrayLike(col)) {
537
- col.splice(0);
538
- }
539
- else {
540
- col.clear();
541
- }
542
- }
543
- const curried = new WeakMap();
544
- export function uncurry2(f) {
545
- if (f == null) {
546
- return null;
547
- }
548
- const f2 = (a1, a2) => f(a1)(a2);
549
- curried.set(f2, f);
550
- return f2;
551
- }
552
- export function curry2(f) {
553
- return curried.get(f) ?? ((a1) => (a2) => f(a1, a2));
554
- }
555
- export function uncurry3(f) {
556
- if (f == null) {
557
- return null;
558
- }
559
- const f2 = (a1, a2, a3) => f(a1)(a2)(a3);
560
- curried.set(f2, f);
561
- return f2;
562
- }
563
- export function curry3(f) {
564
- return curried.get(f)
565
- ?? ((a1) => (a2) => (a3) => f(a1, a2, a3));
566
- }
567
- export function uncurry4(f) {
568
- if (f == null) {
569
- return null;
570
- }
571
- const f2 = (a1, a2, a3, a4) => f(a1)(a2)(a3)(a4);
572
- curried.set(f2, f);
573
- return f2;
574
- }
575
- export function curry4(f) {
576
- return curried.get(f)
577
- ?? ((a1) => (a2) => (a3) => (a4) => f(a1, a2, a3, a4));
578
- }
579
- export function uncurry5(f) {
580
- if (f == null) {
581
- return null;
582
- }
583
- const f2 = (a1, a2, a3, a4, a5) => f(a1)(a2)(a3)(a4)(a5);
584
- curried.set(f2, f);
585
- return f2;
586
- }
587
- export function curry5(f) {
588
- return curried.get(f)
589
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => f(a1, a2, a3, a4, a5));
590
- }
591
- export function uncurry6(f) {
592
- if (f == null) {
593
- return null;
594
- }
595
- const f2 = (a1, a2, a3, a4, a5, a6) => f(a1)(a2)(a3)(a4)(a5)(a6);
596
- curried.set(f2, f);
597
- return f2;
598
- }
599
- export function curry6(f) {
600
- return curried.get(f)
601
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => f(a1, a2, a3, a4, a5, a6));
602
- }
603
- export function uncurry7(f) {
604
- if (f == null) {
605
- return null;
606
- }
607
- const f2 = (a1, a2, a3, a4, a5, a6, a7) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7);
608
- curried.set(f2, f);
609
- return f2;
610
- }
611
- export function curry7(f) {
612
- return curried.get(f)
613
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => f(a1, a2, a3, a4, a5, a6, a7));
614
- }
615
- export function uncurry8(f) {
616
- if (f == null) {
617
- return null;
618
- }
619
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8);
620
- curried.set(f2, f);
621
- return f2;
622
- }
623
- export function curry8(f) {
624
- return curried.get(f)
625
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => f(a1, a2, a3, a4, a5, a6, a7, a8));
626
- }
627
- export function uncurry9(f) {
628
- if (f == null) {
629
- return null;
630
- }
631
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9);
632
- curried.set(f2, f);
633
- return f2;
634
- }
635
- export function curry9(f) {
636
- return curried.get(f)
637
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9));
638
- }
639
- export function uncurry10(f) {
640
- if (f == null) {
641
- return null;
642
- }
643
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10);
644
- curried.set(f2, f);
645
- return f2;
646
- }
647
- export function curry10(f) {
648
- return curried.get(f)
649
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10));
650
- }
651
- export function uncurry11(f) {
652
- if (f == null) {
653
- return null;
654
- }
655
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11);
656
- curried.set(f2, f);
657
- return f2;
658
- }
659
- export function curry11(f) {
660
- return curried.get(f)
661
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11));
662
- }
663
- export function uncurry12(f) {
664
- if (f == null) {
665
- return null;
666
- }
667
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12);
668
- curried.set(f2, f);
669
- return f2;
670
- }
671
- export function curry12(f) {
672
- return curried.get(f)
673
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => (a12) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12));
674
- }
675
- export function uncurry13(f) {
676
- if (f == null) {
677
- return null;
678
- }
679
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13);
680
- curried.set(f2, f);
681
- return f2;
682
- }
683
- export function curry13(f) {
684
- return curried.get(f)
685
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => (a12) => (a13) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13));
686
- }
687
- export function uncurry14(f) {
688
- if (f == null) {
689
- return null;
690
- }
691
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14);
692
- curried.set(f2, f);
693
- return f2;
694
- }
695
- export function curry14(f) {
696
- return curried.get(f)
697
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => (a12) => (a13) => (a14) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14));
698
- }
699
- export function uncurry15(f) {
700
- if (f == null) {
701
- return null;
702
- }
703
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15);
704
- curried.set(f2, f);
705
- return f2;
706
- }
707
- export function curry15(f) {
708
- return curried.get(f)
709
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => (a12) => (a13) => (a14) => (a15) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15));
710
- }
711
- export function uncurry16(f) {
712
- if (f == null) {
713
- return null;
714
- }
715
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16);
716
- curried.set(f2, f);
717
- return f2;
718
- }
719
- export function curry16(f) {
720
- return curried.get(f)
721
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => (a12) => (a13) => (a14) => (a15) => (a16) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16));
722
- }
723
- export function uncurry17(f) {
724
- if (f == null) {
725
- return null;
726
- }
727
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17);
728
- curried.set(f2, f);
729
- return f2;
730
- }
731
- export function curry17(f) {
732
- return curried.get(f)
733
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => (a12) => (a13) => (a14) => (a15) => (a16) => (a17) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17));
734
- }
735
- export function uncurry18(f) {
736
- if (f == null) {
737
- return null;
738
- }
739
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18);
740
- curried.set(f2, f);
741
- return f2;
742
- }
743
- export function curry18(f) {
744
- return curried.get(f)
745
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => (a12) => (a13) => (a14) => (a15) => (a16) => (a17) => (a18) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18));
746
- }
747
- export function uncurry19(f) {
748
- if (f == null) {
749
- return null;
750
- }
751
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19);
752
- curried.set(f2, f);
753
- return f2;
754
- }
755
- export function curry19(f) {
756
- return curried.get(f)
757
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => (a12) => (a13) => (a14) => (a15) => (a16) => (a17) => (a18) => (a19) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19));
758
- }
759
- export function uncurry20(f) {
760
- if (f == null) {
761
- return null;
762
- }
763
- const f2 = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19)(a20);
764
- curried.set(f2, f);
765
- return f2;
766
- }
767
- export function curry20(f) {
768
- return curried.get(f)
769
- ?? ((a1) => (a2) => (a3) => (a4) => (a5) => (a6) => (a7) => (a8) => (a9) => (a10) => (a11) => (a12) => (a13) => (a14) => (a15) => (a16) => (a17) => (a18) => (a19) => (a20) => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20));
770
- }
771
- // More performant method to copy arrays, see #2352
772
- export function copyToArray(source, sourceIndex, target, targetIndex, count) {
773
- if (ArrayBuffer.isView(source) && ArrayBuffer.isView(target)) {
774
- target.set(source.subarray(sourceIndex, sourceIndex + count), targetIndex);
775
- }
776
- else {
777
- for (let i = 0; i < count; ++i) {
778
- target[targetIndex + i] = source[sourceIndex + i];
779
- }
780
- }
781
- }