- Fixes broken CI and updates readme
- Address CI lint issues
Refined synchronous execution support - tryCatch now returns the appropriate type based on input, eliminating unnecessary await for synchronous functions.
Synchronous functions - No await needed, returns Result<T, E> directly:
// Parse JSON
const [err, data] = tryCatch(() => JSON.parse('{"a":1}'));
// Functions that throw
const [err, data] = tryCatch(() => {
throw new RangeError("Out of bounds");
});
// Non-Error throws are wrapped in Error with cause
const [err, data] = tryCatch(() => {
throw "string error";
});
// err.message === "string error", err.cause === "string error"Async functions - Returns Promise<Result<T, E>>:
const [err, data] = await tryCatch(async () => {
const res = await fetch("/api");
return res.json();
});Direct promises - Returns Promise<Result<T, E>>:
const [err, data] = await tryCatch(fetch("/api/data"));
const [err, data] = await tryCatch(Promise.resolve(42));
const [err, data] = await tryCatch(Promise.reject(new Error("fail")));Promise chains - Returns Promise<Result<T, E>>:
const [err, data] = await tryCatch(() => fetch("/api").then((r) => r.json()));Result, Success, and Failure types are now exported for use in your own type definitions:
import { tryCatch, Result, Success, Failure } from "@dschz/try-catch";- Adds badges to readme
- updates package keywords for better discoverability
- updates readme with more examples
- updates signature to accept synchronous functions
- updates jsr config to only upload necessary files
- Fixes package exports
- Update README
- Simple tryCatch utility function to allow async/await syntax