Standard library mappings for TSZig - TypeScript module APIs mapped to Zig equivalents.
tszig-stdlib provides implementations of common TypeScript/Node.js standard library modules using native Zig code. This enables TSZig users to write familiar TypeScript-style code that transpiles to efficient Zig.
| Module | Description | Status |
|---|---|---|
fs |
File system operations | 🔶 In Progress |
path |
Path manipulation | ⏳ Planned |
json |
JSON parsing/stringify | ⏳ Planned |
math |
Math functions | ⏳ Planned |
date |
Date/time utilities | ⏳ Planned |
buffer |
Buffer operations | ⏳ Planned |
crypto |
Cryptographic utilities | ⏳ Future |
.{
.dependencies = .{
.tszig_stdlib = .{
.url = "https://github.com/TSZig/tszig-stdlib/archive/refs/tags/v0.1.0.tar.gz",
.hash = "...",
},
},
}
// TypeScript input
import * as fs from "fs";
const content = fs.readFileSync("data.txt", "utf8");
fs.writeFileSync("output.txt", content);// Generated Zig
const fs = @import("tszig-stdlib").fs;
const content = try fs.readFileSync("data.txt", .utf8);
try fs.writeFileSync("output.txt", content);// TypeScript input
import * as path from "path";
const fullPath = path.join("dir", "subdir", "file.txt");
const ext = path.extname(fullPath);// Generated Zig
const path = @import("tszig-stdlib").path;
const fullPath = path.join(&.{"dir", "subdir", "file.txt"});
const ext = path.extname(fullPath);/// Read file contents as string
pub fn readFileSync(path: []const u8, encoding: Encoding) ![]const u8
/// Write string to file
pub fn writeFileSync(path: []const u8, data: []const u8) !void
/// Open file for reading/writing
pub fn openSync(path: []const u8, flags: OpenFlags) !File
/// Check if path exists
pub fn existsSync(path: []const u8) bool
/// Get file statistics
pub fn statSync(path: []const u8) !Stats/// Join path segments
pub fn join(segments: []const []const u8) []const u8
/// Get file extension
pub fn extname(path: []const u8) []const u8
/// Get directory name
pub fn dirname(path: []const u8) []const u8
/// Get base name
pub fn basename(path: []const u8) []const u8| TypeScript | Zig Equivalent |
|---|---|
fs.readFileSync(path, 'utf8') |
std.fs.cwd().readFile(path, ...) |
fs.writeFileSync(path, data) |
std.fs.cwd().writeFile(path, data) |
fs.existsSync(path) |
std.fs.cwd().access(path, ...) |
path.join(a, b) |
std.fs.path.join(...) |
JSON.parse(str) |
std.json.parseFromSlice(...) |
JSON.stringify(obj) |
std.json.stringifyAlloc(...) |
MIT License - see LICENSE for details.
See CONTRIBUTING.md for guidelines.