@fable-org/fable-library-ts 1.2.0 → 1.4.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/Boolean.ts +2 -2
- package/CHANGELOG.md +10 -0
- package/ConditionalWeakTable.ts +26 -0
- package/Date.ts +1 -1
- package/MapUtil.ts +20 -3
- package/Util.ts +8 -3
- package/package.json +1 -1
package/Boolean.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { FSharpRef } from "./Types.js"
|
|
2
2
|
|
|
3
3
|
export function tryParse(str: string, defValue: FSharpRef<boolean>): boolean {
|
|
4
|
-
if (str.match(/^\s*true\s*$/i)) {
|
|
4
|
+
if (str != null && str.match(/^\s*true\s*$/i)) {
|
|
5
5
|
defValue.contents = true;
|
|
6
6
|
return true;
|
|
7
|
-
} else if (str.match(/^\s*false\s*$/i)) {
|
|
7
|
+
} else if (str != null && str.match(/^\s*false\s*$/i)) {
|
|
8
8
|
defValue.contents = false;
|
|
9
9
|
return true;
|
|
10
10
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
9
|
|
|
10
|
+
## 1.4.0 - 2024-03-18
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
* [JS/TS] Add `ConditionalWeakTable` (by @chkn)
|
|
15
|
+
|
|
16
|
+
## 1.3.0 - 2024-03-18
|
|
17
|
+
|
|
18
|
+
* [JS/TS] `Boolean.tryParse` should not crash on `null` string (@goswinr)
|
|
19
|
+
|
|
10
20
|
## 1.2.0 - 2024-03-01
|
|
11
21
|
|
|
12
22
|
### Fixed
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
export class ConditionalWeakTable<TKey extends object, TValue> {
|
|
3
|
+
private weakMap: WeakMap<TKey, TValue> = new WeakMap<TKey, TValue>();
|
|
4
|
+
|
|
5
|
+
public delete(key: TKey) {
|
|
6
|
+
return this.weakMap.delete(key);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public get(key: TKey) {
|
|
10
|
+
return this.weakMap.get(key);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public has(key: TKey) {
|
|
14
|
+
return this.weakMap.has(key);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public set(key: TKey, value: TValue) {
|
|
18
|
+
return this.weakMap.set(key, value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public clear() {
|
|
22
|
+
this.weakMap = new WeakMap<TKey, TValue>();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default ConditionalWeakTable;
|
package/Date.ts
CHANGED
|
@@ -710,7 +710,7 @@ export function dayOfYear(d: IDateTime) {
|
|
|
710
710
|
|
|
711
711
|
export function add(d: IDateTime, ts: number) {
|
|
712
712
|
const newDate = DateTime(d.getTime() + ts, d.kind);
|
|
713
|
-
if (d.kind
|
|
713
|
+
if (d.kind !== DateKind.UTC) {
|
|
714
714
|
const oldTzOffset = d.getTimezoneOffset();
|
|
715
715
|
const newTzOffset = newDate.getTimezoneOffset();
|
|
716
716
|
return oldTzOffset !== newTzOffset
|
package/MapUtil.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { equals, IMap, ISet } from "./Util.js";
|
|
1
|
+
import { equals, IMap, IMapOrWeakMap, ISet } from "./Util.js";
|
|
2
2
|
import { FSharpRef, Union } from "./Types.js";
|
|
3
3
|
|
|
4
4
|
const CaseRules = {
|
|
@@ -88,7 +88,7 @@ export function containsValue<K, V>(v: V, map: IMap<K, V>) {
|
|
|
88
88
|
return false;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
export function tryGetValue<K, V>(map:
|
|
91
|
+
export function tryGetValue<K, V>(map: IMapOrWeakMap<K, V>, key: K, defaultValue: FSharpRef<V>): boolean {
|
|
92
92
|
if (map.has(key)) {
|
|
93
93
|
defaultValue.contents = map.get(key) as V;
|
|
94
94
|
return true;
|
|
@@ -104,7 +104,15 @@ export function addToSet<T>(v: T, set: ISet<T>) {
|
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
export function
|
|
107
|
+
export function tryAddToDict<K, V>(dict: IMapOrWeakMap<K, V>, k: K, v: V) {
|
|
108
|
+
if (dict.has(k)) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
dict.set(k, v);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function addToDict<K, V>(dict: IMapOrWeakMap<K, V>, k: K, v: V) {
|
|
108
116
|
if (dict.has(k)) {
|
|
109
117
|
throw new Error("An item with the same key has already been added. Key: " + k);
|
|
110
118
|
}
|
|
@@ -118,3 +126,12 @@ export function getItemFromDict<K, V>(map: IMap<K, V>, key: K) {
|
|
|
118
126
|
throw new Error(`The given key '${key}' was not present in the dictionary.`);
|
|
119
127
|
}
|
|
120
128
|
}
|
|
129
|
+
|
|
130
|
+
export function getItemFromDictOrCreate<K, V>(map: IMapOrWeakMap<K, V>, key: K, createValue: (key: K) => V) {
|
|
131
|
+
if (map.has(key)) {
|
|
132
|
+
return map.get(key) as V;
|
|
133
|
+
}
|
|
134
|
+
const value = createValue(key);
|
|
135
|
+
map.set(key, value);
|
|
136
|
+
return value;
|
|
137
|
+
}
|
package/Util.ts
CHANGED
|
@@ -183,13 +183,18 @@ export interface ISet<T> {
|
|
|
183
183
|
values(): Iterable<T>;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
export interface
|
|
187
|
-
clear(): void;
|
|
186
|
+
export interface IMapOrWeakMap<K, V> {
|
|
188
187
|
delete(key: K): boolean;
|
|
189
|
-
forEach(callbackfn: (value: V, key: K, map: IMap<K, V>) => void, thisArg?: any): void;
|
|
190
188
|
get(key: K): V | undefined;
|
|
191
189
|
has(key: K): boolean;
|
|
190
|
+
set(key: K, value: V): IMapOrWeakMap<K, V>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface IMap<K, V> extends IMapOrWeakMap<K, V> {
|
|
194
|
+
clear(): void;
|
|
192
195
|
set(key: K, value: V): IMap<K, V>;
|
|
196
|
+
|
|
197
|
+
forEach(callbackfn: (value: V, key: K, map: IMap<K, V>) => void, thisArg?: any): void;
|
|
193
198
|
readonly size: number;
|
|
194
199
|
|
|
195
200
|
[Symbol.iterator](): Iterator<[K, V]>;
|
package/package.json
CHANGED