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
@@ -1,131 +0,0 @@
1
- import { tryValueIfChoice1Of2, tryValueIfChoice2Of2, value } from "./Option";
2
- export class Observer {
3
- constructor(onNext, onError, onCompleted) {
4
- this.OnNext = onNext;
5
-
6
- this.OnError = onError || (_e => {
7
- return;
8
- });
9
-
10
- this.OnCompleted = onCompleted || (() => {
11
- return;
12
- });
13
- }
14
-
15
- }
16
-
17
- class Observable {
18
- constructor(subscribe) {
19
- this.Subscribe = subscribe;
20
- }
21
-
22
- }
23
-
24
- export function protect(f, succeed, fail) {
25
- try {
26
- return succeed(f());
27
- } catch (e) {
28
- fail(e);
29
- }
30
- }
31
- export function add(callback, source) {
32
- source.Subscribe(new Observer(callback));
33
- }
34
- export function choose(chooser, source) {
35
- return new Observable(observer => source.Subscribe(new Observer(t => protect(() => chooser(t), u => {
36
- if (u != null) {
37
- observer.OnNext(value(u));
38
- }
39
- }, observer.OnError), observer.OnError, observer.OnCompleted)));
40
- }
41
- export function filter(predicate, source) {
42
- return choose(x => predicate(x) ? x : null, source);
43
- }
44
- export function map(mapping, source) {
45
- return new Observable(observer => source.Subscribe(new Observer(t => {
46
- protect(() => mapping(t), observer.OnNext, observer.OnError);
47
- }, observer.OnError, observer.OnCompleted)));
48
- }
49
- export function merge(source1, source2) {
50
- return new Observable(observer => {
51
- let stopped = false;
52
- let completed1 = false;
53
- let completed2 = false;
54
- const h1 = source1.Subscribe(new Observer(v => {
55
- if (!stopped) {
56
- observer.OnNext(v);
57
- }
58
- }, e => {
59
- if (!stopped) {
60
- stopped = true;
61
- observer.OnError(e);
62
- }
63
- }, () => {
64
- if (!stopped) {
65
- completed1 = true;
66
-
67
- if (completed2) {
68
- stopped = true;
69
- observer.OnCompleted();
70
- }
71
- }
72
- }));
73
- const h2 = source2.Subscribe(new Observer(v => {
74
- if (!stopped) {
75
- observer.OnNext(v);
76
- }
77
- }, e => {
78
- if (!stopped) {
79
- stopped = true;
80
- observer.OnError(e);
81
- }
82
- }, () => {
83
- if (!stopped) {
84
- completed2 = true;
85
-
86
- if (completed1) {
87
- stopped = true;
88
- observer.OnCompleted();
89
- }
90
- }
91
- }));
92
- return {
93
- Dispose() {
94
- h1.Dispose();
95
- h2.Dispose();
96
- }
97
-
98
- };
99
- });
100
- }
101
- export function pairwise(source) {
102
- return new Observable(observer => {
103
- let last;
104
- return source.Subscribe(new Observer(next => {
105
- if (last != null) {
106
- observer.OnNext([last, next]);
107
- }
108
-
109
- last = next;
110
- }, observer.OnError, observer.OnCompleted));
111
- });
112
- }
113
- export function partition(predicate, source) {
114
- return [filter(predicate, source), filter(x => !predicate(x), source)];
115
- }
116
- export function scan(collector, state, source) {
117
- return new Observable(observer => {
118
- return source.Subscribe(new Observer(t => {
119
- protect(() => collector(state, t), u => {
120
- state = u;
121
- observer.OnNext(u);
122
- }, observer.OnError);
123
- }, observer.OnError, observer.OnCompleted));
124
- });
125
- }
126
- export function split(splitter, source) {
127
- return [choose(v => tryValueIfChoice1Of2(splitter(v)), source), choose(v => tryValueIfChoice2Of2(splitter(v)), source)];
128
- }
129
- export function subscribe(callback, source) {
130
- return source.Subscribe(new Observer(callback));
131
- }
@@ -1,118 +0,0 @@
1
- import { Union } from "./Types";
2
- import { compare, equals, structuralHash } from "./Util"; // Using a class here for better compatibility with TS files importing Some
3
-
4
- export class Some {
5
- constructor(value) {
6
- this.value = value;
7
- } // Don't add "Some" for consistency with erased options
8
-
9
-
10
- toString() {
11
- return String(this.value);
12
- }
13
-
14
- toJSON() {
15
- return this.value;
16
- }
17
-
18
- GetHashCode() {
19
- return structuralHash(this.value);
20
- }
21
-
22
- Equals(other) {
23
- if (other == null) {
24
- return false;
25
- } else {
26
- return equals(this.value, other instanceof Some ? other.value : other);
27
- }
28
- }
29
-
30
- CompareTo(other) {
31
- if (other == null) {
32
- return 1;
33
- } else {
34
- return compare(this.value, other instanceof Some ? other.value : other);
35
- }
36
- }
37
-
38
- }
39
- export function some(x) {
40
- return x == null || x instanceof Some ? new Some(x) : x;
41
- }
42
- export function value(x) {
43
- if (x == null) {
44
- throw new Error("Option has no value");
45
- } else {
46
- return x instanceof Some ? x.value : x;
47
- }
48
- }
49
- export function tryValue(x) {
50
- return x instanceof Some ? x.value : x;
51
- }
52
- export function toArray(opt) {
53
- return opt == null ? [] : [value(opt)];
54
- }
55
- export function defaultArg(opt, defaultValue) {
56
- return opt != null ? value(opt) : defaultValue;
57
- }
58
- export function defaultArgWith(opt, defThunk) {
59
- return opt != null ? value(opt) : defThunk();
60
- }
61
- export function filter(predicate, opt) {
62
- return opt != null ? predicate(value(opt)) ? opt : undefined : opt;
63
- }
64
- export function map(mapping, opt) {
65
- return opt != null ? some(mapping(value(opt))) : undefined;
66
- }
67
- export function map2(mapping, opt1, opt2) {
68
- return opt1 != null && opt2 != null ? mapping(value(opt1), value(opt2)) : undefined;
69
- }
70
- export function map3(mapping, opt1, opt2, opt3) {
71
- return opt1 != null && opt2 != null && opt3 != null ? mapping(value(opt1), value(opt2), value(opt3)) : undefined;
72
- }
73
- export function bind(binder, opt) {
74
- return opt != null ? binder(value(opt)) : undefined;
75
- }
76
- export function tryOp(op, arg) {
77
- try {
78
- return some(op(arg));
79
- } catch (_a) {
80
- return undefined;
81
- }
82
- } // CHOICE
83
-
84
- export class Choice extends Union {}
85
- export class Choice3 extends Union {}
86
- export class Choice4 extends Union {}
87
- export class Choice5 extends Union {}
88
- export class Choice6 extends Union {}
89
- export class Choice7 extends Union {}
90
- export function choice1Of2(x) {
91
- return new Choice(0, "Choice1Of2", x);
92
- }
93
- export function choice2Of2(x) {
94
- return new Choice(1, "Choice2Of2", x);
95
- }
96
- export function tryValueIfChoice1Of2(x) {
97
- return x.tag === 0 ? some(x.fields[0]) : undefined;
98
- }
99
- export function tryValueIfChoice2Of2(x) {
100
- return x.tag === 1 ? some(x.fields[0]) : undefined;
101
- } // RESULT
102
-
103
- export class Result extends Union {}
104
- export function ok(x) {
105
- return new Result(0, "Ok", x);
106
- }
107
- export function error(x) {
108
- return new Result(1, "Error", x);
109
- }
110
- export function mapOk(f, result) {
111
- return result.tag === 0 ? ok(f(result.fields[0])) : result;
112
- }
113
- export function mapError(f, result) {
114
- return result.tag === 1 ? error(f(result.fields[0])) : result;
115
- }
116
- export function bindOk(f, result) {
117
- return result.tag === 0 ? f(result.fields[0]) : result;
118
- }
@@ -1,345 +0,0 @@
1
- import { anonRecord as makeAnonRecord, Record, Union } from "./Types";
2
- import { compareArraysWith, equalArraysWith } from "./Util";
3
- export class CaseInfo {
4
- constructor(declaringType, tag, name, fields) {
5
- this.declaringType = declaringType;
6
- this.tag = tag;
7
- this.name = name;
8
- this.fields = fields;
9
- }
10
-
11
- }
12
- export class TypeInfo {
13
- constructor(fullname, generics, construct, fields, cases, enumCases) {
14
- this.fullname = fullname;
15
- this.generics = generics;
16
- this.construct = construct;
17
- this.fields = fields;
18
- this.cases = cases;
19
- this.enumCases = enumCases;
20
- }
21
-
22
- toString() {
23
- return fullName(this);
24
- }
25
-
26
- Equals(other) {
27
- return equals(this, other);
28
- }
29
-
30
- CompareTo(other) {
31
- return compare(this, other);
32
- }
33
-
34
- }
35
- export function getGenerics(t) {
36
- return t.generics != null ? t.generics : [];
37
- }
38
- export function equals(t1, t2) {
39
- if (t1.fullname === "") {
40
- // Anonymous records
41
- return t2.fullname === "" && equalArraysWith(getRecordElements(t1), getRecordElements(t2), ([k1, v1], [k2, v2]) => k1 === k2 && equals(v1, v2));
42
- } else {
43
- return t1.fullname === t2.fullname && equalArraysWith(getGenerics(t1), getGenerics(t2), equals);
44
- }
45
- } // System.Type is not comparable in .NET, but let's implement this
46
- // in case users want to create a dictionary with types as keys
47
-
48
- export function compare(t1, t2) {
49
- if (t1.fullname !== t2.fullname) {
50
- return t1.fullname < t2.fullname ? -1 : 1;
51
- } else {
52
- return compareArraysWith(getGenerics(t1), getGenerics(t2), compare);
53
- }
54
- }
55
- export function class_type(fullname, generics, construct) {
56
- return new TypeInfo(fullname, generics, construct);
57
- }
58
- export function record_type(fullname, generics, construct, fields) {
59
- return new TypeInfo(fullname, generics, construct, fields);
60
- }
61
- export function anonRecord_type(...fields) {
62
- return new TypeInfo("", undefined, undefined, () => fields);
63
- }
64
- export function union_type(fullname, generics, construct, cases) {
65
- const t = new TypeInfo(fullname, generics, construct, undefined, () => cases().map((x, i) => typeof x === "string" ? new CaseInfo(t, i, x) : new CaseInfo(t, i, x[0], x[1])));
66
- return t;
67
- }
68
- export function tuple_type(...generics) {
69
- return new TypeInfo("System.Tuple`" + generics.length, generics);
70
- }
71
- export function delegate_type(...generics) {
72
- return new TypeInfo("System.Func`" + generics.length, generics);
73
- }
74
- export function lambda_type(argType, returnType) {
75
- return new TypeInfo("Microsoft.FSharp.Core.FSharpFunc`2", [argType, returnType]);
76
- }
77
- export function option_type(generic) {
78
- return new TypeInfo("Microsoft.FSharp.Core.FSharpOption`1", [generic]);
79
- }
80
- export function list_type(generic) {
81
- return new TypeInfo("Microsoft.FSharp.Collections.FSharpList`1", [generic]);
82
- }
83
- export function array_type(generic) {
84
- return new TypeInfo(generic.fullname + "[]", [generic]);
85
- }
86
- export function enum_type(fullname, underlyingType, enumCases) {
87
- return new TypeInfo(fullname, [underlyingType], undefined, undefined, undefined, enumCases);
88
- }
89
- export const obj_type = new TypeInfo("System.Object");
90
- export const unit_type = new TypeInfo("Microsoft.FSharp.Core.Unit");
91
- export const char_type = new TypeInfo("System.Char");
92
- export const string_type = new TypeInfo("System.String");
93
- export const bool_type = new TypeInfo("System.Boolean");
94
- export const int8_type = new TypeInfo("System.SByte");
95
- export const uint8_type = new TypeInfo("System.Byte");
96
- export const int16_type = new TypeInfo("System.Int16");
97
- export const uint16_type = new TypeInfo("System.UInt16");
98
- export const int32_type = new TypeInfo("System.Int32");
99
- export const uint32_type = new TypeInfo("System.UInt32");
100
- export const float32_type = new TypeInfo("System.Single");
101
- export const float64_type = new TypeInfo("System.Double");
102
- export const decimal_type = new TypeInfo("System.Decimal");
103
- export function name(info) {
104
- if (Array.isArray(info)) {
105
- return info[0];
106
- } else if (info instanceof CaseInfo) {
107
- return info.name;
108
- } else {
109
- const i = info.fullname.lastIndexOf(".");
110
- return i === -1 ? info.fullname : info.fullname.substr(i + 1);
111
- }
112
- }
113
- export function fullName(t) {
114
- const gen = t.generics != null && !isArray(t) ? t.generics : [];
115
-
116
- if (gen.length > 0) {
117
- return t.fullname + "[" + gen.map(x => fullName(x)).join(",") + "]";
118
- } else {
119
- return t.fullname;
120
- }
121
- }
122
- export function namespace(t) {
123
- const i = t.fullname.lastIndexOf(".");
124
- return i === -1 ? "" : t.fullname.substr(0, i);
125
- }
126
- export function isArray(t) {
127
- return t.fullname.endsWith("[]");
128
- }
129
- export function getElementType(t) {
130
- var _a;
131
-
132
- return isArray(t) ? (_a = t.generics) === null || _a === void 0 ? void 0 : _a[0] : undefined;
133
- }
134
- export function isGenericType(t) {
135
- return t.generics != null && t.generics.length > 0;
136
- }
137
- export function isEnum(t) {
138
- return t.enumCases != null && t.enumCases.length > 0;
139
- }
140
- /**
141
- * This doesn't replace types for fields (records) or cases (unions)
142
- * but it should be enough for type comparison purposes
143
- */
144
-
145
- export function getGenericTypeDefinition(t) {
146
- return t.generics == null ? t : new TypeInfo(t.fullname, t.generics.map(() => obj_type));
147
- }
148
- export function getEnumUnderlyingType(t) {
149
- var _a;
150
-
151
- return (_a = t.generics) === null || _a === void 0 ? void 0 : _a[0];
152
- }
153
- export function getEnumValues(t) {
154
- if (isEnum(t) && t.enumCases != null) {
155
- return t.enumCases.map(kv => kv[1]);
156
- } else {
157
- throw new Error(`${t.fullname} is not an enum type`);
158
- }
159
- }
160
- export function getEnumNames(t) {
161
- if (isEnum(t) && t.enumCases != null) {
162
- return t.enumCases.map(kv => kv[0]);
163
- } else {
164
- throw new Error(`${t.fullname} is not an enum type`);
165
- }
166
- }
167
-
168
- function getEnumCase(t, v) {
169
- if (t.enumCases != null) {
170
- if (typeof v === "string") {
171
- for (const kv of t.enumCases) {
172
- if (kv[0] === v) {
173
- return kv;
174
- }
175
- }
176
-
177
- throw new Error(`'${v}' was not found in ${t.fullname}`);
178
- } else {
179
- for (const kv of t.enumCases) {
180
- if (kv[1] === v) {
181
- return kv;
182
- }
183
- } // .NET returns the number even if it doesn't match any of the cases
184
-
185
-
186
- return ["", v];
187
- }
188
- } else {
189
- throw new Error(`${t.fullname} is not an enum type`);
190
- }
191
- }
192
-
193
- export function parseEnum(t, str) {
194
- // TODO: better int parsing here, parseInt ceils floats: "4.8" -> 4
195
- const value = parseInt(str, 10);
196
- return getEnumCase(t, isNaN(value) ? str : value)[1];
197
- }
198
- export function tryParseEnum(t, str) {
199
- try {
200
- const v = parseEnum(t, str);
201
- return [true, v];
202
- } catch (_a) {// supress error
203
- }
204
-
205
- return [false, NaN];
206
- }
207
- export function getEnumName(t, v) {
208
- return getEnumCase(t, v)[0];
209
- }
210
- export function isEnumDefined(t, v) {
211
- try {
212
- const kv = getEnumCase(t, v);
213
- return kv[0] != null && kv[0] !== "";
214
- } catch (_a) {// supress error
215
- }
216
-
217
- return false;
218
- } // FSharpType
219
-
220
- export function getUnionCases(t) {
221
- if (t.cases != null) {
222
- return t.cases();
223
- } else {
224
- throw new Error(`${t.fullname} is not an F# union type`);
225
- }
226
- }
227
- export function getRecordElements(t) {
228
- if (t.fields != null) {
229
- return t.fields();
230
- } else {
231
- throw new Error(`${t.fullname} is not an F# record type`);
232
- }
233
- }
234
- export function getTupleElements(t) {
235
- if (isTuple(t) && t.generics != null) {
236
- return t.generics;
237
- } else {
238
- throw new Error(`${t.fullname} is not a tuple type`);
239
- }
240
- }
241
- export function getFunctionElements(t) {
242
- if (isFunction(t) && t.generics != null) {
243
- const gen = t.generics;
244
- return [gen[0], gen[1]];
245
- } else {
246
- throw new Error(`${t.fullname} is not an F# function type`);
247
- }
248
- }
249
- export function isUnion(t) {
250
- return t instanceof TypeInfo ? t.cases != null : t instanceof Union;
251
- }
252
- export function isRecord(t) {
253
- return t instanceof TypeInfo ? t.fields != null : t instanceof Record;
254
- }
255
- export function isTuple(t) {
256
- return t.fullname.startsWith("System.Tuple");
257
- } // In .NET this is false for delegates
258
-
259
- export function isFunction(t) {
260
- return t.fullname === "Microsoft.FSharp.Core.FSharpFunc`2";
261
- } // FSharpValue
262
-
263
- export function getUnionFields(v, t) {
264
- const cases = getUnionCases(t);
265
- const case_ = cases[v.tag];
266
-
267
- if (case_ == null) {
268
- throw new Error(`Cannot find case ${v.name} in union type`);
269
- }
270
-
271
- return [case_, v.fields];
272
- }
273
- export function getUnionCaseFields(uci) {
274
- return uci.fields == null ? [] : uci.fields;
275
- }
276
- export function getRecordFields(v) {
277
- return Object.keys(v).map(k => v[k]);
278
- }
279
- export function getRecordField(v, field) {
280
- return v[field[0]];
281
- }
282
- export function getTupleFields(v) {
283
- return v;
284
- }
285
- export function getTupleField(v, i) {
286
- return v[i];
287
- }
288
- export function makeUnion(uci, values) {
289
- const expectedLength = (uci.fields || []).length;
290
-
291
- if (values.length !== expectedLength) {
292
- throw new Error(`Expected an array of length ${expectedLength} but got ${values.length}`);
293
- }
294
-
295
- return uci.declaringType.construct != null ? new uci.declaringType.construct(uci.tag, uci.name, ...values) : {};
296
- }
297
- export function makeRecord(t, values) {
298
- const fields = getRecordElements(t);
299
-
300
- if (fields.length !== values.length) {
301
- throw new Error(`Expected an array of length ${fields.length} but got ${values.length}`);
302
- }
303
-
304
- return t.construct != null ? new t.construct(...values) : makeAnonRecord(fields.reduce((obj, [key, _t], i) => {
305
- obj[key] = values[i];
306
- return obj;
307
- }, {}));
308
- }
309
- export function makeTuple(values, _t) {
310
- return values;
311
- }
312
- export function makeGenericType(t, generics) {
313
- return new TypeInfo(t.fullname, generics, t.construct, t.fields, t.cases);
314
- }
315
- export function createInstance(t, consArgs) {
316
- // TODO: Check if consArgs length is same as t.construct?
317
- // (Arg types can still be different)
318
- if (typeof t.construct === "function") {
319
- return new t.construct(...(consArgs !== null && consArgs !== void 0 ? consArgs : []));
320
- } else {
321
- throw new Error(`Cannot access constructor of ${t.fullname}`);
322
- }
323
- }
324
- export function getValue(propertyInfo, v) {
325
- return v[propertyInfo[0]];
326
- } // Fable.Core.Reflection
327
-
328
- function assertUnion(x) {
329
- if (!(x instanceof Union)) {
330
- throw new Error(`Value is not an F# union type`);
331
- }
332
- }
333
-
334
- export function getCaseTag(x) {
335
- assertUnion(x);
336
- return x.tag;
337
- }
338
- export function getCaseName(x) {
339
- assertUnion(x);
340
- return x.name;
341
- }
342
- export function getCaseFields(x) {
343
- assertUnion(x);
344
- return x.fields;
345
- }
@@ -1,118 +0,0 @@
1
- export function create(pattern, options = 0) {
2
- // Supported RegexOptions
3
- // * IgnoreCase: 0x0001
4
- // * Multiline: 0x0002
5
- // * Singleline: 0x0010
6
- // * ECMAScript: 0x0100 (ignored)
7
- if ((options & ~(1 ^ 2 ^ 16 ^ 256)) !== 0) {
8
- throw new Error("RegexOptions only supports: IgnoreCase, Multiline, Singleline and ECMAScript");
9
- }
10
-
11
- let flags = "g";
12
- flags += options & 1 ? "i" : ""; // 0x0001 RegexOptions.IgnoreCase
13
-
14
- flags += options & 2 ? "m" : "";
15
- flags += options & 16 ? "s" : "";
16
- return new RegExp(pattern, flags);
17
- } // From http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
18
-
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(str, pattern, options = 0) {
26
- let reg;
27
- reg = str instanceof RegExp ? (reg = str, str = pattern, reg.lastIndex = options, reg) : reg = create(pattern, options);
28
- return reg.test(str);
29
- }
30
- export function match(str, pattern, options = 0) {
31
- let reg;
32
- reg = str instanceof RegExp ? (reg = str, str = pattern, reg.lastIndex = options, reg) : reg = create(pattern, options);
33
- return reg.exec(str);
34
- }
35
- export function matches(str, pattern, options = 0) {
36
- let reg;
37
- reg = str instanceof RegExp ? (reg = str, str = pattern, reg.lastIndex = options, reg) : reg = create(pattern, options);
38
-
39
- if (!reg.global) {
40
- throw new Error("Non-global RegExp"); // Prevent infinite loop
41
- }
42
-
43
- let m = reg.exec(str);
44
- const matches = [];
45
-
46
- while (m !== null) {
47
- matches.push(m);
48
- m = reg.exec(str);
49
- }
50
-
51
- return matches;
52
- }
53
- export function options(reg) {
54
- let options = 256; // ECMAScript
55
-
56
- options |= reg.ignoreCase ? 1 : 0;
57
- options |= reg.multiline ? 2 : 0;
58
- return options;
59
- }
60
- export function replace(reg, input, replacement, limit, offset = 0) {
61
- function replacer() {
62
- let res = arguments[0];
63
-
64
- if (limit) {
65
- limit--;
66
- const match = [];
67
- const len = arguments.length;
68
-
69
- for (let i = 0; i < len - 2; i++) {
70
- match.push(arguments[i]);
71
- }
72
-
73
- match.index = arguments[len - 2];
74
- match.input = arguments[len - 1];
75
- res = replacement(match);
76
- }
77
-
78
- return res;
79
- }
80
-
81
- if (typeof reg === "string") {
82
- const tmp = reg;
83
- reg = create(input, limit !== null && limit !== void 0 ? limit : 0);
84
- input = tmp;
85
- limit = undefined;
86
- }
87
-
88
- if (typeof replacement === "function") {
89
- limit = limit == null ? -1 : limit;
90
- return input.substring(0, offset) + input.substring(offset).replace(reg, replacer);
91
- } else {
92
- // $0 doesn't work with JS regex, see #1155
93
- replacement = replacement.replace(/\$0/g, _s => "$&");
94
-
95
- if (limit != null) {
96
- let m;
97
- const sub1 = input.substring(offset);
98
-
99
- const _matches = matches(reg, sub1);
100
-
101
- const sub2 = matches.length > limit ? (m = _matches[limit - 1], sub1.substring(0, m.index + m[0].length)) : sub1;
102
- return input.substring(0, offset) + sub2.replace(reg, replacement) + input.substring(offset + sub2.length);
103
- } else {
104
- return input.replace(reg, replacement);
105
- }
106
- }
107
- }
108
- export function split(reg, input, limit, offset = 0) {
109
- if (typeof reg === "string") {
110
- const tmp = reg;
111
- reg = create(input, limit !== null && limit !== void 0 ? limit : 0);
112
- input = tmp;
113
- limit = undefined;
114
- }
115
-
116
- input = input.substring(offset);
117
- return input.split(reg, limit);
118
- }