@fable-org/fable-library-ts 2.3.0 → 2.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/CHANGELOG.md +14 -1
- package/Date.ts +1 -1
- package/Environment.ts +7 -0
- package/File.ts +35 -0
- package/Path.ts +37 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
last_commit_released:
|
|
2
|
+
last_commit_released: 7f915f1dd66b9a5fbbd56f858b07d39b98519b65
|
|
3
3
|
updaters:
|
|
4
4
|
- package.json:
|
|
5
5
|
file: package.json
|
|
@@ -15,6 +15,19 @@ All notable changes to this project will be documented in this file.
|
|
|
15
15
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
16
16
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
17
17
|
|
|
18
|
+
## 2.4.0 - 2026-07-05
|
|
19
|
+
|
|
20
|
+
### 🚀 Features
|
|
21
|
+
|
|
22
|
+
* *(js/ts)* Add `System.IO.Path` and `System.IO.File` API support ([ec99fac5](https://github.com/fable-compiler/Fable/commit/ec99fac5fd7a9428ee54f66f878ef4edad0904cb))
|
|
23
|
+
* *(js/ts/python)* Add Environment and Console.Error support ([6e082f95](https://github.com/fable-compiler/Fable/commit/6e082f955140676da3388a43b55378ea4ad20f1c))
|
|
24
|
+
|
|
25
|
+
### 🐞 Bug Fixes
|
|
26
|
+
|
|
27
|
+
* *(js/ts)* DateTime.ToString() and %A are now consistent across all DateTimeKind values (#4714) ([de98b0e4](https://github.com/fable-compiler/Fable/commit/de98b0e466c8824b0ba8b941d20efae70d232abb))
|
|
28
|
+
|
|
29
|
+
<strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/c977d78b39225a51c7bd051a1fe363ed0ccbe201..7f915f1dd66b9a5fbbd56f858b07d39b98519b65)</small></strong>
|
|
30
|
+
|
|
18
31
|
## 2.3.0 - 2026-06-30
|
|
19
32
|
|
|
20
33
|
### 🚀 Features
|
package/Date.ts
CHANGED
|
@@ -509,7 +509,7 @@ function dateToString_Y(date: IDateTime) {
|
|
|
509
509
|
function dateToStringWithKind(date: IDateTime, format?: string) {
|
|
510
510
|
const utc = date.kind === DateTimeKind.Utc;
|
|
511
511
|
if (typeof format !== "string") {
|
|
512
|
-
return
|
|
512
|
+
return dateToString_d(date) + " " + dateToString_T(date);
|
|
513
513
|
} else if (format.length === 1) {
|
|
514
514
|
switch (format) {
|
|
515
515
|
case "D": return dateToString_D(date);
|
package/Environment.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// process.env is Node-specific; there is no browser equivalent for reading
|
|
2
|
+
// environment variables, so this only works when running under Node.
|
|
3
|
+
declare const process: { env: Record<string, string | undefined> };
|
|
4
|
+
|
|
5
|
+
export function getEnvironmentVariable(name: string): string {
|
|
6
|
+
return process.env[name] as string;
|
|
7
|
+
}
|
package/File.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// This library doesn't depend on @types/node (to stay browser-compatible),
|
|
2
|
+
// so this Node.js built-in import can't be type-checked; the exported
|
|
3
|
+
// functions below still declare their own types for callers to rely on.
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { MutableArray } from "./Util.ts";
|
|
7
|
+
|
|
8
|
+
// byte[] is represented as a plain JS/TS array of numbers, not a typed array
|
|
9
|
+
// (see e.g. BitConverter.ts), so convert the Buffer returned by readFileSync.
|
|
10
|
+
export function readAllBytes(path: string): number[] {
|
|
11
|
+
return Array.from(readFileSync(path));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function readAllLines(path: string): string[] {
|
|
15
|
+
const lines = readFileSync(path, "utf8").split(/\r\n|\r|\n/);
|
|
16
|
+
|
|
17
|
+
if (lines[lines.length - 1] === "") {
|
|
18
|
+
lines.pop();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return lines;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function readAllText(path: string): string {
|
|
25
|
+
return readFileSync(path, "utf8");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function writeAllBytes(path: string, bytes: MutableArray<number>): void {
|
|
29
|
+
// Convert back from the plain array representation to a typed array Node's fs accepts.
|
|
30
|
+
writeFileSync(path, Uint8Array.from(bytes));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function writeAllLines(path: string, lines: MutableArray<string>): void {
|
|
34
|
+
writeFileSync(path, lines.join("\n"));
|
|
35
|
+
}
|
package/Path.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// This library doesn't depend on @types/node (to stay browser-compatible),
|
|
2
|
+
// so these Node.js built-in imports can't be type-checked; the exported
|
|
3
|
+
// functions below still declare their own types for callers to rely on.
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { basename, extname, join } from "node:path";
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import { writeFileSync } from "node:fs";
|
|
10
|
+
|
|
11
|
+
// Mirrors the format of .NET's Path.GetRandomFileName(): 8 random hex chars,
|
|
12
|
+
// a dot, then 3 more random hex chars.
|
|
13
|
+
export function getRandomFileName(): string {
|
|
14
|
+
const nameBytes = new Uint8Array(4);
|
|
15
|
+
crypto.getRandomValues(nameBytes);
|
|
16
|
+
const name = Array.from(nameBytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
17
|
+
|
|
18
|
+
const extBytes = new Uint8Array(2);
|
|
19
|
+
crypto.getRandomValues(extBytes);
|
|
20
|
+
const ext = Array.from(extBytes, (b) => b.toString(16).padStart(2, "0")).join("").slice(0, 3);
|
|
21
|
+
|
|
22
|
+
return `${name}.${ext}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getFileNameWithoutExtension(path: string): string {
|
|
26
|
+
return basename(path, extname(path));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function hasExtension(path: string): boolean {
|
|
30
|
+
return extname(path) !== "";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getTempFileName(): string {
|
|
34
|
+
const path = join(tmpdir(), getRandomFileName());
|
|
35
|
+
writeFileSync(path, "");
|
|
36
|
+
return path;
|
|
37
|
+
}
|
package/package.json
CHANGED