@fable-org/fable-library-ts 1.0.0-beta-001

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 (57) hide show
  1. package/Array.ts +1362 -0
  2. package/Async.ts +207 -0
  3. package/AsyncBuilder.ts +222 -0
  4. package/BigInt.ts +337 -0
  5. package/BitConverter.ts +165 -0
  6. package/Boolean.ts +22 -0
  7. package/CHANGELOG.md +15 -0
  8. package/Char.ts +222 -0
  9. package/Choice.ts +300 -0
  10. package/Date.ts +495 -0
  11. package/DateOffset.ts +324 -0
  12. package/DateOnly.ts +146 -0
  13. package/Decimal.ts +250 -0
  14. package/Double.ts +55 -0
  15. package/Encoding.ts +170 -0
  16. package/Event.ts +119 -0
  17. package/FSharp.Collections.ts +34 -0
  18. package/FSharp.Core.CompilerServices.ts +37 -0
  19. package/FSharp.Core.ts +86 -0
  20. package/Global.ts +37 -0
  21. package/Guid.ts +143 -0
  22. package/Int32.ts +156 -0
  23. package/List.ts +1417 -0
  24. package/Long.ts +49 -0
  25. package/MailboxProcessor.ts +125 -0
  26. package/Map.ts +1552 -0
  27. package/MapUtil.ts +120 -0
  28. package/MutableMap.ts +344 -0
  29. package/MutableSet.ts +248 -0
  30. package/Native.ts +11 -0
  31. package/Numeric.ts +80 -0
  32. package/Observable.ts +156 -0
  33. package/Option.ts +137 -0
  34. package/README.md +3 -0
  35. package/Random.ts +196 -0
  36. package/Range.ts +56 -0
  37. package/Reflection.ts +539 -0
  38. package/RegExp.ts +143 -0
  39. package/Result.ts +196 -0
  40. package/Seq.ts +1526 -0
  41. package/Seq2.ts +129 -0
  42. package/Set.ts +1955 -0
  43. package/String.ts +589 -0
  44. package/System.Collections.Generic.ts +380 -0
  45. package/System.Text.ts +137 -0
  46. package/SystemException.ts +7 -0
  47. package/TimeOnly.ts +131 -0
  48. package/TimeSpan.ts +194 -0
  49. package/Timer.ts +80 -0
  50. package/Types.ts +231 -0
  51. package/Unicode.13.0.0.ts +4 -0
  52. package/Uri.ts +206 -0
  53. package/Util.ts +928 -0
  54. package/lib/big.d.ts +338 -0
  55. package/lib/big.js +1054 -0
  56. package/package.json +24 -0
  57. package/tsconfig.json +103 -0
