Repository navigation
v4.2.0
What's Changed
- Add a new
ts.data.json/minientry point. It is the same library without theDecoderclass. A decoder is a plain function(json) => Result<T>, and the methods become standalone imports (decode,parse,decodePromise,map,flatMap). oneOfnow infers the union of its alternatives, sooneOf([string(), number()])givesDecoder<string | number>without a type argument. The explicit formoneOf<string | number>([...])still works.- Move the decoding logic into shared internal functions used by both entry points. Both entry points validate the same way and report the same issues.
import * as J from 'ts.data.json/mini'
const user = J.object({ id: J.number(), name: J.string() })
type User = J.FromDecoder<typeof user>
J.decode(user, json) // Result<User>, never throws
J.parse(user, json) // User, throws on failure
J.map(J.string(), iso => new Date(iso))mini saves about 1 kB minified. That matters most for apps that import only a few decoders:
| What you import | main entry | mini |
|---|---|---|
string() alone |
1457 B | 452 B |
| object + string + number + array + optional | 2562 B | 1451 B |
Things to know:
- Decoders from the two entry points are different types and cannot be mixed. Pick one per project.
nullandundefinedare exported under those names. A named import needs an alias:import { null as jsonNull } from 'ts.data.json/mini'.- In
mini, Standard Schema support is opt-in throughtoStandardSchema(decoder), so apps that do not use it do not bundle it.
Docs
New mini entry point section in the README, and a mini API reference. The API docs sidebar now lists the main and mini entry points separately.
Full Changelog: v4.1.0...v4.2.0