@magnusopera/fscript 0.86.1 → 0.86.2
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.
- package/dist/FScript.Language/Ast.js +2 -2
- package/dist/FScript.Language/BuiltinFunctions.js +31 -19
- package/dist/FScript.Language/BuiltinSignatures.js +6 -6
- package/dist/FScript.Language/BuiltinTypes.js +1 -1
- package/dist/FScript.Language/Error.js +2 -2
- package/dist/FScript.Language/Eval.js +11 -11
- package/dist/FScript.Language/Execution.js +6 -6
- package/dist/FScript.Language/ExportSignatures.js +5 -5
- package/dist/FScript.Language/HostInterop.js +8 -8
- package/dist/FScript.Language/IncludeResolver.js +10 -10
- package/dist/FScript.Language/Interactive.js +7 -7
- package/dist/FScript.Language/Lexer.js +9 -9
- package/dist/FScript.Language/Parser.js +10 -10
- package/dist/FScript.Language/Pretty.js +4 -4
- package/dist/FScript.Language/Span.js +2 -2
- package/dist/FScript.Language/TaskFunctions.js +2 -2
- package/dist/FScript.Language/TaskSharingAnalysis.js +17 -17
- package/dist/FScript.Language/Token.js +2 -2
- package/dist/FScript.Language/TypeInfer.js +12 -12
- package/dist/FScript.Language/Types.js +8 -8
- package/dist/FScript.Language/Value.js +2 -2
- package/dist/Library.js +13 -13
- package/dist/fable_modules/fable-library-js.5.24.0/Async.js +363 -0
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/AsyncBuilder.js +70 -10
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/CHANGELOG.md +90 -1
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/CollectionUtil.js +10 -16
- package/dist/fable_modules/fable-library-js.5.24.0/DateOnlyTemporal.js +146 -0
- package/dist/fable_modules/fable-library-js.5.24.0/DateTimeFormat.js +523 -0
- package/dist/fable_modules/fable-library-js.5.24.0/DateTimeOffsetTemporal.js +283 -0
- package/dist/fable_modules/fable-library-js.5.24.0/DateTimeTemporal.js +243 -0
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Decimal.js +100 -11
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Encoding.js +23 -16
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Guid.js +3 -1
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/MailboxProcessor.js +23 -3
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/MutableMap.js +5 -1
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/MutableSet.js +5 -1
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Numeric.js +38 -1
- package/dist/fable_modules/fable-library-js.5.24.0/Stopwatch.js +65 -0
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/String.js +43 -9
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/System.Text.js +9 -9
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Task.js +22 -0
- package/dist/fable_modules/fable-library-js.5.24.0/TimeOnlyTemporal.js +142 -0
- package/dist/fable_modules/fable-library-js.5.24.0/TimeSpanTemporal.js +259 -0
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Util.js +15 -3
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/big.d.ts +1 -0
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/lib/big.js +111 -64
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/package.json +1 -1
- package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/quotation.js +47 -0
- package/dist/fable_modules/project_cracked.json +1 -1
- package/package.json +1 -1
- package/dist/fable_modules/fable-library-js.5.13.0/Async.js +0 -163
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Array.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/BigInt.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/BitConverter.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Boolean.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Char.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Choice.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/ConditionalWeakTable.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Date.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/DateOffset.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/DateOnly.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Directory.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Double.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Environment.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Event.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/FSharp.Collections.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/FSharp.Core.CompilerServices.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/FSharp.Core.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/File.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Global.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Int32.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/List.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Long.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Map.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/MapUtil.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Native.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Observable.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Option.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Path.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/README.md +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Random.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Range.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Reflection.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/RegExp.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Result.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Seq.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Seq2.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Set.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/System.Collections.Generic.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/System.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/TaskBuilder.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/TimeOnly.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/TimeSpan.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Timer.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Types.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Unicode.13.0.0.js +0 -0
- /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Uri.js +0 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { toInt64 } from "./BigInt.js";
|
|
2
|
+
import { Exception, padWithZeros } from "./Util.js";
|
|
3
|
+
export const Duration = Temporal.Duration;
|
|
4
|
+
// The generic equality/comparison/hashing helpers in Util.ts dispatch at runtime
|
|
5
|
+
// on .NET-style Equals/CompareTo/GetHashCode methods. Attach them so TimeSpan
|
|
6
|
+
// also works in generic contexts: records, tuples, erased generics, etc.
|
|
7
|
+
const proto = Temporal.Duration.prototype;
|
|
8
|
+
proto.Equals = function (other) { return Temporal.Duration.compare(this, other) === 0; };
|
|
9
|
+
proto.CompareTo = function (other) { return Temporal.Duration.compare(this, other); };
|
|
10
|
+
proto.GetHashCode = function () { return hash(this); };
|
|
11
|
+
// Lets String.Format format this value without String.ts importing this module (see String.ts)
|
|
12
|
+
proto[Symbol.for("Fable.DateTimeFormattable")] = function (format) { return toString(this, format); };
|
|
13
|
+
const nsPerMillisecond = 1000000n;
|
|
14
|
+
const nsPerSecond = 1000000000n;
|
|
15
|
+
const nsPerMinute = 60000000000n;
|
|
16
|
+
const nsPerHour = 3600000000000n;
|
|
17
|
+
const nsPerDay = 86400000000000n;
|
|
18
|
+
export function totalNanoseconds(ts) {
|
|
19
|
+
return BigInt(ts.days) * nsPerDay
|
|
20
|
+
+ BigInt(ts.hours) * nsPerHour
|
|
21
|
+
+ BigInt(ts.minutes) * nsPerMinute
|
|
22
|
+
+ BigInt(ts.seconds) * nsPerSecond
|
|
23
|
+
+ BigInt(ts.milliseconds) * nsPerMillisecond
|
|
24
|
+
+ BigInt(ts.microseconds) * 1000n
|
|
25
|
+
+ BigInt(ts.nanoseconds);
|
|
26
|
+
}
|
|
27
|
+
function fromNanoseconds(totalNs) {
|
|
28
|
+
const negative = totalNs < 0n;
|
|
29
|
+
// A .NET TimeSpan is a whole number of 100ns ticks, so anything finer than a
|
|
30
|
+
// tick is dropped (toward zero, as .NET does) rather than carried in the
|
|
31
|
+
// Duration's nanosecond field — otherwise values that cannot exist in .NET
|
|
32
|
+
// would leak out of Parse/FromMilliseconds/arithmetic.
|
|
33
|
+
let n = (negative ? -totalNs : totalNs) / 100n * 100n;
|
|
34
|
+
const days = Number(n / nsPerDay);
|
|
35
|
+
n %= nsPerDay;
|
|
36
|
+
const hours = Number(n / nsPerHour);
|
|
37
|
+
n %= nsPerHour;
|
|
38
|
+
const minutes = Number(n / nsPerMinute);
|
|
39
|
+
n %= nsPerMinute;
|
|
40
|
+
const seconds = Number(n / nsPerSecond);
|
|
41
|
+
n %= nsPerSecond;
|
|
42
|
+
const milliseconds = Number(n / nsPerMillisecond);
|
|
43
|
+
n %= nsPerMillisecond;
|
|
44
|
+
const microseconds = Number(n / 1000n);
|
|
45
|
+
n %= 1000n;
|
|
46
|
+
const d = new Temporal.Duration(0, 0, 0, days, hours, minutes, seconds, milliseconds, microseconds, Number(n));
|
|
47
|
+
return negative ? d.negated() : d;
|
|
48
|
+
}
|
|
49
|
+
// Converts a possibly fractional unit count into an exact nanosecond amount,
|
|
50
|
+
// keeping the integer part exact for the full Int64 tick range.
|
|
51
|
+
function unitToNanoseconds(value, nsPerUnit) {
|
|
52
|
+
const whole = Math.trunc(value);
|
|
53
|
+
const frac = value - whole;
|
|
54
|
+
return BigInt(whole) * nsPerUnit + BigInt(Math.round(frac * Number(nsPerUnit)));
|
|
55
|
+
}
|
|
56
|
+
export function create(d = 0, h = 0, m = 0, s = 0, ms = 0, us = 0) {
|
|
57
|
+
switch (arguments.length) {
|
|
58
|
+
case 1:
|
|
59
|
+
// ticks
|
|
60
|
+
return fromTicks(arguments[0]);
|
|
61
|
+
case 3:
|
|
62
|
+
// h,m,s
|
|
63
|
+
d = 0, h = arguments[0], m = arguments[1], s = arguments[2], ms = 0;
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
// d,h,m,s,ms,us
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return fromNanoseconds(unitToNanoseconds(d, nsPerDay) + unitToNanoseconds(h, nsPerHour) + unitToNanoseconds(m, nsPerMinute)
|
|
70
|
+
+ unitToNanoseconds(s, nsPerSecond) + unitToNanoseconds(ms, nsPerMillisecond) + unitToNanoseconds(us, 1000n));
|
|
71
|
+
}
|
|
72
|
+
export function fromTicks(ticks) {
|
|
73
|
+
return fromNanoseconds(BigInt(ticks) * 100n);
|
|
74
|
+
}
|
|
75
|
+
export function zero() {
|
|
76
|
+
return new Temporal.Duration();
|
|
77
|
+
}
|
|
78
|
+
const ticksPerUnit = {
|
|
79
|
+
days: 864000000000,
|
|
80
|
+
hours: 36000000000,
|
|
81
|
+
minutes: 600000000,
|
|
82
|
+
seconds: 10000000,
|
|
83
|
+
milliseconds: 10000,
|
|
84
|
+
};
|
|
85
|
+
// The DateTime/DateTimeOffset/TimeOnly Add* members take a double and are
|
|
86
|
+
// tick-precise in .NET: the value is scaled to ticks and rounded, so
|
|
87
|
+
// AddSeconds(0.0000001) moves exactly one tick and AddDays(1.5) exactly 36 hours.
|
|
88
|
+
// Temporal's own `add({ days: 1.5 })` rejects non-integers, so the scaling has to
|
|
89
|
+
// happen here.
|
|
90
|
+
export function fromUnits(value, unit) {
|
|
91
|
+
return fromTicks(BigInt(Math.round(value * ticksPerUnit[unit])));
|
|
92
|
+
}
|
|
93
|
+
export function fromDays(d, h = 0, m = 0n, s = 0n, ms = 0n) {
|
|
94
|
+
return create(d, h, Number(m), Number(s), Number(ms));
|
|
95
|
+
}
|
|
96
|
+
export function fromHours(h, m = 0n, s = 0n, ms = 0n) {
|
|
97
|
+
return create(0, h, Number(m), Number(s), Number(ms));
|
|
98
|
+
}
|
|
99
|
+
export function fromMinutes(m, s = 0n, ms = 0n) {
|
|
100
|
+
return create(0, 0, Number(m), Number(s), Number(ms));
|
|
101
|
+
}
|
|
102
|
+
export function fromSeconds(s, ms = 0n) {
|
|
103
|
+
return create(0, 0, 0, Number(s), Number(ms));
|
|
104
|
+
}
|
|
105
|
+
export function fromMilliseconds(ms) {
|
|
106
|
+
return fromNanoseconds(unitToNanoseconds(Number(ms), nsPerMillisecond));
|
|
107
|
+
}
|
|
108
|
+
export function ticks(ts) {
|
|
109
|
+
return toInt64(totalNanoseconds(ts) / 100n);
|
|
110
|
+
}
|
|
111
|
+
// .NET computes each total as (double)Ticks / TicksPerUnit; match that exactly
|
|
112
|
+
// (Temporal's own .total() balances differently and can be 1 ULP off).
|
|
113
|
+
function totalTicks(ts) {
|
|
114
|
+
return Number(totalNanoseconds(ts) / 100n);
|
|
115
|
+
}
|
|
116
|
+
export function totalDays(ts) {
|
|
117
|
+
return totalTicks(ts) / 864000000000;
|
|
118
|
+
}
|
|
119
|
+
export function totalHours(ts) {
|
|
120
|
+
return totalTicks(ts) / 36000000000;
|
|
121
|
+
}
|
|
122
|
+
export function totalMinutes(ts) {
|
|
123
|
+
return totalTicks(ts) / 600000000;
|
|
124
|
+
}
|
|
125
|
+
export function totalSeconds(ts) {
|
|
126
|
+
return totalTicks(ts) / 10000000;
|
|
127
|
+
}
|
|
128
|
+
export function totalMilliseconds(ts) {
|
|
129
|
+
return totalTicks(ts) / 10000;
|
|
130
|
+
}
|
|
131
|
+
export function negate(ts) {
|
|
132
|
+
return ts.negated();
|
|
133
|
+
}
|
|
134
|
+
export function add(ts1, ts2) {
|
|
135
|
+
return fromNanoseconds(totalNanoseconds(ts1) + totalNanoseconds(ts2));
|
|
136
|
+
}
|
|
137
|
+
export function subtract(ts1, ts2) {
|
|
138
|
+
return fromNanoseconds(totalNanoseconds(ts1) - totalNanoseconds(ts2));
|
|
139
|
+
}
|
|
140
|
+
// .NET scales the tick count as a double and rounds: `new TimeSpan((long)Math
|
|
141
|
+
// .Round(Ticks * factor))`. Scaling ticks rather than nanoseconds keeps the
|
|
142
|
+
// magnitude — and so the rounding — identical to .NET's.
|
|
143
|
+
export function multiply(ts, factor) {
|
|
144
|
+
return fromTicks(BigInt(Math.round(Number(ticks(ts)) * factor)));
|
|
145
|
+
}
|
|
146
|
+
export function divide(ts, factor) {
|
|
147
|
+
return fromTicks(BigInt(Math.round(Number(ticks(ts)) / factor)));
|
|
148
|
+
}
|
|
149
|
+
export function divideByTimeSpan(ts, other) {
|
|
150
|
+
return Number(ticks(ts)) / Number(ticks(other));
|
|
151
|
+
}
|
|
152
|
+
export const op_Addition = add;
|
|
153
|
+
export const op_Subtraction = subtract;
|
|
154
|
+
export const op_Multiply = multiply;
|
|
155
|
+
export const op_UnaryNegation = negate;
|
|
156
|
+
export function compare(x, y) {
|
|
157
|
+
return Temporal.Duration.compare(x, y);
|
|
158
|
+
}
|
|
159
|
+
export const compareTo = compare;
|
|
160
|
+
export function equals(x, y) {
|
|
161
|
+
return Temporal.Duration.compare(x, y) === 0;
|
|
162
|
+
}
|
|
163
|
+
export function hash(ts) {
|
|
164
|
+
return Number(totalNanoseconds(ts) % 2147483647n);
|
|
165
|
+
}
|
|
166
|
+
export function duration(ts) {
|
|
167
|
+
return ts.abs();
|
|
168
|
+
}
|
|
169
|
+
export function toString(ts, format = "c", _provider) {
|
|
170
|
+
if (["c", "g", "G"].indexOf(format) === -1) {
|
|
171
|
+
throw new Exception("Custom formats are not supported");
|
|
172
|
+
}
|
|
173
|
+
const d = Math.abs(ts.days);
|
|
174
|
+
const h = Math.abs(ts.hours);
|
|
175
|
+
const m = Math.abs(ts.minutes);
|
|
176
|
+
const s = Math.abs(ts.seconds);
|
|
177
|
+
const ticks = Math.abs(ts.milliseconds) * 10000
|
|
178
|
+
+ Math.abs(ts.microseconds) * 10
|
|
179
|
+
+ Math.trunc(Math.abs(ts.nanoseconds) / 100);
|
|
180
|
+
const sign = ts.sign < 0 ? "-" : "";
|
|
181
|
+
const days = d === 0 && format !== "G" ? "" : format === "c" ? d + "." : d + ":";
|
|
182
|
+
const time = `${format === "g" ? h : padWithZeros(h, 2)}:${padWithZeros(m, 2)}:${padWithZeros(s, 2)}`;
|
|
183
|
+
// .NET prints seven tick digits for "c" and "G", trims trailing zeros for "g", and omits a zero fraction for "c" and "g".
|
|
184
|
+
const fraction = format === "g"
|
|
185
|
+
? (ticks === 0 ? "" : "." + padWithZeros(ticks, 7).replace(/0+$/, ""))
|
|
186
|
+
: (ticks === 0 && format === "c" ? "" : "." + padWithZeros(ticks, 7));
|
|
187
|
+
return `${sign}${days}${time}${fraction}`;
|
|
188
|
+
}
|
|
189
|
+
export function parse(str) {
|
|
190
|
+
const firstDot = str.search("\\.");
|
|
191
|
+
const firstColon = str.search("\\:");
|
|
192
|
+
if (firstDot === -1 && firstColon === -1) { // There is only a day ex: 4
|
|
193
|
+
const d = parseInt(str, 0);
|
|
194
|
+
if (isNaN(d)) {
|
|
195
|
+
throw new Exception(`String '${str}' was not recognized as a valid TimeSpan.`);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
return create(d, 0, 0, 0, 0);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (firstColon > 0) { // process time part
|
|
202
|
+
// WIP: (-?)(((\d+)\.)?([0-9]|0[0-9]|1[0-9]|2[0-3]):(\d+)(:\d+(\.\d{1,7})?)?|\d+(?:(?!\.)))
|
|
203
|
+
const r = /^(-?)((\d+)\.)?(?:0*)([0-9]|0[0-9]|1[0-9]|2[0-3]):(?:0*)([0-5][0-9]|[0-9])(:(?:0*)([0-5][0-9]|[0-9]))?\.?(\d+)?$/.exec(str);
|
|
204
|
+
if (r != null && r[4] != null && r[5] != null) {
|
|
205
|
+
let d = 0;
|
|
206
|
+
let ms = 0;
|
|
207
|
+
let s = 0;
|
|
208
|
+
const sign = r[1] != null && r[1] === "-" ? -1 : 1;
|
|
209
|
+
const h = +r[4];
|
|
210
|
+
const m = +r[5];
|
|
211
|
+
if (r[3] != null) {
|
|
212
|
+
d = +r[3];
|
|
213
|
+
}
|
|
214
|
+
if (r[7] != null) {
|
|
215
|
+
s = +r[7];
|
|
216
|
+
}
|
|
217
|
+
if (r[8] != null) {
|
|
218
|
+
// Depending on the number of decimals passed, we need to adapt the numbers
|
|
219
|
+
switch (r[8].length) {
|
|
220
|
+
case 1:
|
|
221
|
+
ms = +r[8] * 100;
|
|
222
|
+
break;
|
|
223
|
+
case 2:
|
|
224
|
+
ms = +r[8] * 10;
|
|
225
|
+
break;
|
|
226
|
+
case 3:
|
|
227
|
+
ms = +r[8];
|
|
228
|
+
break;
|
|
229
|
+
case 4:
|
|
230
|
+
ms = +r[8] / 10;
|
|
231
|
+
break;
|
|
232
|
+
case 5:
|
|
233
|
+
ms = +r[8] / 100;
|
|
234
|
+
break;
|
|
235
|
+
case 6:
|
|
236
|
+
ms = +r[8] / 1000;
|
|
237
|
+
break;
|
|
238
|
+
case 7:
|
|
239
|
+
ms = +r[8] / 10000;
|
|
240
|
+
break;
|
|
241
|
+
default:
|
|
242
|
+
throw new Exception(`String '${str}' was not recognized as a valid TimeSpan.`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const ts = create(d, h, m, s, ms);
|
|
246
|
+
return sign < 0 ? negate(ts) : ts;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
throw new Exception(`String '${str}' was not recognized as a valid TimeSpan.`);
|
|
250
|
+
}
|
|
251
|
+
export function tryParse(v, defValue) {
|
|
252
|
+
try {
|
|
253
|
+
defValue.contents = parse(v);
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -559,11 +559,23 @@ export function count(col) {
|
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
561
|
export function clear(col) {
|
|
562
|
-
if (
|
|
563
|
-
col.
|
|
562
|
+
if (Array.isArray(col)) {
|
|
563
|
+
col.length = 0;
|
|
564
|
+
}
|
|
565
|
+
else if (ArrayBuffer.isView(col)) {
|
|
566
|
+
// TODO: throw for typed arrays?
|
|
567
|
+
}
|
|
568
|
+
else if (typeof col.clear === "function") {
|
|
569
|
+
col.clear(); // map, set
|
|
570
|
+
}
|
|
571
|
+
else if (typeof col["System.Collections.Generic.ICollection`1.Clear"] === "function") {
|
|
572
|
+
col["System.Collections.Generic.ICollection`1.Clear"](); // collection
|
|
573
|
+
}
|
|
574
|
+
else if (typeof col["System.Collections.IList.Clear"] === "function") {
|
|
575
|
+
col["System.Collections.IList.Clear"](); // collection
|
|
564
576
|
}
|
|
565
577
|
else {
|
|
566
|
-
|
|
578
|
+
// TODO: throw for other collections?
|
|
567
579
|
}
|
|
568
580
|
}
|
|
569
581
|
const curried = new WeakMap();
|
|
@@ -202,6 +202,7 @@ export interface Big extends CustomNumeric {
|
|
|
202
202
|
* @throws `!Big.RM!` if rm is invalid.
|
|
203
203
|
*/
|
|
204
204
|
round(dp?: number, rm?: RoundingMode): Big;
|
|
205
|
+
prec(sd: number, rm?: RoundingMode): Big;
|
|
205
206
|
/**
|
|
206
207
|
* Returns a Big number whose value is the square root of this Big number.
|
|
207
208
|
*
|
|
@@ -67,7 +67,6 @@ function _Big_() {
|
|
|
67
67
|
x.s = n.s;
|
|
68
68
|
x.e = n.e;
|
|
69
69
|
x.c = n.c.slice();
|
|
70
|
-
normalize(x);
|
|
71
70
|
}
|
|
72
71
|
else {
|
|
73
72
|
if (typeof n !== 'string') {
|
|
@@ -91,14 +90,6 @@ function _Big_() {
|
|
|
91
90
|
Big.strict = STRICT;
|
|
92
91
|
return Big;
|
|
93
92
|
}
|
|
94
|
-
function normalize(x) {
|
|
95
|
-
// x = round(x, DP, 0);
|
|
96
|
-
if (x.c.length > 1 && !x.c[0]) {
|
|
97
|
-
let i = x.c.findIndex(x => x);
|
|
98
|
-
x.c = x.c.slice(i);
|
|
99
|
-
x.e = x.e - i;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
93
|
/*
|
|
103
94
|
* Parse the number or string value passed to a Big constructor.
|
|
104
95
|
*
|
|
@@ -128,15 +119,13 @@ function parse(x, n) {
|
|
|
128
119
|
e = n.length;
|
|
129
120
|
}
|
|
130
121
|
nl = n.length;
|
|
131
|
-
// Determine leading zeros
|
|
132
|
-
for (i = 0; i <
|
|
122
|
+
// Determine leading zeros.
|
|
123
|
+
for (i = 0; i < nl && n.charAt(i) == '0';)
|
|
133
124
|
++i;
|
|
134
|
-
// original version (ignores decimal point).
|
|
135
|
-
// // Determine leading zeros.
|
|
136
|
-
// for (i = 0; i < nl && n.charAt(i) == '0';) ++i;
|
|
137
125
|
if (i == nl) {
|
|
138
|
-
// Zero.
|
|
139
|
-
x.c = [
|
|
126
|
+
// Zero, keeping the scale: 0.00 is c = [0], e = -2.
|
|
127
|
+
x.c = [0];
|
|
128
|
+
x.e = nl > e ? e - nl : 0;
|
|
140
129
|
}
|
|
141
130
|
else {
|
|
142
131
|
x.e = e - i - 1;
|
|
@@ -150,8 +139,7 @@ function parse(x, n) {
|
|
|
150
139
|
// // Convert string to array of digits without leading/trailing zeros.
|
|
151
140
|
// for (e = 0; i <= nl;) x.c[e++] = +n.charAt(i++);
|
|
152
141
|
}
|
|
153
|
-
|
|
154
|
-
return x;
|
|
142
|
+
return fit(x);
|
|
155
143
|
}
|
|
156
144
|
/*
|
|
157
145
|
* Round Big x to a maximum of sd significant digits using rounding mode rm.
|
|
@@ -171,17 +159,11 @@ function round(x, sd, rm, more) {
|
|
|
171
159
|
if (sd < 1) {
|
|
172
160
|
more =
|
|
173
161
|
rm === 3 && (more || !!xc[0]) || sd === 0 && (rm === 1 && xc[0] >= 5 ||
|
|
174
|
-
rm === 2 && (xc[0] > 5 || xc[0] === 5 && (more || xc
|
|
162
|
+
rm === 2 && (xc[0] > 5 || xc[0] === 5 && (more || xc.some((d, i) => i > 0 && d))));
|
|
175
163
|
xc.length = 1;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
xc[0] = 1;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
// Zero.
|
|
183
|
-
xc[0] = x.e = 0;
|
|
184
|
-
}
|
|
164
|
+
// 1, 0.1, 0.01, 0.001, 0.0001 etc., or zero at the same place.
|
|
165
|
+
x.e = x.e - sd + 1;
|
|
166
|
+
xc[0] = more ? 1 : 0;
|
|
185
167
|
}
|
|
186
168
|
else if (sd < xc.length) {
|
|
187
169
|
// xc[sd] is the digit after the digit that may be rounded up.
|
|
@@ -189,7 +171,7 @@ function round(x, sd, rm, more) {
|
|
|
189
171
|
more =
|
|
190
172
|
rm === 1 && xc[sd] >= 5 ||
|
|
191
173
|
rm === 2 && (xc[sd] > 5 || xc[sd] === 5 &&
|
|
192
|
-
(more || xc
|
|
174
|
+
(more || xc.some((d, i) => i > sd && d) || xc[sd - 1] & 1)) ||
|
|
193
175
|
rm === 3 && (more || !isZero);
|
|
194
176
|
// Remove any digits after the required precision.
|
|
195
177
|
xc.length = sd--;
|
|
@@ -204,12 +186,60 @@ function round(x, sd, rm, more) {
|
|
|
204
186
|
}
|
|
205
187
|
}
|
|
206
188
|
}
|
|
207
|
-
// Remove trailing zeros.
|
|
208
|
-
for (sd = xc.length; !xc[--sd];)
|
|
209
|
-
xc.pop();
|
|
210
189
|
}
|
|
211
190
|
return x;
|
|
212
191
|
}
|
|
192
|
+
// Largest System.Decimal mantissa, 2^96 - 1.
|
|
193
|
+
var MAX_MANTISSA = '79228162514264337593543950335'.split('').map(Number), OVERFLOW = 'Value was either too large or too small for a Decimal.';
|
|
194
|
+
/*
|
|
195
|
+
* Return the number of decimal places of Big x.
|
|
196
|
+
*/
|
|
197
|
+
function scaleOf(x) {
|
|
198
|
+
return x.c.length - x.e - 1;
|
|
199
|
+
}
|
|
200
|
+
/*
|
|
201
|
+
* Pad Big x with trailing zeros up to dp decimal places.
|
|
202
|
+
*/
|
|
203
|
+
function padScale(x, dp) {
|
|
204
|
+
if (!x.c[0]) {
|
|
205
|
+
x.e = Math.min(x.e, -dp);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
for (; scaleOf(x) < dp;)
|
|
209
|
+
x.c.push(0);
|
|
210
|
+
}
|
|
211
|
+
return x;
|
|
212
|
+
}
|
|
213
|
+
/*
|
|
214
|
+
* Return true if the digits c, padded with zeros to the length of MAX_MANTISSA, exceed it.
|
|
215
|
+
*/
|
|
216
|
+
function exceedsMax(c) {
|
|
217
|
+
for (var i = 0; i < MAX_MANTISSA.length; i++) {
|
|
218
|
+
var d = i < c.length ? c[i] : 0;
|
|
219
|
+
if (d !== MAX_MANTISSA[i])
|
|
220
|
+
return d > MAX_MANTISSA[i];
|
|
221
|
+
}
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
/*
|
|
225
|
+
* Round Big x half to even so that it fits a System.Decimal: at most Big.DP decimal places
|
|
226
|
+
* and a mantissa no larger than MAX_MANTISSA. Throws when no decimal place is left to drop.
|
|
227
|
+
*/
|
|
228
|
+
function fit(x) {
|
|
229
|
+
var scale = scaleOf(x), dp = Math.min(scale, Big.DP, Big.DP - x.e);
|
|
230
|
+
if (x.e > Big.DP)
|
|
231
|
+
throw Error(OVERFLOW);
|
|
232
|
+
if (dp < scale)
|
|
233
|
+
round(x, x.e + 1 + dp, 2);
|
|
234
|
+
if (x.e > Big.DP)
|
|
235
|
+
throw Error(OVERFLOW);
|
|
236
|
+
// Both the value and the mantissa itself must not exceed MAX_MANTISSA.
|
|
237
|
+
if (x.e === Big.DP && exceedsMax(x.c))
|
|
238
|
+
throw Error(OVERFLOW);
|
|
239
|
+
if (x.c.length === MAX_MANTISSA.length && exceedsMax(x.c))
|
|
240
|
+
round(x, x.c.length - 1, 2);
|
|
241
|
+
return x;
|
|
242
|
+
}
|
|
213
243
|
/*
|
|
214
244
|
* Return a string representing the value of Big x in normal or exponential notation.
|
|
215
245
|
* Handles P.toExponential, P.toFixed, P.toJSON, P.toPrecision, P.toString and P.valueOf.
|
|
@@ -218,6 +248,8 @@ function stringify(x, doExponential, isNonzero) {
|
|
|
218
248
|
var e = x.e, s = x.c.join(''), n = s.length;
|
|
219
249
|
// Exponential notation?
|
|
220
250
|
if (doExponential) {
|
|
251
|
+
if (!x.c[0])
|
|
252
|
+
e = 0;
|
|
221
253
|
s = s.charAt(0) + (n > 1 ? '.' + s.slice(1) : '') + (e < 0 ? 'e' : 'e+') + e;
|
|
222
254
|
// Normal notation.
|
|
223
255
|
}
|
|
@@ -289,20 +321,31 @@ P.cmp = function (y) {
|
|
|
289
321
|
* if necessary, to a maximum of Big.DP decimal places using rounding mode Big.RM.
|
|
290
322
|
*/
|
|
291
323
|
P.div = function (y) {
|
|
292
|
-
var Big = this.constructor,
|
|
293
|
-
b = y.c, // divisor
|
|
294
|
-
k = x.s == y.s ? 1 : -1, dp = Big.DP;
|
|
324
|
+
var Big = this.constructor, dp = Big.DP;
|
|
295
325
|
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
296
326
|
throw Error(INVALID_DP);
|
|
297
327
|
}
|
|
328
|
+
return divide(new Big(this), new Big(y), dp, 2);
|
|
329
|
+
};
|
|
330
|
+
/*
|
|
331
|
+
* Return Big x divided by Big y to dp decimal places using rounding mode rm.
|
|
332
|
+
* Both are modified.
|
|
333
|
+
*/
|
|
334
|
+
function divide(x, y, dp, rm) {
|
|
335
|
+
var a = x.c, // dividend
|
|
336
|
+
b = y.c, // divisor
|
|
337
|
+
k = x.s == y.s ? 1 : -1;
|
|
298
338
|
// Divisor is zero?
|
|
299
339
|
if (!b[0]) {
|
|
300
340
|
throw Error(DIV_BY_ZERO);
|
|
301
341
|
}
|
|
342
|
+
// Scale of the exact quotient is at least the scale of x less the scale of y.
|
|
343
|
+
var minScale = Math.max(0, scaleOf(x) - scaleOf(y));
|
|
302
344
|
// Dividend is 0? Return +-0.
|
|
303
345
|
if (!a[0]) {
|
|
304
346
|
y.s = k;
|
|
305
|
-
y.c = [
|
|
347
|
+
y.c = [0];
|
|
348
|
+
y.e = -minScale;
|
|
306
349
|
return y;
|
|
307
350
|
}
|
|
308
351
|
var bl, bt, n, cmp, ri, bz = b.slice(), ai = bl = b.length, al = a.length, r = a.slice(0, bl), // remainder
|
|
@@ -366,11 +409,20 @@ P.div = function (y) {
|
|
|
366
409
|
q.e--;
|
|
367
410
|
p--;
|
|
368
411
|
}
|
|
412
|
+
var exact = r[0] === UNDEFINED;
|
|
369
413
|
// Round?
|
|
370
414
|
if (qi > p)
|
|
371
|
-
round(q, p,
|
|
415
|
+
round(q, p, rm, !exact);
|
|
416
|
+
fit(q);
|
|
417
|
+
if (!q.c[0]) {
|
|
418
|
+
q.e = 0;
|
|
419
|
+
}
|
|
420
|
+
else if (exact) {
|
|
421
|
+
for (; scaleOf(q) > minScale && !q.c[q.c.length - 1];)
|
|
422
|
+
q.c.pop();
|
|
423
|
+
}
|
|
372
424
|
return q;
|
|
373
|
-
}
|
|
425
|
+
}
|
|
374
426
|
/*
|
|
375
427
|
* Return true if the value of this Big is equal to the value of Big y, otherwise return false.
|
|
376
428
|
*/
|
|
@@ -417,6 +469,7 @@ P.minus = P.sub = function (y) {
|
|
|
417
469
|
var xc = x.c.slice(), xe = x.e, yc = y.c, ye = y.e;
|
|
418
470
|
// Either zero?
|
|
419
471
|
if (!xc[0] || !yc[0]) {
|
|
472
|
+
var dp = Math.max(scaleOf(x), scaleOf(y));
|
|
420
473
|
if (yc[0]) {
|
|
421
474
|
y.s = -b;
|
|
422
475
|
}
|
|
@@ -426,7 +479,7 @@ P.minus = P.sub = function (y) {
|
|
|
426
479
|
else {
|
|
427
480
|
y.s = 1;
|
|
428
481
|
}
|
|
429
|
-
return y;
|
|
482
|
+
return padScale(y, dp);
|
|
430
483
|
}
|
|
431
484
|
// Determine which is the bigger number. Prepend zeros to equalise exponents.
|
|
432
485
|
if (a = xe - ye) {
|
|
@@ -477,9 +530,8 @@ P.minus = P.sub = function (y) {
|
|
|
477
530
|
}
|
|
478
531
|
xc[j] -= yc[j];
|
|
479
532
|
}
|
|
480
|
-
//
|
|
481
|
-
|
|
482
|
-
xc.pop();
|
|
533
|
+
// The result keeps the larger scale.
|
|
534
|
+
var dp = xc.length - ye - 1;
|
|
483
535
|
// Remove leading zeros and adjust exponent accordingly.
|
|
484
536
|
for (; xc[0] === 0;) {
|
|
485
537
|
xc.shift();
|
|
@@ -489,11 +541,12 @@ P.minus = P.sub = function (y) {
|
|
|
489
541
|
// n - n = +0
|
|
490
542
|
y.s = 1;
|
|
491
543
|
// Result must be zero.
|
|
492
|
-
xc = [
|
|
544
|
+
xc = [0];
|
|
545
|
+
ye = -dp;
|
|
493
546
|
}
|
|
494
547
|
y.c = xc;
|
|
495
548
|
y.e = ye;
|
|
496
|
-
return y;
|
|
549
|
+
return fit(y);
|
|
497
550
|
};
|
|
498
551
|
/*
|
|
499
552
|
* Return a new Big whose value is the value of this Big modulo the value of Big y.
|
|
@@ -509,12 +562,7 @@ P.mod = function (y) {
|
|
|
509
562
|
y.s = b;
|
|
510
563
|
if (ygtx)
|
|
511
564
|
return new Big(x);
|
|
512
|
-
|
|
513
|
-
b = Big.RM;
|
|
514
|
-
Big.DP = Big.RM = 0;
|
|
515
|
-
x = x.div(y);
|
|
516
|
-
Big.DP = a;
|
|
517
|
-
Big.RM = b;
|
|
565
|
+
x = divide(x, new Big(y), 0, 0);
|
|
518
566
|
return this.minus(x.times(y));
|
|
519
567
|
};
|
|
520
568
|
/*
|
|
@@ -530,6 +578,7 @@ P.plus = P.add = function (y) {
|
|
|
530
578
|
var xe = x.e, xc = x.c, ye = y.e, yc = y.c;
|
|
531
579
|
// Either zero?
|
|
532
580
|
if (!xc[0] || !yc[0]) {
|
|
581
|
+
var dp = Math.max(scaleOf(x), scaleOf(y));
|
|
533
582
|
if (!yc[0]) {
|
|
534
583
|
if (xc[0]) {
|
|
535
584
|
y = new Big(x);
|
|
@@ -538,7 +587,7 @@ P.plus = P.add = function (y) {
|
|
|
538
587
|
y.s = x.s;
|
|
539
588
|
}
|
|
540
589
|
}
|
|
541
|
-
return y;
|
|
590
|
+
return padScale(y, dp);
|
|
542
591
|
}
|
|
543
592
|
xc = xc.slice();
|
|
544
593
|
// Prepend zeros to equalise exponents.
|
|
@@ -572,12 +621,9 @@ P.plus = P.add = function (y) {
|
|
|
572
621
|
xc.unshift(k);
|
|
573
622
|
++ye;
|
|
574
623
|
}
|
|
575
|
-
// Remove trailing zeros.
|
|
576
|
-
for (e = xc.length; xc[--e] === 0;)
|
|
577
|
-
xc.pop();
|
|
578
624
|
y.c = xc;
|
|
579
625
|
y.e = ye;
|
|
580
|
-
return y;
|
|
626
|
+
return fit(y);
|
|
581
627
|
};
|
|
582
628
|
/*
|
|
583
629
|
* Return a Big whose value is the value of this Big raised to the power n.
|
|
@@ -678,7 +724,9 @@ P.times = P.mul = function (y) {
|
|
|
678
724
|
y.s = x.s == y.s ? 1 : -1;
|
|
679
725
|
// Return signed 0 if either 0.
|
|
680
726
|
if (!xc[0] || !yc[0]) {
|
|
681
|
-
|
|
727
|
+
var dp = scaleOf(x) + scaleOf(y);
|
|
728
|
+
y.c = [0];
|
|
729
|
+
y.e = -dp;
|
|
682
730
|
return y;
|
|
683
731
|
}
|
|
684
732
|
// Initialise exponent of result as x.e + y.e.
|
|
@@ -714,11 +762,8 @@ P.times = P.mul = function (y) {
|
|
|
714
762
|
++y.e;
|
|
715
763
|
else
|
|
716
764
|
c.shift();
|
|
717
|
-
// Remove trailing zeros.
|
|
718
|
-
for (i = c.length; !c[--i];)
|
|
719
|
-
c.pop();
|
|
720
765
|
y.c = c;
|
|
721
|
-
return y;
|
|
766
|
+
return fit(y);
|
|
722
767
|
};
|
|
723
768
|
/*
|
|
724
769
|
* Return a string representing the value of this Big in exponential notation rounded to dp fixed
|
|
@@ -746,11 +791,11 @@ P.toExponential = function (dp, rm) {
|
|
|
746
791
|
* dp? {number} Decimal places: integer, 0 to MAX_DP inclusive.
|
|
747
792
|
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
748
793
|
*
|
|
749
|
-
*
|
|
750
|
-
* (-0).toFixed(
|
|
794
|
+
* Unlike JavaScript, the sign is omitted when the rounded result is zero:
|
|
795
|
+
* (-0.1).toFixed(0) is '0' and (-0.01).toFixed(1) is '0.0', matching .NET.
|
|
751
796
|
*/
|
|
752
797
|
P.toFixed = function (dp, rm) {
|
|
753
|
-
var x = this
|
|
798
|
+
var x = this;
|
|
754
799
|
if (dp !== UNDEFINED) {
|
|
755
800
|
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
756
801
|
throw Error(INVALID_DP);
|
|
@@ -760,7 +805,7 @@ P.toFixed = function (dp, rm) {
|
|
|
760
805
|
for (dp = dp + x.e + 1; x.c.length < dp;)
|
|
761
806
|
x.c.push(0);
|
|
762
807
|
}
|
|
763
|
-
return stringify(x, false, !!
|
|
808
|
+
return stringify(x, false, !!x.c[0]);
|
|
764
809
|
};
|
|
765
810
|
/*
|
|
766
811
|
* Return a string representing the value of this Big.
|
|
@@ -798,6 +843,8 @@ P.toPrecision = function (sd, rm) {
|
|
|
798
843
|
throw Error(INVALID + 'precision');
|
|
799
844
|
}
|
|
800
845
|
x = round(new Big(x), sd, rm);
|
|
846
|
+
if (!x.c[0])
|
|
847
|
+
x.e = 0;
|
|
801
848
|
for (; x.c.length < sd;)
|
|
802
849
|
x.c.push(0);
|
|
803
850
|
}
|