@fable-org/fable-library-js 2.10.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Array.js +272 -167
- package/BigInt.js +18 -6
- package/CHANGELOG.md +42 -1
- package/Date.js +1 -1
- package/Decimal.js +16 -46
- package/Double.js +25 -10
- package/FSharp.Core.js +7 -1
- package/Global.js +1 -1
- package/Int32.js +10 -1
- package/List.js +226 -156
- package/Long.js +7 -2
- package/Map.js +46 -39
- package/MutableMap.js +76 -96
- package/MutableSet.js +58 -80
- package/NumberStyles.js +56 -0
- package/Numeric.js +10 -4
- package/Random.js +3 -4
- package/Range.js +4 -3
- package/RegExp.js +3 -2
- package/Seq.js +132 -64
- package/Seq2.js +4 -8
- package/Set.js +64 -57
- package/String.js +71 -23
- package/System.Collections.Generic.js +3 -2
- package/System.Text.js +2 -2
- package/System.js +5 -5
- package/TimeOnly.js +1 -1
- package/Types.js +25 -10
- package/Util.js +91 -48
- package/package.json +1 -1
package/MutableSet.js
CHANGED
|
@@ -4,13 +4,14 @@ import { item as item_1, setItem } from "./Array.js";
|
|
|
4
4
|
import { some } from "./Option.js";
|
|
5
5
|
import { FSharpRef } from "./Types.js";
|
|
6
6
|
import { class_type } from "./Reflection.js";
|
|
7
|
-
import { getItemFromDict
|
|
7
|
+
import { getItemFromDict } from "./MapUtil.js";
|
|
8
8
|
export class HashSet {
|
|
9
9
|
constructor(items, comparer) {
|
|
10
10
|
const this$ = new FSharpRef(defaultOf());
|
|
11
11
|
this.comparer = comparer;
|
|
12
12
|
this$.contents = this;
|
|
13
13
|
this.hashMap = (new Map([]));
|
|
14
|
+
this.count = 0;
|
|
14
15
|
this["init@9"] = 1;
|
|
15
16
|
const enumerator = getEnumerator(items);
|
|
16
17
|
try {
|
|
@@ -116,39 +117,39 @@ export function HashSet_$reflection(gen0) {
|
|
|
116
117
|
export function HashSet_$ctor_Z6150332D(items, comparer) {
|
|
117
118
|
return new HashSet(items, comparer);
|
|
118
119
|
}
|
|
119
|
-
function
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
let outArg = defaultOf();
|
|
123
|
-
matchValue = [tryGetValue(this$.hashMap, h, new FSharpRef(() => outArg, (v) => {
|
|
124
|
-
outArg = v;
|
|
125
|
-
})), outArg];
|
|
126
|
-
if (matchValue[0]) {
|
|
127
|
-
return [true, h, matchValue[1].findIndex((v_1) => this$.comparer.Equals(k, v_1))];
|
|
120
|
+
function HashSet__TryFindBucket_Z524259A4(this$, h) {
|
|
121
|
+
if (this$.hashMap.has(h)) {
|
|
122
|
+
return getItemFromDict(this$.hashMap, h);
|
|
128
123
|
}
|
|
129
124
|
else {
|
|
130
|
-
return
|
|
125
|
+
return undefined;
|
|
131
126
|
}
|
|
132
127
|
}
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
let
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
matchResult = 1;
|
|
128
|
+
function HashSet__FindIndex_Z142BBCA7(this$, k, bucket) {
|
|
129
|
+
let i = 0;
|
|
130
|
+
let found = -1;
|
|
131
|
+
while ((found < 0) && (i < bucket.length)) {
|
|
132
|
+
if (this$.comparer.Equals(k, item_1(i, bucket))) {
|
|
133
|
+
found = (i | 0);
|
|
142
134
|
}
|
|
135
|
+
i = ((i + 1) | 0);
|
|
143
136
|
}
|
|
144
|
-
|
|
145
|
-
|
|
137
|
+
return found | 0;
|
|
138
|
+
}
|
|
139
|
+
function HashSet__TryFind_2B595(this$, k) {
|
|
140
|
+
const matchValue = HashSet__TryFindBucket_Z524259A4(this$, this$.comparer.GetHashCode(k));
|
|
141
|
+
if (matchValue == null) {
|
|
142
|
+
return undefined;
|
|
146
143
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
else {
|
|
145
|
+
const bucket = matchValue;
|
|
146
|
+
const i = HashSet__FindIndex_Z142BBCA7(this$, k, bucket) | 0;
|
|
147
|
+
if (i > -1) {
|
|
148
|
+
return some(item_1(i, bucket));
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
151
|
return undefined;
|
|
152
|
+
}
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
export function HashSet__get_Comparer(this$) {
|
|
@@ -156,82 +157,59 @@ export function HashSet__get_Comparer(this$) {
|
|
|
156
157
|
}
|
|
157
158
|
export function HashSet__Clear(this$) {
|
|
158
159
|
this$.hashMap.clear();
|
|
160
|
+
this$.count = 0;
|
|
159
161
|
}
|
|
160
162
|
export function HashSet__get_Count(this$) {
|
|
161
|
-
|
|
162
|
-
let enumerator = getEnumerator(this$.hashMap.values());
|
|
163
|
-
try {
|
|
164
|
-
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
165
|
-
const items = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
166
|
-
count = ((count + items.length) | 0);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
finally {
|
|
170
|
-
disposeSafe(enumerator);
|
|
171
|
-
}
|
|
172
|
-
return count | 0;
|
|
163
|
+
return this$.count | 0;
|
|
173
164
|
}
|
|
174
165
|
export function HashSet__Add_2B595(this$, k) {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
166
|
+
const h = this$.comparer.GetHashCode(k) | 0;
|
|
167
|
+
const matchValue = HashSet__TryFindBucket_Z524259A4(this$, h);
|
|
168
|
+
if (matchValue == null) {
|
|
169
|
+
this$.hashMap.set(h, [k]);
|
|
170
|
+
this$.count = ((this$.count + 1) | 0);
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const bucket = matchValue;
|
|
175
|
+
if (HashSet__FindIndex_Z142BBCA7(this$, k, bucket) > -1) {
|
|
178
176
|
return false;
|
|
179
177
|
}
|
|
180
178
|
else {
|
|
181
|
-
void (
|
|
179
|
+
void (bucket.push(k));
|
|
180
|
+
this$.count = ((this$.count + 1) | 0);
|
|
182
181
|
return true;
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
|
-
else {
|
|
186
|
-
this$.hashMap.set(matchValue[1], [k]);
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
184
|
}
|
|
190
185
|
export function HashSet__Contains_2B595(this$, k) {
|
|
191
|
-
const matchValue =
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (matchValue[2] > -1) {
|
|
195
|
-
matchResult = 0;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
matchResult = 1;
|
|
199
|
-
}
|
|
186
|
+
const matchValue = HashSet__TryFindBucket_Z524259A4(this$, this$.comparer.GetHashCode(k));
|
|
187
|
+
if (matchValue == null) {
|
|
188
|
+
return false;
|
|
200
189
|
}
|
|
201
190
|
else {
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
switch (matchResult) {
|
|
205
|
-
case 0:
|
|
206
|
-
return true;
|
|
207
|
-
default:
|
|
208
|
-
return false;
|
|
191
|
+
return HashSet__FindIndex_Z142BBCA7(this$, k, matchValue) > -1;
|
|
209
192
|
}
|
|
210
193
|
}
|
|
211
194
|
export function HashSet__Remove_2B595(this$, k) {
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
if (matchValue
|
|
215
|
-
|
|
216
|
-
matchResult = 0;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
matchResult = 1;
|
|
220
|
-
}
|
|
195
|
+
const h = this$.comparer.GetHashCode(k) | 0;
|
|
196
|
+
const matchValue = HashSet__TryFindBucket_Z524259A4(this$, h);
|
|
197
|
+
if (matchValue == null) {
|
|
198
|
+
return false;
|
|
221
199
|
}
|
|
222
200
|
else {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
this$.hashMap.delete(h_1);
|
|
201
|
+
const bucket = matchValue;
|
|
202
|
+
const i = HashSet__FindIndex_Z142BBCA7(this$, k, bucket) | 0;
|
|
203
|
+
if (i > -1) {
|
|
204
|
+
bucket.splice(i, 1);
|
|
205
|
+
this$.count = ((this$.count - 1) | 0);
|
|
206
|
+
if (bucket.length === 0) {
|
|
207
|
+
this$.hashMap.delete(h);
|
|
231
208
|
}
|
|
232
209
|
return true;
|
|
233
210
|
}
|
|
234
|
-
|
|
211
|
+
else {
|
|
235
212
|
return false;
|
|
213
|
+
}
|
|
236
214
|
}
|
|
237
215
|
}
|
package/NumberStyles.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Exception } from "./Util.js";
|
|
2
|
+
export const NumberStyles = {
|
|
3
|
+
None: 0,
|
|
4
|
+
AllowLeadingWhite: 1,
|
|
5
|
+
AllowTrailingWhite: 2,
|
|
6
|
+
AllowLeadingSign: 4,
|
|
7
|
+
AllowTrailingSign: 8,
|
|
8
|
+
AllowParentheses: 16,
|
|
9
|
+
AllowDecimalPoint: 32,
|
|
10
|
+
AllowThousands: 64,
|
|
11
|
+
AllowExponent: 128,
|
|
12
|
+
AllowHexSpecifier: 512,
|
|
13
|
+
Integer: 7,
|
|
14
|
+
Number: 111,
|
|
15
|
+
Float: 167,
|
|
16
|
+
};
|
|
17
|
+
// The digits of a number string once white space, sign and parentheses are stripped.
|
|
18
|
+
// .NET allows group separators anywhere after the first digit of the integral part, even repeated.
|
|
19
|
+
function digitsPattern(style) {
|
|
20
|
+
const integral = style & NumberStyles.AllowThousands ? "\\d+(?:,\\d*)*" : "\\d+";
|
|
21
|
+
const point = style & NumberStyles.AllowDecimalPoint ? "(?:\\.\\d*)?" : "";
|
|
22
|
+
const leadingPoint = style & NumberStyles.AllowDecimalPoint ? "|\\.\\d+" : "";
|
|
23
|
+
const exponent = style & NumberStyles.AllowExponent ? "(?:[eE][+-]?\\d+)?" : "";
|
|
24
|
+
return new RegExp(`^(?:${integral}${point}${leadingPoint})${exponent}$`);
|
|
25
|
+
}
|
|
26
|
+
// Returns undefined when the string does not have the format allowed by the style
|
|
27
|
+
export function splitNumber(str, style) {
|
|
28
|
+
if (style & NumberStyles.AllowHexSpecifier) {
|
|
29
|
+
throw new Exception("The number style AllowHexSpecifier is not supported on floating point data types.");
|
|
30
|
+
}
|
|
31
|
+
// .NET ignores trailing NULs and its white space is only [\t\n\v\f\r ]
|
|
32
|
+
let s = str.replace(/\0+$/, "");
|
|
33
|
+
if (style & NumberStyles.AllowLeadingWhite) {
|
|
34
|
+
s = s.replace(/^[\t-\r ]+/, "");
|
|
35
|
+
}
|
|
36
|
+
if (style & NumberStyles.AllowTrailingWhite) {
|
|
37
|
+
s = s.replace(/[\t-\r ]+$/, "");
|
|
38
|
+
}
|
|
39
|
+
let negative = false;
|
|
40
|
+
if (style & NumberStyles.AllowParentheses && s.startsWith("(") && s.endsWith(")")) {
|
|
41
|
+
s = s.slice(1, -1);
|
|
42
|
+
negative = true;
|
|
43
|
+
}
|
|
44
|
+
if (style & NumberStyles.AllowLeadingSign && /^[+-]/.test(s)) {
|
|
45
|
+
negative = s[0] === "-" ? !negative : negative;
|
|
46
|
+
s = s.slice(1);
|
|
47
|
+
}
|
|
48
|
+
else if (style & NumberStyles.AllowTrailingSign && /[+-]$/.test(s)) {
|
|
49
|
+
negative = s[s.length - 1] === "-" ? !negative : negative;
|
|
50
|
+
s = s.slice(0, -1);
|
|
51
|
+
}
|
|
52
|
+
if (!digitsPattern(style).test(s)) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return { digits: s.replace(/,/g, ""), negative };
|
|
56
|
+
}
|
package/Numeric.js
CHANGED
|
@@ -98,15 +98,21 @@ export function toExponential(x, dp) {
|
|
|
98
98
|
return x[symbol]().toExponential(dp);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
export function
|
|
101
|
+
export function toRadix(x, radix) {
|
|
102
102
|
if (typeof x === "number") {
|
|
103
|
-
return (Number(x) >>> 0).toString(
|
|
103
|
+
return (Number(x) >>> 0).toString(radix);
|
|
104
104
|
}
|
|
105
105
|
else if (typeof x === "bigint") {
|
|
106
106
|
// TODO: properly handle other bit sizes
|
|
107
|
-
return BigInt.asUintN(64, x).toString(
|
|
107
|
+
return BigInt.asUintN(64, x).toString(radix);
|
|
108
108
|
}
|
|
109
|
-
else {
|
|
109
|
+
else if (radix === 16) {
|
|
110
110
|
return x[symbol]().toHex();
|
|
111
111
|
}
|
|
112
|
+
else {
|
|
113
|
+
return String(x);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function toHex(x) {
|
|
117
|
+
return toRadix(x, 16);
|
|
112
118
|
}
|
package/Random.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ArgumentNullException_$ctor_Z721C83C5, ArgumentOutOfRangeException_$ctor_Z721C83C5 } from "./System.js";
|
|
2
|
-
import { Operators_IsNull } from "./FSharp.Core.js";
|
|
3
2
|
import { class_type } from "./Reflection.js";
|
|
4
3
|
import { fromFloat64, op_Addition, toInt32_unchecked, toFloat64, compare, fromInt32, toInt64_unchecked } from "./BigInt.js";
|
|
5
4
|
import { item, setItem } from "./Array.js";
|
|
@@ -13,7 +12,7 @@ function Native_randomNext(minValue, maxValue) {
|
|
|
13
12
|
return Math.floor(Math.random() * (maxValue - minValue)) + minValue;
|
|
14
13
|
}
|
|
15
14
|
function Native_randomBytes(buffer) {
|
|
16
|
-
if (
|
|
15
|
+
if (buffer == null) {
|
|
17
16
|
throw ArgumentNullException_$ctor_Z721C83C5("buffer");
|
|
18
17
|
}
|
|
19
18
|
for (let i = 0; i < buffer.length; i += 6) {
|
|
@@ -113,11 +112,11 @@ export class Seeded {
|
|
|
113
112
|
}
|
|
114
113
|
NextBytes(buffer) {
|
|
115
114
|
const this$ = this;
|
|
116
|
-
if (
|
|
115
|
+
if (buffer == null) {
|
|
117
116
|
throw ArgumentNullException_$ctor_Z721C83C5("buffer");
|
|
118
117
|
}
|
|
119
118
|
for (let i = 0; i <= (buffer.length - 1); i++) {
|
|
120
|
-
setItem(buffer, i, (Seeded__InternalSample(this$) % (~~255 + 1)) & 0xFF);
|
|
119
|
+
setItem(buffer, i, ~~(Seeded__InternalSample(this$) % (~~255 + 1)) & 0xFF);
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
}
|
package/Range.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compare } from "./Util.js";
|
|
2
|
+
import { Operators_InvalidArg } from "./FSharp.Core.js";
|
|
2
3
|
import { unfold, delay } from "./Seq.js";
|
|
3
4
|
import { toUInt64_unchecked, toInt64_unchecked, op_Addition, fromZero } from "./BigInt.js";
|
|
4
5
|
import { op_Addition as op_Addition_1, fromParts } from "./Decimal.js";
|
|
5
6
|
export function makeRangeStepFunction(step, stop, zero, add) {
|
|
6
7
|
const stepComparedWithZero = compare(step, zero) | 0;
|
|
7
8
|
if (stepComparedWithZero === 0) {
|
|
8
|
-
throw
|
|
9
|
+
throw Operators_InvalidArg("step", "The step of a range cannot be zero.");
|
|
9
10
|
}
|
|
10
11
|
const stepGreaterThanZero = stepComparedWithZero > 0;
|
|
11
12
|
return (x) => {
|
|
@@ -36,7 +37,7 @@ export function rangeChar(start, stop) {
|
|
|
36
37
|
const intStop = ~~stop.charCodeAt(0) | 0;
|
|
37
38
|
return delay(() => unfold((i) => {
|
|
38
39
|
if (i <= intStop) {
|
|
39
|
-
return [String.fromCharCode(i & 0xFFFF), i + 1];
|
|
40
|
+
return [String.fromCharCode(~~i & 0xFFFF), i + 1];
|
|
40
41
|
}
|
|
41
42
|
else {
|
|
42
43
|
return undefined;
|
package/RegExp.js
CHANGED
|
@@ -6,8 +6,9 @@ export function create(pattern, options = 0) {
|
|
|
6
6
|
// * Compiled: 0x0008 (ignored)
|
|
7
7
|
// * Singleline: 0x0010
|
|
8
8
|
// * ECMAScript: 0x0100 (ignored)
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
// * NonBacktracking: 0x0400 (ignored)
|
|
10
|
+
if ((options & ~(1 ^ 2 ^ 8 ^ 16 ^ 256 ^ 1024)) !== 0) {
|
|
11
|
+
throw new Exception("RegexOptions only supports: IgnoreCase, Multiline, Compiled, Singleline, ECMAScript and NonBacktracking");
|
|
11
12
|
}
|
|
12
13
|
// Set always global and unicode flags for compatibility with dotnet, see #2925
|
|
13
14
|
let flags = "gu";
|