@fable-org/fable-library-js 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.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { FSharpRef } from "./Types.js";
2
2
  export function tryParse(str, defValue) {
3
- if (str.match(/^\s*true\s*$/i)) {
3
+ if (str != null && str.match(/^\s*true\s*$/i)) {
4
4
  defValue.contents = true;
5
5
  return true;
6
6
  }
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,9 @@
1
+ export declare class ConditionalWeakTable<TKey extends object, TValue> {
2
+ private weakMap;
3
+ delete(key: TKey): boolean;
4
+ get(key: TKey): TValue | undefined;
5
+ has(key: TKey): boolean;
6
+ set(key: TKey, value: TValue): WeakMap<TKey, TValue>;
7
+ clear(): void;
8
+ }
9
+ export default ConditionalWeakTable;
@@ -0,0 +1,21 @@
1
+ export class ConditionalWeakTable {
2
+ constructor() {
3
+ this.weakMap = new WeakMap();
4
+ }
5
+ delete(key) {
6
+ return this.weakMap.delete(key);
7
+ }
8
+ get(key) {
9
+ return this.weakMap.get(key);
10
+ }
11
+ has(key) {
12
+ return this.weakMap.has(key);
13
+ }
14
+ set(key, value) {
15
+ return this.weakMap.set(key, value);
16
+ }
17
+ clear() {
18
+ this.weakMap = new WeakMap();
19
+ }
20
+ }
21
+ export default ConditionalWeakTable;
package/Date.js CHANGED
@@ -655,7 +655,7 @@ export function dayOfYear(d) {
655
655
  }
656
656
  export function add(d, ts) {
657
657
  const newDate = DateTime(d.getTime() + ts, d.kind);
658
- if (d.kind === 2 /* DateKind.Local */) {
658
+ if (d.kind !== 1 /* DateKind.UTC */) {
659
659
  const oldTzOffset = d.getTimezoneOffset();
660
660
  const newTzOffset = newDate.getTimezoneOffset();
661
661
  return oldTzOffset !== newTzOffset
package/MapUtil.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { IMap, ISet } from "./Util.js";
1
+ import { IMap, IMapOrWeakMap, ISet } from "./Util.js";
2
2
  import { FSharpRef } from "./Types.js";
3
3
  export declare function keyValueList(fields: Iterable<any>, caseRule?: number): {
4
4
  [k: string]: any;
5
5
  };
6
6
  export declare function containsValue<K, V>(v: V, map: IMap<K, V>): boolean;
7
- export declare function tryGetValue<K, V>(map: IMap<K, V>, key: K, defaultValue: FSharpRef<V>): boolean;
7
+ export declare function tryGetValue<K, V>(map: IMapOrWeakMap<K, V>, key: K, defaultValue: FSharpRef<V>): boolean;
8
8
  export declare function addToSet<T>(v: T, set: ISet<T>): boolean;
9
- export declare function addToDict<K, V>(dict: IMap<K, V>, k: K, v: V): void;
9
+ export declare function tryAddToDict<K, V>(dict: IMapOrWeakMap<K, V>, k: K, v: V): boolean;
10
+ export declare function addToDict<K, V>(dict: IMapOrWeakMap<K, V>, k: K, v: V): void;
10
11
  export declare function getItemFromDict<K, V>(map: IMap<K, V>, key: K): V;
12
+ export declare function getItemFromDictOrCreate<K, V>(map: IMapOrWeakMap<K, V>, key: K, createValue: (key: K) => V): V;
package/MapUtil.js CHANGED
@@ -96,6 +96,13 @@ export function addToSet(v, set) {
96
96
  set.add(v);
97
97
  return true;
98
98
  }
99
+ export function tryAddToDict(dict, k, v) {
100
+ if (dict.has(k)) {
101
+ return false;
102
+ }
103
+ dict.set(k, v);
104
+ return true;
105
+ }
99
106
  export function addToDict(dict, k, v) {
100
107
  if (dict.has(k)) {
101
108
  throw new Error("An item with the same key has already been added. Key: " + k);
@@ -110,3 +117,11 @@ export function getItemFromDict(map, key) {
110
117
  throw new Error(`The given key '${key}' was not present in the dictionary.`);
111
118
  }
112
119
  }
120
+ export function getItemFromDictOrCreate(map, key, createValue) {
121
+ if (map.has(key)) {
122
+ return map.get(key);
123
+ }
124
+ const value = createValue(key);
125
+ map.set(key, value);
126
+ return value;
127
+ }
package/Util.d.ts CHANGED
@@ -93,13 +93,16 @@ export interface ISet<T> {
93
93
  keys(): Iterable<T>;
94
94
  values(): Iterable<T>;
95
95
  }
96
- export interface IMap<K, V> {
97
- clear(): void;
96
+ export interface IMapOrWeakMap<K, V> {
98
97
  delete(key: K): boolean;
99
- forEach(callbackfn: (value: V, key: K, map: IMap<K, V>) => void, thisArg?: any): void;
100
98
  get(key: K): V | undefined;
101
99
  has(key: K): boolean;
100
+ set(key: K, value: V): IMapOrWeakMap<K, V>;
101
+ }
102
+ export interface IMap<K, V> extends IMapOrWeakMap<K, V> {
103
+ clear(): void;
102
104
  set(key: K, value: V): IMap<K, V>;
105
+ forEach(callbackfn: (value: V, key: K, map: IMap<K, V>) => void, thisArg?: any): void;
103
106
  readonly size: number;
104
107
  [Symbol.iterator](): Iterator<[K, V]>;
105
108
  entries(): Iterable<[K, V]>;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "private": false,
4
4
  "type": "module",
5
5
  "name": "@fable-org/fable-library-js",
6
- "version": "1.2.0",
6
+ "version": "1.4.0",
7
7
  "description": "Core library used by F# projects compiled with fable.io",
8
8
  "author": "Fable Contributors",
9
9
  "license": "MIT",