v0.36.0
Minor Changes
-
b9b0dce: Add
parseJsonandJsonParseErrortowellcrafted/json.parseJson(text)parses a JSON string into aResult<JsonValue, JsonParseError>instead of throwing. It is the Result-returning counterpart toJSON.parse:- the success value is typed as
JsonValuerather thanany, so you must narrow or validate it before treating it as a known shape - malformed input is reported as a tagged
JsonParseError(built withdefineErrors) carrying the underlyingSyntaxErrorascause, instead of throwing
import { parseJson } from "wellcrafted/json"; const { data, error } = parseJson(raw); if (error) return Err(error); // JsonParseError data; // JsonValue
No reviver argument is accepted: a reviver can return arbitrary values, which would make the
JsonValuesuccess type unsound. - the success value is typed as
-
5c4dab6: Add the
wellcrafted/testingentry point withexpectOkandexpectErr.These are test-only assertion helpers for
Resultvalues. Each unwraps the expected branch and returns it narrowed, throwing if theResultis the other variant:import { expectOk, expectErr } from "wellcrafted/testing"; const value = expectOk(parseConfig(raw)); // success value, narrowed const error = expectErr(parseConfig("x")); // error value, narrowed expect(error.name).toBe("ConfigParseError");
They intentionally throw: a failed expectation should abort the test, which every runner reports as a failure. Throwing is fenced into this separate
wellcrafted/testingentry point sowellcrafted/resultstays throw-free. The helpers throw a plainError, so they work under bun, vitest, jest, ornode:testwithout depending on a test framework.