package/Double.ts ADDED
@@ -0,0 +1,55 @@
1
+ import { FSharpRef } from "./Types.js";
2
+
3
+ export function tryParse(str: string, defValue: FSharpRef<number>): boolean {
4
+ // TODO: test if value is valid and in range
5
+ if (str != null && /\S/.test(str)) {
6
+ const v = +str.replace("_", "");
7
+ if (!Number.isNaN(v)) {
8
+ defValue.contents = v;
9
+ return true;
10
+ }
11
+ }
12
+ return false;
13
+ }
14
+
15
+ export function parse(str: string): number {
16
+ const defValue = new FSharpRef(0);
17
+ if (tryParse(str, defValue)) {
18
+ return defValue.contents;
19
+ } else {
20
+ throw new Error(`The input string ${str} was not in a correct format.`);
21
+ }
22
+ }
23
+
24
+ // JS Number.isFinite function evals false for NaN
25
+ export function isPositiveInfinity(x: number) {
26
+ return x === Number.POSITIVE_INFINITY;
27
+ }
28
+
29
+ export function isNegativeInfinity(x: number) {
30
+ return x === Number.NEGATIVE_INFINITY;
31
+ }
32
+
33
+ export function isInfinity(x: number) {
34
+ return x === Number.POSITIVE_INFINITY || x === Number.NEGATIVE_INFINITY;
35
+ }
36
+
37
+ export function max(x: number, y: number): number {
38
+ return x > y ? x : y;
39
+ }
40
+
41
+ export function min(x: number, y: number): number {
42
+ return x < y ? x : y;
43
+ }
44
+
45
+ export function maxMagnitude(x: number, y: number): number {
46
+ return Math.abs(x) > Math.abs(y) ? x : y;
47
+ }
48
+
49
+ export function minMagnitude(x: number, y: number): number {
50
+ return Math.abs(x) < Math.abs(y) ? x : y;
51
+ }
52
+
53
+ export function clamp(x: number, min: number, max: number): number {
54
+ return x < min ? min : x > max ? max : x;
55
+ }
package/Encoding.ts ADDED
@@ -0,0 +1,170 @@
1
+ import { uint8 } from "./Int32.js";
2
+
3
+ const littleEndian = true;
4
+
5
+ function utf16le_encode(str: string) {
6
+ const bytes = new Uint8Array(str.length * 2);
7
+ const view = new DataView(bytes.buffer);
8
+ for (let i = 0; i < str.length; i++) {
9
+ const code = str.charCodeAt(i);
10
+ view.setUint16(i * 2, code, littleEndian);
11
+ }
12
+ return bytes;
13
+ }
14
+
15
+ function utf16le_decode(bytes: ArrayLike<uint8>) {
16
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
17
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
18
+ const chars = new Array<string>(view.byteLength / 2);
19
+ for (let i = 0; i < chars.length; i++) {
20
+ const code = view.getUint16(i * 2, littleEndian);
21
+ chars[i] = String.fromCharCode(code);
22
+ }
23
+ return chars.join("");
24
+ }
25
+
26
+ function utf8_encode(str: string) {
27
+ let pos = 0;
28
+ let buf = new Uint8Array(str.length * 3);
29
+ for (let i = 0; i < str.length; i++) {
30
+ let code = str.charCodeAt(i);
31
+ if (code >= 0xD800 && code <= 0xDBFF) {
32
+ const nextCode = (i < str.length) ? str.charCodeAt(i + 1) : 0;
33
+ if (nextCode >= 0xDC00 && nextCode <= 0xDFFF) {
34
+ i += 1;
35
+ code = (code - 0xD800) * 0x400 + nextCode - 0xDC00 + 0x10000;
36
+ if (code > 0xFFFF) {
37
+ buf[pos++] = (0x1E << 3) | (code >>> 18);
38
+ buf[pos++] = (0x2 << 6) | ((code >>> 12) & 0x3F);
39
+ buf[pos++] = (0x2 << 6) | ((code >>> 6) & 0x3F);
40
+ buf[pos++] = (0x2 << 6) | (code & 0x3F);
41
+ }
42
+ } else {
43
+ buf[pos++] = 0xEF;
44
+ buf[pos++] = 0xBF;
45
+ buf[pos++] = 0xBD;
46
+ }
47
+ } else if (code <= 0x007F) {
48
+ buf[pos++] = (0x0 << 7) | code;
49
+ } else if (code <= 0x07FF) {
50
+ buf[pos++] = (0x6 << 5) | (code >>> 6);
51
+ buf[pos++] = (0x2 << 6) | (code & 0x3F);
52
+ } else {
53
+ buf[pos++] = (0xE << 4) | (code >>> 12);
54
+ buf[pos++] = (0x2 << 6) | ((code >>> 6) & 0x3F);
55
+ buf[pos++] = (0x2 << 6) | (code & 0x3F);
56
+ }
57
+ }
58
+ buf = new Uint8Array(buf.buffer.slice(0, pos));
59
+ return buf;
60
+ }
61
+
62
+ function utf8_decode(bytes: ArrayLike<uint8>) {
63
+ let pos = 0;
64
+ const decodeUtf8 = () => {
65
+ const i1 = bytes[pos++];
66
+ if ((i1 & 0x80) === 0) {
67
+ return i1;
68
+ } else if ((i1 & 0xE0) === 0xC0) {
69
+ const i2 = bytes[pos++];
70
+ return ((i1 & 0x1F) << 6) | (i2 & 0x3F);
71
+ } else if ((i1 & 0xF0) === 0xE0) {
72
+ const i2 = bytes[pos++];
73
+ const i3 = bytes[pos++];
74
+ return ((i1 & 0x0F) << 12) | ((i2 & 0x3F) << 6) | (i3 & 0x3F);
75
+ } else if ((i1 & 0xF8) === 0xF0) {
76
+ const i2 = bytes[pos++];
77
+ const i3 = bytes[pos++];
78
+ const i4 = bytes[pos++];
79
+ return ((i1 & 0x07) << 18) | ((i2 & 0x3F) << 12) | ((i3 & 0x3F) << 6) | (i4 & 0x3F);
80
+ } else {
81
+ throw new RangeError("Invalid UTF8 byte: " + i1);
82
+ }
83
+ };
84
+ const chars = new Array<string>();
85
+ while (pos < bytes.length) {
86
+ const code = decodeUtf8();
87
+ chars.push(String.fromCodePoint(code));
88
+ }
89
+ return chars.join("");
90
+ }
91
+
92
+ class UTF16LE {
93
+
94
+ public getBytes(str: string | string[], index?: number, count?: number) {
95
+ str = Array.isArray(str) ? str.join("") : str;
96
+ if (index != null && count != null) {
97
+ str = str.substring(index, index + count);
98
+ } else if (index != null) {
99
+ str = str.substring(index);
100
+ }
101
+ if (typeof Buffer !== "undefined") {
102
+ const bytes = Buffer.from(str, "utf16le");
103
+ return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
104
+ } else {
105
+ return utf16le_encode(str); // polyfill
106
+ }
107
+ }
108
+
109
+ public getString(bytes: ArrayLike<uint8>, index?: number, count?: number) {
110
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
111
+ let buffer = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
112
+ if (index != null && count != null) {
113
+ buffer = buffer.subarray(index, index + count);
114
+ } else if (index != null) {
115
+ buffer = buffer.subarray(index);
116
+ }
117
+ if (typeof TextDecoder !== "undefined") {
118
+ return new TextDecoder("utf-16le").decode(buffer);
119
+ } else if (typeof Buffer !== "undefined") {
120
+ return Buffer.from(buffer).toString("utf16le");
121
+ } else {
122
+ return utf16le_decode(buffer); // polyfill
123
+ }
124
+ }
125
+
126
+ }
127
+
128
+ class UTF8 {
129
+
130
+ public getBytes(str: string | string[], index?: number, count?: number) {
131
+ str = Array.isArray(str) ? str.join("") : str;
132
+ if (index != null && count != null) {
133
+ str = str.substring(index, index + count);
134
+ } else if (index != null) {
135
+ str = str.substring(index);
136
+ }
137
+ if (typeof TextEncoder !== "undefined") {
138
+ return new TextEncoder().encode(str);
139
+ } else if (typeof Buffer !== "undefined") {
140
+ const bytes = Buffer.from(str, "utf8");
141
+ return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
142
+ } else {
143
+ return utf8_encode(str); // polyfill
144
+ }
145
+ }
146
+
147
+ public getString(bytes: ArrayLike<uint8>, index?: number, count?: number) {
148
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
149
+ let buffer = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
150
+ if (index != null && count != null) {
151
+ buffer = buffer.subarray(index, index + count);
152
+ } else if (index != null) {
153
+ buffer = buffer.subarray(index);
154
+ }
155
+ if (typeof TextDecoder !== "undefined") {
156
+ return new TextDecoder().decode(buffer);
157
+ } else if (typeof Buffer !== "undefined") {
158
+ return Buffer.from(buffer).toString("utf8");
159
+ } else {
160
+ return utf8_decode(buffer); // polyfill
161
+ }
162
+ }
163
+
164
+ }
165
+
166
+ const _UTF16 = new UTF16LE();
167
+ const _UTF8 = new UTF8();
168
+
169
+ export function get_Unicode() { return _UTF16; }
170
+ export function get_UTF8() { return _UTF8; }
package/Event.ts ADDED
@@ -0,0 +1,119 @@
1
+ import { IObservable, subscribe } from "./Observable.js";
2
+ import { Option, some, value } from "./Option.js";
3
+ import { FSharpChoice$2_$union, Choice_tryValueIfChoice1Of2, Choice_tryValueIfChoice2Of2 } from "./Choice.js";
4
+
5
+ export type Handler<T> = (sender: any, x: T) => void;
6
+
7
+ export interface IDelegateEvent<Delegate extends Function> {
8
+ AddHandler(d: Delegate): void;
9
+ RemoveHandler(d: Delegate): void;
10
+ }
11
+
12
+ export interface IEvent$2<Delegate extends Function, Args> extends IDelegateEvent<Delegate>, IObservable<Args> {
13
+ }
14
+
15
+ export type IEvent<T> = IEvent$2<Handler<T>, T>
16
+
17
+ export class Event$2<Delegate extends Function, Args> {
18
+ private delegates: Delegate[] = [];
19
+
20
+ private _add(d: Delegate) {
21
+ this.delegates.push(d);
22
+ }
23
+
24
+ private _remove(d: Delegate) {
25
+ const index = this.delegates.indexOf(d);
26
+ if (index > -1) {
27
+ this.delegates.splice(index, 1);
28
+ }
29
+ }
30
+
31
+ get Publish(): IEvent$2<Delegate, Args> {
32
+ return createEvent(h => { this._add(h) }, h => { this._remove(h) });
33
+ }
34
+
35
+ public Trigger(value: Args): void;
36
+ public Trigger(sender: any, value: Args): void
37
+ public Trigger(senderOrValue: any, valueOrUndefined?: Args): void {
38
+ let sender: any = null;
39
+ const value = valueOrUndefined === undefined ? senderOrValue as Args : (sender = senderOrValue, valueOrUndefined);
40
+ this.delegates.forEach(f => { f(sender, value) });
41
+ }
42
+ }
43
+
44
+ export class Event<T> extends Event$2<Handler<T>, T> {
45
+ }
46
+
47
+ export function add<Del extends Function, T>(callback: (x: T) => void, sourceEvent: IEvent$2<Del, T>): void {
48
+ subscribe(callback, sourceEvent);
49
+ }
50
+
51
+ export function choose<Del extends Function, T, U>(chooser: (x: T) => Option<U>, sourceEvent: IEvent$2<Del, T>): IEvent<U> {
52
+ const ev = new Event<U>();
53
+ add((t) => {
54
+ const u = chooser(t);
55
+ if (u != null) { ev.Trigger(value(u)); }
56
+ }, sourceEvent);
57
+ return ev.Publish;
58
+ }
59
+
60
+ export function filter<Del extends Function, T>(predicate: (x: T) => boolean, sourceEvent: IEvent$2<Del, T>): IEvent<T> {
61
+ return choose((x) => predicate(x) ? some(x) : undefined, sourceEvent);
62
+ }
63
+
64
+ export function map<Del extends Function, T, U>(mapping: (x: T) => U, sourceEvent: IEvent$2<Del, T>): IEvent<U> {
65
+ const ev = new Event<U>();
66
+ add((t) => ev.Trigger(mapping(t)), sourceEvent);
67
+ return ev.Publish;
68
+ }
69
+
70
+ export function merge<Del1 extends Function, Del2 extends Function, T>(event1: IEvent$2<Del1, T>, event2: IEvent$2<Del2, T>): IEvent<T> {
71
+ const ev = new Event<T>();
72
+ const fn = (x: T) => ev.Trigger(x);
73
+ add(fn, event1);
74
+ add(fn, event2);
75
+ return ev.Publish;
76
+ }
77
+
78
+ export function pairwise<Del extends Function, T>(sourceEvent: IEvent$2<Del, T>): IEvent<[T, T]> {
79
+ const ev = new Event<[T, T]>();
80
+ let last: T;
81
+ let haveLast = false;
82
+ add((next) => {
83
+ if (haveLast) {
84
+ ev.Trigger([last, next]);
85
+ }
86
+ last = next;
87
+ haveLast = true;
88
+ }, sourceEvent);
89
+ return ev.Publish;
90
+ }
91
+
92
+ export function partition<Del extends Function, T>(predicate: (x: T) => boolean, sourceEvent: IEvent$2<Del, T>): [IEvent<T>, IEvent<T>] {
93
+ return [filter(predicate, sourceEvent), filter((x) => !predicate(x), sourceEvent)];
94
+ }
95
+
96
+ export function scan<Del extends Function, U, T>(collector: (u: U, t: T) => U, state: U, sourceEvent: IEvent$2<Del, T>): IEvent<U> {
97
+ return map((t) => state = collector(state, t), sourceEvent);
98
+ }
99
+
100
+ export function split<Del extends Function, T, U1, U2>(splitter: (x: T) => FSharpChoice$2_$union<U1, U2>, sourceEvent: IEvent$2<Del, T>): [IEvent<U1>, IEvent<U2>] {
101
+ return [
102
+ choose((v) => Choice_tryValueIfChoice1Of2(splitter(v)), sourceEvent),
103
+ choose((v) => Choice_tryValueIfChoice2Of2(splitter(v)), sourceEvent),
104
+ ];
105
+ }
106
+
107
+ export function createEvent<Del extends Function, T>(addHandler: (h: Del) => void, removeHandler: (h: Del) => void): IEvent$2<Del, T> {
108
+ return {
109
+ AddHandler(h) { addHandler(h); },
110
+ RemoveHandler(h) { removeHandler(h); },
111
+ Subscribe(r) {
112
+ const h = ((_: any, args: T) => r.OnNext(args)) as unknown as Del;
113
+ addHandler(h);
114
+ return {
115
+ Dispose() { removeHandler(h); }
116
+ };
117
+ }
118
+ };
119
+ }
@@ -0,0 +1,34 @@
1
+ import { int32 } from "./Int32.js";
2
+ import { compare, IComparer, physicalHash, equals, structuralHash, IEqualityComparer } from "./Util.js";
3
+
4
+ export function HashIdentity_FromFunctions<T>(hash: ((arg0: T) => int32), eq: ((arg0: T, arg1: T) => boolean)): IEqualityComparer<T> {
5
+ return {
6
+ Equals(x: T, y: T): boolean {
7
+ return eq(x, y);
8
+ },
9
+ GetHashCode(x_1: T): int32 {
10
+ return hash(x_1);
11
+ },
12
+ };
13
+ }
14
+
15
+ export function HashIdentity_Structural<T>(): IEqualityComparer<T> {
16
+ return HashIdentity_FromFunctions<T>(structuralHash, equals);
17
+ }
18
+
19
+ export function HashIdentity_Reference<T>(): IEqualityComparer<T> {
20
+ return HashIdentity_FromFunctions<T>(physicalHash, (e: T, e_1: T): boolean => (e === e_1));
21
+ }
22
+
23
+ export function ComparisonIdentity_FromFunction<T>(comparer: ((arg0: T, arg1: T) => int32)): IComparer<T> {
24
+ return {
25
+ Compare(x: T, y: T): int32 {
26
+ return comparer(x, y);
27
+ },
28
+ };
29
+ }
30
+
31
+ export function ComparisonIdentity_Structural<T>(): IComparer<T> {
32
+ return ComparisonIdentity_FromFunction<T>(compare);
33
+ }
34
+
@@ -0,0 +1,37 @@
1
+ import { class_type, TypeInfo } from "./Reflection.js";
2
+ import { addRangeInPlace } from "./Array.js";
3
+ import { toList } from "./Seq.js";
4
+ import { FSharpList } from "./List.js";
5
+
6
+ export class ListCollector$1<T> {
7
+ readonly collector: T[];
8
+ constructor() {
9
+ this.collector = [];
10
+ }
11
+ }
12
+
13
+ export function ListCollector$1_$reflection(gen0: TypeInfo): TypeInfo {
14
+ return class_type("Microsoft.FSharp.Core.CompilerServices.ListCollector`1", [gen0], ListCollector$1);
15
+ }
16
+
17
+ export function ListCollector$1_$ctor<T>(): ListCollector$1<T> {
18
+ return new ListCollector$1();
19
+ }
20
+
21
+ export function ListCollector$1__Add_2B595<T>(this$: ListCollector$1<T>, value: T): void {
22
+ void (this$.collector.push(value));
23
+ }
24
+
25
+ export function ListCollector$1__AddMany_BB573A<T>(this$: ListCollector$1<T>, values: Iterable<T>): void {
26
+ addRangeInPlace(values, this$.collector);
27
+ }
28
+
29
+ export function ListCollector$1__AddManyAndClose_BB573A<T>(this$: ListCollector$1<T>, values: Iterable<T>): FSharpList<T> {
30
+ addRangeInPlace(values, this$.collector);
31
+ return toList<T>(this$.collector);
32
+ }
33
+
34
+ export function ListCollector$1__Close<T>(this$: ListCollector$1<T>): FSharpList<T> {
35
+ return toList<T>(this$.collector);
36
+ }
37
+
package/FSharp.Core.ts ADDED
@@ -0,0 +1,86 @@
1
+ import { IDisposable, disposeSafe, defaultOf, IEqualityComparer, IComparer, structuralHash, equals } from "./Util.js";
2
+ import { int32 } from "./Int32.js";
3
+ import { HashIdentity_Structural, ComparisonIdentity_Structural } from "./FSharp.Collections.js";
4
+ import { Option } from "./Option.js";
5
+ import { StringBuilder, StringBuilder__Append_Z721C83C5 } from "./System.Text.js";
6
+
7
+ export const LanguagePrimitives_GenericEqualityComparer: any = {
8
+ "System.Collections.IEqualityComparer.Equals541DA560"(x: any, y: any): boolean {
9
+ return equals(x, y);
10
+ },
11
+ "System.Collections.IEqualityComparer.GetHashCode4E60E31B"(x_1: any): int32 {
12
+ return structuralHash(x_1);
13
+ },
14
+ };
15
+
16
+ export const LanguagePrimitives_GenericEqualityERComparer: any = {
17
+ "System.Collections.IEqualityComparer.Equals541DA560"(x: any, y: any): boolean {
18
+ return equals(x, y);
19
+ },
20
+ "System.Collections.IEqualityComparer.GetHashCode4E60E31B"(x_1: any): int32 {
21
+ return structuralHash(x_1);
22
+ },
23
+ };
24
+
25
+ export function LanguagePrimitives_FastGenericComparer<T>(): IComparer<T> {
26
+ return ComparisonIdentity_Structural<T>();
27
+ }
28
+
29
+ export function LanguagePrimitives_FastGenericComparerFromTable<T>(): IComparer<T> {
30
+ return ComparisonIdentity_Structural<T>();
31
+ }
32
+
33
+ export function LanguagePrimitives_FastGenericEqualityComparer<T>(): IEqualityComparer<T> {
34
+ return HashIdentity_Structural<T>();
35
+ }
36
+
37
+ export function LanguagePrimitives_FastGenericEqualityComparerFromTable<T>(): IEqualityComparer<T> {
38
+ return HashIdentity_Structural<T>();
39
+ }
40
+
41
+ export function Operators_Failure(message: string): Error {
42
+ return new Error(message);
43
+ }
44
+
45
+ export function Operators_FailurePattern(exn: Error): Option<string> {
46
+ return exn.message;
47
+ }
48
+
49
+ export function Operators_NullArg<$a>(x: string): $a {
50
+ throw new Error(x);
51
+ }
52
+
53
+ export function Operators_Using<T extends IDisposable, R>(resource: T, action: ((arg0: T) => R)): R {
54
+ try {
55
+ return action(resource);
56
+ }
57
+ finally {
58
+ if (equals(resource, defaultOf())) {
59
+ }
60
+ else {
61
+ let copyOfStruct: T = resource;
62
+ disposeSafe(copyOfStruct);
63
+ }
64
+ }
65
+ }
66
+
67
+ export function Operators_Lock<$a, $b>(_lockObj: $a, action: (() => $b)): $b {
68
+ return action();
69
+ }
70
+
71
+ export function ExtraTopLevelOperators_LazyPattern<$a>(input: any): $a {
72
+ return input.Value;
73
+ }
74
+
75
+ export function PrintfModule_PrintFormatToStringBuilderThen<$a, $b>(continuation: (() => $a), builder: StringBuilder, format: any): $b {
76
+ return format.cont((s: string): $a => {
77
+ StringBuilder__Append_Z721C83C5(builder, s);
78
+ return continuation();
79
+ });
80
+ }
81
+
82
+ export function PrintfModule_PrintFormatToStringBuilder<$a>(builder: StringBuilder, format: any): $a {
83
+ return PrintfModule_PrintFormatToStringBuilderThen<void, $a>((): void => {
84
+ }, builder, format);
85
+ }
86
+
package/Global.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { int32 } from "./Int32.js";
2
+
3
+ export interface Fable_Core_IGenericAdder$1<T> {
4
+ Add(arg0: T, arg1: T): T,
5
+ GetZero(): T
6
+ }
7
+
8
+ export interface Fable_Core_IGenericAverager$1<T> {
9
+ Add(arg0: T, arg1: T): T,
10
+ DivideByInt(arg0: T, arg1: int32): T,
11
+ GetZero(): T
12
+ }
13
+
14
+ export interface Fable_Core_Symbol_wellknown {
15
+ [Symbol.toStringTag]: string
16
+ }
17
+
18
+ export interface Fable_Core_IJsonSerializable {
19
+ toJSON(): any
20
+ }
21
+
22
+ export const SR_indexOutOfBounds = "The index was outside the range of elements in the collection.";
23
+
24
+ export const SR_inputWasEmpty = "Collection was empty.";
25
+
26
+ export const SR_inputMustBeNonNegative = "The input must be non-negative.";
27
+
28
+ export const SR_inputSequenceEmpty = "The input sequence was empty.";
29
+
30
+ export const SR_inputSequenceTooLong = "The input sequence contains more than one element.";
31
+
32
+ export const SR_keyNotFoundAlt = "An index satisfying the predicate was not found in the collection.";
33
+
34
+ export const SR_differentLengths = "The collections had different lengths.";
35
+
36
+ export const SR_notEnoughElements = "The input sequence has an insufficient number of elements.";
37
+
package/Guid.ts ADDED
@@ -0,0 +1,143 @@
1
+ import { trim } from "./String.js";
2
+ import { FSharpRef } from "./Types.js";
3
+
4
+ // RFC 4122 compliant. From https://stackoverflow.com/a/13653180/3922220
5
+ // const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
6
+ // Relax GUID parsing, see #1637
7
+ const guidRegex = /^[\(\{]{0,2}[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}[\)\}]{0,2}$/;
8
+ const guidRegexNoHyphen = /^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/;
9
+ const guidRegexHex = /^\{0x[0-9a-f]{8},(0x[0-9a-f]{4},){2}\{(0x[0-9a-f]{2},){7}0x[0-9a-f]{2}\}\}$/;
10
+ const guidHexCaptures = /^([0-9a-f]{8})-(([0-9a-f]{4})-)(([0-9a-f]{4})-)([0-9a-f]{2})([0-9a-f]{2})-([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/;
11
+
12
+ export function toString(str: string, format?: string, _provider?: any) {
13
+ if (format && format?.length > 0) {
14
+ switch (format) {
15
+ case "N":
16
+ return str.replace(/-/g, '');
17
+ case "D":
18
+ return str;
19
+ case "B":
20
+ return "{" + str + "}";
21
+ case "P":
22
+ return "(" + str + ")";
23
+ case "X":
24
+ return str.replace(guidHexCaptures, "{0x$1,0x$3,0x$5,{0x$6,0x$7,0x$8,0x$9,0x$10,0x$11,0x$12,0x$13}}");
25
+ default:
26
+ throw new Error("Unrecognized Guid print format");
27
+ }
28
+ }
29
+ else {
30
+ return str;
31
+ }
32
+ }
33
+
34
+ /** Validates UUID as specified in RFC4122 (versions 1-5). */
35
+ export function parse(str: string): string {
36
+ function hyphenateGuid(str: string) {
37
+ return str.replace(guidRegexNoHyphen, "$1-$2-$3-$4-$5");
38
+ }
39
+
40
+ const wsTrimAndLowered = str.trim().toLowerCase();
41
+
42
+ if (guidRegex.test(wsTrimAndLowered)) {
43
+ return trim(wsTrimAndLowered, "{", "}", "(", ")");
44
+ }
45
+ else if (guidRegexNoHyphen.test(wsTrimAndLowered)) {
46
+ return hyphenateGuid(wsTrimAndLowered);
47
+ }
48
+ else if (guidRegexHex.test(wsTrimAndLowered)) {
49
+ return hyphenateGuid(wsTrimAndLowered.replace(/[\{\},]|0x/g, ''));
50
+ }
51
+ else {
52
+ throw new Error("Guid should contain 32 digits with 4 dashes: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
53
+ }
54
+ }
55
+
56
+ export function tryParse(str: string, defValue: FSharpRef<string>): boolean {
57
+ try {
58
+ defValue.contents = parse(str);
59
+ return true;
60
+ } catch {
61
+ return false;
62
+ }
63
+ }
64
+
65
+ // From https://gist.github.com/LeverOne/1308368
66
+ export function newGuid() {
67
+ let b = "";
68
+ for (let a = 0; a++ < 36;) {
69
+ b += a * 51 & 52
70
+ ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16)
71
+ : "-";
72
+ }
73
+ return b;
74
+ }
75
+
76
+ // Maps for number <-> hex string conversion
77
+ let _convertMapsInitialized = false;
78
+ let _byteToHex: string[];
79
+ let _hexToByte: { [k: string]: number };
80
+
81
+ function initConvertMaps() {
82
+ _byteToHex = new Array(256);
83
+ _hexToByte = {};
84
+ for (let i = 0; i < 256; i++) {
85
+ _byteToHex[i] = (i + 0x100).toString(16).substr(1);
86
+ _hexToByte[_byteToHex[i]] = i;
87
+ }
88
+ _convertMapsInitialized = true;
89
+ }
90
+
91
+ /** Parse a UUID into it's component bytes */
92
+ // Adapted from https://github.com/zefferus/uuid-parse
93
+ export function guidToArray(s: string): number[] {
94
+ if (!_convertMapsInitialized) {
95
+ initConvertMaps();
96
+ }
97
+ let i = 0;
98
+ const buf = new Uint8Array(16);
99
+ s.toLowerCase().replace(/[0-9a-f]{2}/g, ((oct: number) => {
100
+ switch (i) {
101
+ // .NET saves first three byte groups with different endianness
102
+ // See https://stackoverflow.com/a/16722909/3922220
103
+ case 0: case 1: case 2: case 3:
104
+ buf[3 - i++] = _hexToByte[oct];
105
+ break;
106
+ case 4: case 5:
107
+ buf[9 - i++] = _hexToByte[oct];
108
+ break;
109
+ case 6: case 7:
110
+ buf[13 - i++] = _hexToByte[oct];
111
+ break;
112
+ case 8: case 9: case 10: case 11:
113
+ case 12: case 13: case 14: case 15:
114
+ buf[i++] = _hexToByte[oct];
115
+ break;
116
+ }
117
+ }) as any);
118
+ // Zero out remaining bytes if string was short
119
+ while (i < 16) {
120
+ buf[i++] = 0;
121
+ }
122
+ return buf as any as number[];
123
+ }
124
+
125
+ /** Convert UUID byte array into a string */
126
+ export function arrayToGuid(buf: ArrayLike<number>) {
127
+ if (buf.length !== 16) {
128
+ throw new Error("Byte array for GUID must be exactly 16 bytes long");
129
+ }
130
+ if (!_convertMapsInitialized) {
131
+ initConvertMaps();
132
+ }
133
+ const guid =
134
+ _byteToHex[buf[3]] + _byteToHex[buf[2]] +
135
+ _byteToHex[buf[1]] + _byteToHex[buf[0]] + "-" +
136
+ _byteToHex[buf[5]] + _byteToHex[buf[4]] + "-" +
137
+ _byteToHex[buf[7]] + _byteToHex[buf[6]] + "-" +
138
+ _byteToHex[buf[8]] + _byteToHex[buf[9]] + "-" +
139
+ _byteToHex[buf[10]] + _byteToHex[buf[11]] +
140
+ _byteToHex[buf[12]] + _byteToHex[buf[13]] +
141
+ _byteToHex[buf[14]] + _byteToHex[buf[15]];
142
+ return guid;
143
+ }