compostjs 0.0.8 → 0.0.12

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 (141) hide show
  1. package/README.md +4 -4
  2. package/dist/fable_modules/fable-library-js.4.28.0/Array.d.ts +123 -0
  3. package/dist/fable_modules/fable-library-js.4.28.0/Array.js +1242 -0
  4. package/dist/fable_modules/fable-library-js.4.28.0/Async.d.ts +26 -0
  5. package/dist/fable_modules/fable-library-js.4.28.0/Async.js +145 -0
  6. package/dist/fable_modules/fable-library-js.4.28.0/AsyncBuilder.d.ts +59 -0
  7. package/dist/fable_modules/fable-library-js.4.28.0/AsyncBuilder.js +183 -0
  8. package/dist/fable_modules/fable-library-js.4.28.0/BigInt.d.ts +115 -0
  9. package/dist/fable_modules/fable-library-js.4.28.0/BigInt.js +283 -0
  10. package/dist/fable_modules/fable-library-js.4.28.0/BitConverter.d.ts +27 -0
  11. package/dist/fable_modules/fable-library-js.4.28.0/BitConverter.js +138 -0
  12. package/dist/fable_modules/fable-library-js.4.28.0/Boolean.d.ts +3 -0
  13. package/dist/fable_modules/fable-library-js.4.28.0/Boolean.js +21 -0
  14. package/dist/fable_modules/fable-library-js.4.28.0/CHANGELOG.md +100 -0
  15. package/dist/fable_modules/fable-library-js.4.28.0/Char.d.ts +65 -0
  16. package/dist/fable_modules/fable-library-js.4.28.0/Char.js +169 -0
  17. package/dist/fable_modules/fable-library-js.4.28.0/Choice.d.ts +121 -0
  18. package/dist/fable_modules/fable-library-js.4.28.0/Choice.js +184 -0
  19. package/dist/fable_modules/fable-library-js.4.28.0/CollectionUtil.d.ts +7 -0
  20. package/dist/fable_modules/fable-library-js.4.28.0/CollectionUtil.js +182 -0
  21. package/dist/fable_modules/fable-library-js.4.28.0/ConditionalWeakTable.d.ts +9 -0
  22. package/dist/fable_modules/fable-library-js.4.28.0/ConditionalWeakTable.js +21 -0
  23. package/dist/fable_modules/fable-library-js.4.28.0/Date.d.ts +70 -0
  24. package/dist/fable_modules/fable-library-js.4.28.0/Date.js +748 -0
  25. package/dist/fable_modules/fable-library-js.4.28.0/DateOffset.d.ts +63 -0
  26. package/dist/fable_modules/fable-library-js.4.28.0/DateOffset.js +268 -0
  27. package/dist/fable_modules/fable-library-js.4.28.0/DateOnly.d.ts +18 -0
  28. package/dist/fable_modules/fable-library-js.4.28.0/DateOnly.js +124 -0
  29. package/dist/fable_modules/fable-library-js.4.28.0/Decimal.d.ts +45 -0
  30. package/dist/fable_modules/fable-library-js.4.28.0/Decimal.js +212 -0
  31. package/dist/fable_modules/fable-library-js.4.28.0/Double.d.ts +11 -0
  32. package/dist/fable_modules/fable-library-js.4.28.0/Double.js +46 -0
  33. package/dist/fable_modules/fable-library-js.4.28.0/Encoding.d.ts +12 -0
  34. package/dist/fable_modules/fable-library-js.4.28.0/Encoding.js +173 -0
  35. package/dist/fable_modules/fable-library-js.4.28.0/Event.d.ts +31 -0
  36. package/dist/fable_modules/fable-library-js.4.28.0/Event.js +93 -0
  37. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Collections.d.ts +7 -0
  38. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Collections.js +27 -0
  39. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.CompilerServices.d.ts +12 -0
  40. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.CompilerServices.js +27 -0
  41. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.d.ts +17 -0
  42. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.js +69 -0
  43. package/dist/fable_modules/fable-library-js.4.28.0/Global.d.ts +24 -0
  44. package/dist/fable_modules/fable-library-js.4.28.0/Global.js +8 -0
  45. package/dist/fable_modules/fable-library-js.4.28.0/Guid.d.ts +10 -0
  46. package/dist/fable_modules/fable-library-js.4.28.0/Guid.js +142 -0
  47. package/dist/fable_modules/fable-library-js.4.28.0/Int32.d.ts +28 -0
  48. package/dist/fable_modules/fable-library-js.4.28.0/Int32.js +135 -0
  49. package/dist/fable_modules/fable-library-js.4.28.0/List.d.ts +143 -0
  50. package/dist/fable_modules/fable-library-js.4.28.0/List.js +1273 -0
  51. package/dist/fable_modules/fable-library-js.4.28.0/Long.d.ts +3 -0
  52. package/dist/fable_modules/fable-library-js.4.28.0/Long.js +46 -0
  53. package/dist/fable_modules/fable-library-js.4.28.0/MailboxProcessor.d.ts +25 -0
  54. package/dist/fable_modules/fable-library-js.4.28.0/MailboxProcessor.js +93 -0
  55. package/dist/fable_modules/fable-library-js.4.28.0/Map.d.ts +178 -0
  56. package/dist/fable_modules/fable-library-js.4.28.0/Map.js +1396 -0
  57. package/dist/fable_modules/fable-library-js.4.28.0/MapUtil.d.ts +12 -0
  58. package/dist/fable_modules/fable-library-js.4.28.0/MapUtil.js +127 -0
  59. package/dist/fable_modules/fable-library-js.4.28.0/MutableMap.d.ts +52 -0
  60. package/dist/fable_modules/fable-library-js.4.28.0/MutableMap.js +327 -0
  61. package/dist/fable_modules/fable-library-js.4.28.0/MutableSet.d.ts +39 -0
  62. package/dist/fable_modules/fable-library-js.4.28.0/MutableSet.js +233 -0
  63. package/dist/fable_modules/fable-library-js.4.28.0/Native.d.ts +2 -0
  64. package/dist/fable_modules/fable-library-js.4.28.0/Native.js +8 -0
  65. package/dist/fable_modules/fable-library-js.4.28.0/Numeric.d.ts +19 -0
  66. package/dist/fable_modules/fable-library-js.4.28.0/Numeric.js +71 -0
  67. package/dist/fable_modules/fable-library-js.4.28.0/Observable.d.ts +32 -0
  68. package/dist/fable_modules/fable-library-js.4.28.0/Observable.js +113 -0
  69. package/dist/fable_modules/fable-library-js.4.28.0/Option.d.ts +28 -0
  70. package/dist/fable_modules/fable-library-js.4.28.0/Option.js +96 -0
  71. package/dist/fable_modules/fable-library-js.4.28.0/README.md +3 -0
  72. package/dist/fable_modules/fable-library-js.4.28.0/Random.d.ts +37 -0
  73. package/dist/fable_modules/fable-library-js.4.28.0/Random.js +170 -0
  74. package/dist/fable_modules/fable-library-js.4.28.0/Range.d.ts +12 -0
  75. package/dist/fable_modules/fable-library-js.4.28.0/Range.js +45 -0
  76. package/dist/fable_modules/fable-library-js.4.28.0/Reflection.d.ts +119 -0
  77. package/dist/fable_modules/fable-library-js.4.28.0/Reflection.js +461 -0
  78. package/dist/fable_modules/fable-library-js.4.28.0/RegExp.d.ts +10 -0
  79. package/dist/fable_modules/fable-library-js.4.28.0/RegExp.js +131 -0
  80. package/dist/fable_modules/fable-library-js.4.28.0/Result.d.ts +37 -0
  81. package/dist/fable_modules/fable-library-js.4.28.0/Result.js +165 -0
  82. package/dist/fable_modules/fable-library-js.4.28.0/Seq.d.ts +165 -0
  83. package/dist/fable_modules/fable-library-js.4.28.0/Seq.js +1378 -0
  84. package/dist/fable_modules/fable-library-js.4.28.0/Seq2.d.ts +18 -0
  85. package/dist/fable_modules/fable-library-js.4.28.0/Seq2.js +111 -0
  86. package/dist/fable_modules/fable-library-js.4.28.0/Set.d.ts +190 -0
  87. package/dist/fable_modules/fable-library-js.4.28.0/Set.js +1789 -0
  88. package/dist/fable_modules/fable-library-js.4.28.0/String.d.ts +58 -0
  89. package/dist/fable_modules/fable-library-js.4.28.0/String.js +554 -0
  90. package/dist/fable_modules/fable-library-js.4.28.0/System.Collections.Generic.d.ts +79 -0
  91. package/dist/fable_modules/fable-library-js.4.28.0/System.Collections.Generic.js +317 -0
  92. package/dist/fable_modules/fable-library-js.4.28.0/System.Text.d.ts +38 -0
  93. package/dist/fable_modules/fable-library-js.4.28.0/System.Text.js +162 -0
  94. package/dist/fable_modules/fable-library-js.4.28.0/SystemException.d.ts +5 -0
  95. package/dist/fable_modules/fable-library-js.4.28.0/SystemException.js +5 -0
  96. package/dist/fable_modules/fable-library-js.4.28.0/TimeOnly.d.ts +15 -0
  97. package/dist/fable_modules/fable-library-js.4.28.0/TimeOnly.js +122 -0
  98. package/dist/fable_modules/fable-library-js.4.28.0/TimeSpan.d.ts +34 -0
  99. package/dist/fable_modules/fable-library-js.4.28.0/TimeSpan.js +177 -0
  100. package/dist/fable_modules/fable-library-js.4.28.0/Timer.d.ts +19 -0
  101. package/dist/fable_modules/fable-library-js.4.28.0/Timer.js +67 -0
  102. package/dist/fable_modules/fable-library-js.4.28.0/Types.d.ts +58 -0
  103. package/dist/fable_modules/fable-library-js.4.28.0/Types.js +208 -0
  104. package/dist/fable_modules/fable-library-js.4.28.0/Unicode.13.0.0.d.ts +2 -0
  105. package/dist/fable_modules/fable-library-js.4.28.0/Unicode.13.0.0.js +4 -0
  106. package/dist/fable_modules/fable-library-js.4.28.0/Uri.d.ts +31 -0
  107. package/dist/fable_modules/fable-library-js.4.28.0/Uri.js +159 -0
  108. package/dist/fable_modules/fable-library-js.4.28.0/Util.d.ts +210 -0
  109. package/dist/fable_modules/fable-library-js.4.28.0/Util.js +769 -0
  110. package/dist/fable_modules/fable-library-js.4.28.0/big.d.ts +338 -0
  111. package/dist/fable_modules/fable-library-js.4.28.0/lib/big.d.ts +5 -0
  112. package/dist/fable_modules/fable-library-js.4.28.0/lib/big.js +825 -0
  113. package/dist/fable_modules/fable-library-js.4.28.0/package.json +24 -0
  114. package/dist/fable_modules/project_cracked.json +1 -0
  115. package/package.json +6 -5
  116. package/.claude/settings.local.json +0 -11
  117. package/dist/fable-library.2.10.1/Array.js +0 -1336
  118. package/dist/fable-library.2.10.1/Async.js +0 -121
  119. package/dist/fable-library.2.10.1/AsyncBuilder.js +0 -200
  120. package/dist/fable-library.2.10.1/Date.js +0 -501
  121. package/dist/fable-library.2.10.1/Decimal.js +0 -208
  122. package/dist/fable-library.2.10.1/Event.js +0 -193
  123. package/dist/fable-library.2.10.1/Int32.js +0 -157
  124. package/dist/fable-library.2.10.1/List.js +0 -1234
  125. package/dist/fable-library.2.10.1/Long.js +0 -155
  126. package/dist/fable-library.2.10.1/Map.js +0 -1292
  127. package/dist/fable-library.2.10.1/MutableMap.js +0 -360
  128. package/dist/fable-library.2.10.1/MutableSet.js +0 -279
  129. package/dist/fable-library.2.10.1/Observable.js +0 -131
  130. package/dist/fable-library.2.10.1/Option.js +0 -118
  131. package/dist/fable-library.2.10.1/Reflection.js +0 -345
  132. package/dist/fable-library.2.10.1/RegExp.js +0 -118
  133. package/dist/fable-library.2.10.1/Seq.js +0 -917
  134. package/dist/fable-library.2.10.1/Set.js +0 -1692
  135. package/dist/fable-library.2.10.1/String.js +0 -679
  136. package/dist/fable-library.2.10.1/Types.js +0 -308
  137. package/dist/fable-library.2.10.1/Util.js +0 -761
  138. package/dist/helpers.js +0 -31
  139. package/dist/lib/big.js +0 -905
  140. package/dist/lib/long.js +0 -1375
  141. package/index.html +0 -49
@@ -0,0 +1,461 @@
1
+ import { Record, Union } from "./Types.js";
2
+ import { combineHashCodes, equalArraysWith, stringHash } from "./Util.js";
3
+ import Decimal from "./Decimal.js";
4
+ export class CaseInfo {
5
+ constructor(declaringType, tag, name, fields) {
6
+ this.declaringType = declaringType;
7
+ this.tag = tag;
8
+ this.name = name;
9
+ this.fields = fields;
10
+ }
11
+ }
12
+ export class MethodInfo {
13
+ constructor(name, parameters, returnType) {
14
+ this.name = name;
15
+ this.parameters = parameters;
16
+ this.returnType = returnType;
17
+ }
18
+ }
19
+ export class TypeInfo {
20
+ constructor(fullname, generics, construct, parent, fields, cases, enumCases) {
21
+ this.fullname = fullname;
22
+ this.generics = generics;
23
+ this.construct = construct;
24
+ this.parent = parent;
25
+ this.fields = fields;
26
+ this.cases = cases;
27
+ this.enumCases = enumCases;
28
+ }
29
+ toString() {
30
+ return fullName(this);
31
+ }
32
+ GetHashCode() {
33
+ return getHashCode(this);
34
+ }
35
+ Equals(other) {
36
+ return equals(this, other);
37
+ }
38
+ }
39
+ export class GenericParameter extends TypeInfo {
40
+ constructor(name) {
41
+ super(name);
42
+ }
43
+ }
44
+ export function getGenerics(t) {
45
+ return t.generics != null ? t.generics : [];
46
+ }
47
+ export function getHashCode(t) {
48
+ const fullnameHash = stringHash(t.fullname);
49
+ const genHashes = getGenerics(t).map(getHashCode);
50
+ return combineHashCodes([fullnameHash, ...genHashes]);
51
+ }
52
+ export function equals(t1, t2) {
53
+ if (t1.fullname === "") { // Anonymous records
54
+ return t2.fullname === ""
55
+ && equalArraysWith(getRecordElements(t1), getRecordElements(t2), ([k1, v1], [k2, v2]) => k1 === k2 && equals(v1, v2));
56
+ }
57
+ else {
58
+ return t1.fullname === t2.fullname
59
+ && equalArraysWith(getGenerics(t1), getGenerics(t2), equals);
60
+ }
61
+ }
62
+ export function class_type(fullname, generics, construct, parent) {
63
+ return new TypeInfo(fullname, generics, construct, parent);
64
+ }
65
+ export function record_type(fullname, generics, construct, fields) {
66
+ return new TypeInfo(fullname, generics, construct, undefined, fields);
67
+ }
68
+ export function anonRecord_type(...fields) {
69
+ return new TypeInfo("", undefined, undefined, undefined, () => fields);
70
+ }
71
+ export function union_type(fullname, generics, construct, cases) {
72
+ const t = new TypeInfo(fullname, generics, construct, undefined, undefined, () => {
73
+ const caseNames = construct.prototype.cases();
74
+ return cases().map((fields, i) => new CaseInfo(t, i, caseNames[i], fields));
75
+ });
76
+ return t;
77
+ }
78
+ export function tuple_type(...generics) {
79
+ return new TypeInfo("System.Tuple`" + generics.length, generics);
80
+ }
81
+ export function delegate_type(...generics) {
82
+ return new TypeInfo("System.Func`" + generics.length, generics);
83
+ }
84
+ export function lambda_type(argType, returnType) {
85
+ return new TypeInfo("Microsoft.FSharp.Core.FSharpFunc`2", [argType, returnType]);
86
+ }
87
+ export function option_type(generic) {
88
+ return new TypeInfo("Microsoft.FSharp.Core.FSharpOption`1", [generic]);
89
+ }
90
+ export function list_type(generic) {
91
+ return new TypeInfo("Microsoft.FSharp.Collections.FSharpList`1", [generic]);
92
+ }
93
+ export function array_type(generic) {
94
+ return new TypeInfo("[]", [generic]);
95
+ }
96
+ export function enum_type(fullname, underlyingType, enumCases) {
97
+ return new TypeInfo(fullname, [underlyingType], undefined, undefined, undefined, undefined, enumCases);
98
+ }
99
+ export function measure_type(fullname) {
100
+ return new TypeInfo(fullname);
101
+ }
102
+ export function generic_type(name) {
103
+ return new GenericParameter(name);
104
+ }
105
+ export const obj_type = new TypeInfo("System.Object");
106
+ export const unit_type = new TypeInfo("Microsoft.FSharp.Core.Unit");
107
+ export const char_type = new TypeInfo("System.Char");
108
+ export const string_type = new TypeInfo("System.String");
109
+ export const bool_type = new TypeInfo("System.Boolean");
110
+ export const int8_type = new TypeInfo("System.SByte");
111
+ export const uint8_type = new TypeInfo("System.Byte");
112
+ export const int16_type = new TypeInfo("System.Int16");
113
+ export const uint16_type = new TypeInfo("System.UInt16");
114
+ export const int32_type = new TypeInfo("System.Int32");
115
+ export const uint32_type = new TypeInfo("System.UInt32");
116
+ export const int64_type = new TypeInfo("System.Int64");
117
+ export const uint64_type = new TypeInfo("System.UInt64");
118
+ export const int128_type = new TypeInfo("System.Int128");
119
+ export const uint128_type = new TypeInfo("System.UInt128");
120
+ export const nativeint_type = new TypeInfo("System.IntPtr");
121
+ export const unativeint_type = new TypeInfo("System.UIntPtr");
122
+ export const float16_type = new TypeInfo("System.Half");
123
+ export const float32_type = new TypeInfo("System.Single");
124
+ export const float64_type = new TypeInfo("System.Double");
125
+ export const decimal_type = new TypeInfo("System.Decimal");
126
+ export const bigint_type = new TypeInfo("System.Numerics.BigInteger");
127
+ export function name(info) {
128
+ if (Array.isArray(info)) {
129
+ return info[0];
130
+ }
131
+ else if (info instanceof TypeInfo) {
132
+ const elemType = getElementType(info);
133
+ if (elemType != null) {
134
+ return name(elemType) + "[]";
135
+ }
136
+ else {
137
+ const i = info.fullname.lastIndexOf(".");
138
+ return i === -1 ? info.fullname : info.fullname.substr(i + 1);
139
+ }
140
+ }
141
+ else {
142
+ return info.name;
143
+ }
144
+ }
145
+ export function fullName(t) {
146
+ const elemType = getElementType(t);
147
+ if (elemType != null) {
148
+ return fullName(elemType) + "[]";
149
+ }
150
+ else if (t.generics == null || t.generics.length === 0) {
151
+ return t.fullname;
152
+ }
153
+ else {
154
+ return t.fullname + "[" + t.generics.map((x) => fullName(x)).join(",") + "]";
155
+ }
156
+ }
157
+ export function namespace(t) {
158
+ const elemType = getElementType(t);
159
+ if (elemType != null) {
160
+ return namespace(elemType);
161
+ }
162
+ else {
163
+ const i = t.fullname.lastIndexOf(".");
164
+ return i === -1 ? "" : t.fullname.substr(0, i);
165
+ }
166
+ }
167
+ export function isArray(t) {
168
+ return getElementType(t) != null;
169
+ }
170
+ export function getElementType(t) {
171
+ return t.fullname === "[]" && t.generics?.length === 1 ? t.generics[0] : undefined;
172
+ }
173
+ export function isGenericType(t) {
174
+ return t.generics != null && t.generics.length > 0;
175
+ }
176
+ export function isGenericParameter(t) {
177
+ return t instanceof GenericParameter;
178
+ }
179
+ export function isEnum(t) {
180
+ return t.enumCases != null && t.enumCases.length > 0;
181
+ }
182
+ export function isSubclassOf(t1, t2) {
183
+ return (t2.fullname === obj_type.fullname) || (t1.parent != null && (t1.parent.Equals(t2) || isSubclassOf(t1.parent, t2)));
184
+ }
185
+ function isErasedToNumber(t) {
186
+ return isEnum(t) || [
187
+ int8_type.fullname,
188
+ uint8_type.fullname,
189
+ int16_type.fullname,
190
+ uint16_type.fullname,
191
+ int32_type.fullname,
192
+ uint32_type.fullname,
193
+ float16_type.fullname,
194
+ float32_type.fullname,
195
+ float64_type.fullname,
196
+ ].includes(t.fullname);
197
+ }
198
+ function isErasedToBigInt(t) {
199
+ return isEnum(t) || [
200
+ int64_type.fullname,
201
+ uint64_type.fullname,
202
+ int128_type.fullname,
203
+ uint128_type.fullname,
204
+ nativeint_type.fullname,
205
+ unativeint_type.fullname,
206
+ bigint_type.fullname,
207
+ ].includes(t.fullname);
208
+ }
209
+ export function isInstanceOfType(t, o) {
210
+ if (t.fullname === obj_type.fullname)
211
+ return true;
212
+ switch (typeof o) {
213
+ case "boolean":
214
+ return t.fullname === bool_type.fullname;
215
+ case "string":
216
+ return t.fullname === string_type.fullname;
217
+ case "function":
218
+ return isFunction(t);
219
+ case "number":
220
+ return isErasedToNumber(t);
221
+ case "bigint":
222
+ return isErasedToBigInt(t);
223
+ default:
224
+ return t.construct != null && o instanceof t.construct;
225
+ }
226
+ }
227
+ /**
228
+ * This doesn't replace types for fields (records) or cases (unions)
229
+ * but it should be enough for type comparison purposes
230
+ */
231
+ export function getGenericTypeDefinition(t) {
232
+ return t.generics == null ? t : new TypeInfo(t.fullname, t.generics.map(() => obj_type));
233
+ }
234
+ export function getEnumUnderlyingType(t) {
235
+ return t.generics?.[0];
236
+ }
237
+ export function getEnumValues(t) {
238
+ if (isEnum(t) && t.enumCases != null) {
239
+ return t.enumCases.map((kv) => kv[1]);
240
+ }
241
+ else {
242
+ throw new Error(`${t.fullname} is not an enum type`);
243
+ }
244
+ }
245
+ export function getEnumNames(t) {
246
+ if (isEnum(t) && t.enumCases != null) {
247
+ return t.enumCases.map((kv) => kv[0]);
248
+ }
249
+ else {
250
+ throw new Error(`${t.fullname} is not an enum type`);
251
+ }
252
+ }
253
+ function getEnumCase(t, v) {
254
+ if (t.enumCases != null) {
255
+ if (typeof v === "string") {
256
+ for (const kv of t.enumCases) {
257
+ if (kv[0] === v) {
258
+ return kv;
259
+ }
260
+ }
261
+ throw new Error(`'${v}' was not found in ${t.fullname}`);
262
+ }
263
+ else {
264
+ for (const kv of t.enumCases) {
265
+ if (kv[1] === v) {
266
+ return kv;
267
+ }
268
+ }
269
+ // .NET returns the number even if it doesn't match any of the cases
270
+ return ["", v];
271
+ }
272
+ }
273
+ else {
274
+ throw new Error(`${t.fullname} is not an enum type`);
275
+ }
276
+ }
277
+ export function parseEnum(t, str) {
278
+ // TODO: better int parsing here, parseInt ceils floats: "4.8" -> 4
279
+ const value = parseInt(str, 10);
280
+ return getEnumCase(t, isNaN(value) ? str : value)[1];
281
+ }
282
+ export function tryParseEnum(t, str, defValue) {
283
+ try {
284
+ defValue.contents = parseEnum(t, str);
285
+ return true;
286
+ }
287
+ catch {
288
+ return false;
289
+ }
290
+ }
291
+ export function getEnumName(t, v) {
292
+ return getEnumCase(t, v)[0];
293
+ }
294
+ export function isEnumDefined(t, v) {
295
+ try {
296
+ const kv = getEnumCase(t, v);
297
+ return kv[0] != null && kv[0] !== "";
298
+ }
299
+ catch {
300
+ // supress error
301
+ }
302
+ return false;
303
+ }
304
+ // FSharpType
305
+ export function getUnionCases(t) {
306
+ if (t.cases != null) {
307
+ return t.cases();
308
+ }
309
+ else {
310
+ throw new Error(`${t.fullname} is not an F# union type`);
311
+ }
312
+ }
313
+ export function getRecordElements(t) {
314
+ if (t.fields != null) {
315
+ return t.fields();
316
+ }
317
+ else {
318
+ throw new Error(`${t.fullname} is not an F# record type`);
319
+ }
320
+ }
321
+ export function getTupleElements(t) {
322
+ if (isTuple(t) && t.generics != null) {
323
+ return t.generics;
324
+ }
325
+ else {
326
+ throw new Error(`${t.fullname} is not a tuple type`);
327
+ }
328
+ }
329
+ export function getFunctionElements(t) {
330
+ if (isFunction(t) && t.generics != null) {
331
+ const gen = t.generics;
332
+ return [gen[0], gen[1]];
333
+ }
334
+ else {
335
+ throw new Error(`${t.fullname} is not an F# function type`);
336
+ }
337
+ }
338
+ export function isUnion(t) {
339
+ return t instanceof TypeInfo ? t.cases != null : t instanceof Union;
340
+ }
341
+ export function isRecord(t) {
342
+ return t instanceof TypeInfo ? t.fields != null : t instanceof Record;
343
+ }
344
+ export function isTuple(t) {
345
+ return t.fullname.startsWith("System.Tuple");
346
+ }
347
+ // In .NET this is false for delegates
348
+ export function isFunction(t) {
349
+ return t.fullname === "Microsoft.FSharp.Core.FSharpFunc`2";
350
+ }
351
+ // FSharpValue
352
+ export function getUnionFields(v, t) {
353
+ const cases = getUnionCases(t);
354
+ const case_ = cases[v.tag];
355
+ if (case_ == null) {
356
+ throw new Error(`Cannot find case ${v.name} in union type`);
357
+ }
358
+ return [case_, v.fields];
359
+ }
360
+ export function getUnionCaseFields(uci) {
361
+ return uci.fields == null ? [] : uci.fields;
362
+ }
363
+ // This is used as replacement of `FSharpValue.GetRecordFields`
364
+ // For `FSharpTypes.GetRecordFields` see `getRecordElements`
365
+ // Object.keys returns keys in the order they were added to the object
366
+ export function getRecordFields(v) {
367
+ return Object.keys(v).map((k) => v[k]);
368
+ }
369
+ export function getRecordField(v, field) {
370
+ return v[field[0]];
371
+ }
372
+ export function getTupleFields(v) {
373
+ return v;
374
+ }
375
+ export function getTupleField(v, i) {
376
+ return v[i];
377
+ }
378
+ export function makeUnion(uci, values) {
379
+ const expectedLength = (uci.fields || []).length;
380
+ if (values.length !== expectedLength) {
381
+ throw new Error(`Expected an array of length ${expectedLength} but got ${values.length}`);
382
+ }
383
+ const construct = uci.declaringType.construct;
384
+ if (construct == null) {
385
+ return {};
386
+ }
387
+ const isSingleCase = uci.declaringType.cases ? uci.declaringType.cases().length == 1 : false;
388
+ if (isSingleCase) {
389
+ return new construct(...values);
390
+ }
391
+ else {
392
+ return new construct(uci.tag, values);
393
+ }
394
+ }
395
+ export function makeRecord(t, values) {
396
+ const fields = getRecordElements(t);
397
+ if (fields.length !== values.length) {
398
+ throw new Error(`Expected an array of length ${fields.length} but got ${values.length}`);
399
+ }
400
+ return t.construct != null
401
+ ? new t.construct(...values)
402
+ : fields.reduce((obj, [key, _t], i) => {
403
+ obj[key] = values[i];
404
+ return obj;
405
+ }, {});
406
+ }
407
+ export function makeTuple(values, _t) {
408
+ return values;
409
+ }
410
+ export function makeGenericType(t, generics) {
411
+ return new TypeInfo(t.fullname, generics, t.construct, t.parent, t.fields, t.cases);
412
+ }
413
+ export function createInstance(t, consArgs) {
414
+ // TODO: Check if consArgs length is same as t.construct?
415
+ // (Arg types can still be different)
416
+ if (typeof t.construct === "function") {
417
+ return new t.construct(...(consArgs ?? []));
418
+ }
419
+ else if (isErasedToNumber(t)) {
420
+ return 0;
421
+ }
422
+ else if (isErasedToBigInt(t)) {
423
+ return 0n;
424
+ }
425
+ else {
426
+ switch (t.fullname) {
427
+ case obj_type.fullname:
428
+ return {};
429
+ case bool_type.fullname:
430
+ return false;
431
+ case decimal_type.fullname:
432
+ return new Decimal(0);
433
+ case char_type.fullname:
434
+ // Even though char is a value type, it's erased to string, and Unchecked.defaultof<char> is null
435
+ return null;
436
+ default:
437
+ throw new Error(`Cannot access constructor of ${t.fullname}`);
438
+ }
439
+ }
440
+ }
441
+ export function getValue(propertyInfo, v) {
442
+ return v[propertyInfo[0]];
443
+ }
444
+ // Fable.Core.Reflection
445
+ function assertUnion(x) {
446
+ if (!(x instanceof Union)) {
447
+ throw new Error(`Value is not an F# union type`);
448
+ }
449
+ }
450
+ export function getCaseTag(x) {
451
+ assertUnion(x);
452
+ return x.tag;
453
+ }
454
+ export function getCaseName(x) {
455
+ assertUnion(x);
456
+ return x.cases()[x.tag];
457
+ }
458
+ export function getCaseFields(x) {
459
+ assertUnion(x);
460
+ return x.fields;
461
+ }
@@ -0,0 +1,10 @@
1
+ export type MatchEvaluator = (match: any) => string;
2
+ export declare function create(pattern: string, options?: number): RegExp;
3
+ export declare function escape(str: string): string;
4
+ export declare function unescape(str: string): string;
5
+ export declare function isMatch(reg: RegExp, input: string, startAt?: number): boolean;
6
+ export declare function match(reg: RegExp, input: string, startAt?: number): RegExpExecArray | null;
7
+ export declare function matches(reg: RegExp, input: string, startAt?: number): RegExpExecArray[];
8
+ export declare function options(reg: RegExp): number;
9
+ export declare function replace(reg: string | RegExp, input: string, replacement: string | MatchEvaluator, limit?: number, offset?: number): string;
10
+ export declare function split(reg: string | RegExp, input: string, limit?: number, offset?: number): string[];
@@ -0,0 +1,131 @@
1
+ export function create(pattern, options = 0) {
2
+ // Supported RegexOptions
3
+ // * IgnoreCase: 0x0001
4
+ // * Multiline: 0x0002
5
+ // * Compiled: 0x0008 (ignored)
6
+ // * Singleline: 0x0010
7
+ // * ECMAScript: 0x0100 (ignored)
8
+ if ((options & ~(1 ^ 2 ^ 8 ^ 16 ^ 256)) !== 0) {
9
+ throw new Error("RegexOptions only supports: IgnoreCase, Multiline, Compiled, Singleline and ECMAScript");
10
+ }
11
+ // Set always global and unicode flags for compatibility with dotnet, see #2925
12
+ let flags = "gu";
13
+ flags += options & 1 ? "i" : ""; // 0x0001 RegexOptions.IgnoreCase
14
+ flags += options & 2 ? "m" : "";
15
+ flags += options & 16 ? "s" : "";
16
+ return new RegExp(pattern, flags);
17
+ }
18
+ // From http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
19
+ export function escape(str) {
20
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
21
+ }
22
+ export function unescape(str) {
23
+ return str.replace(/\\([\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|])/g, "$1");
24
+ }
25
+ export function isMatch(reg, input, startAt = 0) {
26
+ reg.lastIndex = startAt;
27
+ return reg.test(input);
28
+ }
29
+ export function match(reg, input, startAt = 0) {
30
+ reg.lastIndex = startAt;
31
+ return reg.exec(input);
32
+ }
33
+ export function matches(reg, input, startAt = 0) {
34
+ if (input == null) {
35
+ throw new Error("Input cannot ve null");
36
+ }
37
+ if (!reg.global) {
38
+ throw new Error("Non-global RegExp"); // Prevent infinite loop
39
+ }
40
+ reg.lastIndex = startAt;
41
+ const matches = [];
42
+ let m;
43
+ let lastMatchIndex = -1;
44
+ while ((m = reg.exec(input)) != null) {
45
+ // It can happen even global regex get stuck, see #2845
46
+ if (m.index === lastMatchIndex) {
47
+ reg.lastIndex++;
48
+ }
49
+ else {
50
+ lastMatchIndex = m.index;
51
+ matches.push(m);
52
+ }
53
+ }
54
+ return matches;
55
+ }
56
+ export function options(reg) {
57
+ let options = 256; // ECMAScript
58
+ options |= reg.ignoreCase ? 1 : 0;
59
+ options |= reg.multiline ? 2 : 0;
60
+ return options;
61
+ }
62
+ export function replace(reg, input, replacement, limit, offset = 0) {
63
+ function replacer() {
64
+ let res = arguments[0];
65
+ if (limit) {
66
+ limit--;
67
+ const match = [];
68
+ const len = arguments.length;
69
+ // arguments: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_function_as_a_parameter
70
+ // * match: matched substring
71
+ // * p1, p2, ...: nth capture group string
72
+ // * offset: offset of matched substring
73
+ // * string: whole string examined
74
+ // * groups: named capturing groups
75
+ // ONLY if regex contains a named capture group AND browser supports named groups
76
+ // -> last element can be groups OR input string
77
+ // -> check if last element is string
78
+ const withGroups = typeof arguments[len - 1] !== "string";
79
+ let pLast = withGroups ? len - 3 : len - 2;
80
+ for (let i = 0; i < pLast; i++) {
81
+ match.push(arguments[i]);
82
+ }
83
+ match.index = arguments[pLast++];
84
+ match.input = arguments[pLast++];
85
+ if (withGroups) {
86
+ match.groups = arguments[pLast];
87
+ }
88
+ res = replacement(match);
89
+ }
90
+ return res;
91
+ }
92
+ if (typeof reg === "string") {
93
+ const tmp = reg;
94
+ reg = create(input, limit ?? 0);
95
+ input = tmp;
96
+ limit = undefined;
97
+ }
98
+ if (typeof replacement === "function") {
99
+ limit = limit == null ? -1 : limit;
100
+ return input.substring(0, offset) + input.substring(offset).replace(reg, replacer);
101
+ }
102
+ else {
103
+ replacement =
104
+ replacement
105
+ // $0 doesn't work with JS regex, see #1155
106
+ .replace(/\$0/g, (_s) => "$&")
107
+ // named groups in replacement are `${name}` in .Net, but `$<name>` in JS (in regex: groups are `(?<name>...)` in both)
108
+ .replace(/\${([^}]+)}/g, "\$<$1>");
109
+ if (limit != null) {
110
+ let m;
111
+ const sub1 = input.substring(offset);
112
+ const _matches = matches(reg, sub1);
113
+ const sub2 = matches.length > limit ? (m = _matches[limit - 1], sub1.substring(0, m.index + m[0].length)) : sub1;
114
+ return input.substring(0, offset) + sub2.replace(reg, replacement)
115
+ + input.substring(offset + sub2.length);
116
+ }
117
+ else {
118
+ return input.replace(reg, replacement);
119
+ }
120
+ }
121
+ }
122
+ export function split(reg, input, limit, offset = 0) {
123
+ if (typeof reg === "string") {
124
+ const tmp = reg;
125
+ reg = create(input, limit ?? 0);
126
+ input = tmp;
127
+ limit = undefined;
128
+ }
129
+ input = input.substring(offset);
130
+ return input.split(reg, limit);
131
+ }
@@ -0,0 +1,37 @@
1
+ import { Union } from "./Types.js";
2
+ import { TypeInfo } from "./Reflection.js";
3
+ import { int32 } from "./Int32.js";
4
+ import { FSharpList } from "./List.js";
5
+ import { Option } from "./Option.js";
6
+ export type FSharpResult$2_$union<T, TError> = FSharpResult$2<T, TError, 0> | FSharpResult$2<T, TError, 1>;
7
+ export type FSharpResult$2_$cases<T, TError> = {
8
+ 0: ["Ok", [T]];
9
+ 1: ["Error", [TError]];
10
+ };
11
+ export declare function FSharpResult$2_Ok<T, TError>(ResultValue: T): FSharpResult$2<T, TError, 0>;
12
+ export declare function FSharpResult$2_Error<T, TError>(ErrorValue: TError): FSharpResult$2<T, TError, 1>;
13
+ export declare class FSharpResult$2<T, TError, Tag extends keyof FSharpResult$2_$cases<T, TError>> extends Union<Tag, FSharpResult$2_$cases<T, TError>[Tag][0]> {
14
+ readonly tag: Tag;
15
+ readonly fields: FSharpResult$2_$cases<T, TError>[Tag][1];
16
+ constructor(tag: Tag, fields: FSharpResult$2_$cases<T, TError>[Tag][1]);
17
+ cases(): string[];
18
+ }
19
+ export declare function FSharpResult$2_$reflection(gen0: TypeInfo, gen1: TypeInfo): TypeInfo;
20
+ export declare function Result_Map<a, b, c>(mapping: ((arg0: a) => b), result: FSharpResult$2_$union<a, c>): FSharpResult$2_$union<b, c>;
21
+ export declare function Result_MapError<a, b, c>(mapping: ((arg0: a) => b), result: FSharpResult$2_$union<c, a>): FSharpResult$2_$union<c, b>;
22
+ export declare function Result_Bind<a, b, c>(binder: ((arg0: a) => FSharpResult$2_$union<b, c>), result: FSharpResult$2_$union<a, c>): FSharpResult$2_$union<b, c>;
23
+ export declare function Result_IsOk<a, b>(result: FSharpResult$2_$union<a, b>): boolean;
24
+ export declare function Result_IsError<a, b>(result: FSharpResult$2_$union<a, b>): boolean;
25
+ export declare function Result_Contains<a, b>(value: a, result: FSharpResult$2_$union<a, b>): boolean;
26
+ export declare function Result_Count<a, b>(result: FSharpResult$2_$union<a, b>): int32;
27
+ export declare function Result_DefaultValue<a, b>(defaultValue: a, result: FSharpResult$2_$union<a, b>): a;
28
+ export declare function Result_DefaultWith<b, a>(defThunk: ((arg0: b) => a), result: FSharpResult$2_$union<a, b>): a;
29
+ export declare function Result_Exists<a, b>(predicate: ((arg0: a) => boolean), result: FSharpResult$2_$union<a, b>): boolean;
30
+ export declare function Result_Fold<a, b, s>(folder: ((arg0: s, arg1: a) => s), state: s, result: FSharpResult$2_$union<a, b>): s;
31
+ export declare function Result_FoldBack<a, b, s>(folder: ((arg0: a, arg1: s) => s), result: FSharpResult$2_$union<a, b>, state: s): s;
32
+ export declare function Result_ForAll<a, b>(predicate: ((arg0: a) => boolean), result: FSharpResult$2_$union<a, b>): boolean;
33
+ export declare function Result_Iterate<a, b>(action: ((arg0: a) => void), result: FSharpResult$2_$union<a, b>): void;
34
+ export declare function Result_ToArray<a, b>(result: FSharpResult$2_$union<a, b>): a[];
35
+ export declare function Result_ToList<a, b>(result: FSharpResult$2_$union<a, b>): FSharpList<a>;
36
+ export declare function Result_ToOption<a, b>(result: FSharpResult$2_$union<a, b>): Option<a>;
37
+ export declare function Result_ToValueOption<a, b>(result: FSharpResult$2_$union<a, b>): Option<a>;