@scottrabin/decoder
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

@scottrabin/decoder

Decode unknown JSON values into known types via composable decoders.

The intended use case is external type parsing, which have no guarantees on structural types. This library aims to provide type safety to e.g. responses to API calls, localStorage and its ilk, and other boundaries where type information is lost or unavailable. It is not intended for use in transforming the interpreted data - it only affirms the data returned by the decoders meets the structural requirements.

Getting Started

$ yarn add @scottrabin/decoder
// in yourFile.ts
import * as decoders from "@scottrabin/decoder";

const myDecoder = decoders.struct(/* ... */);

API

See the documentation

Philosophy

decoder is intended to be modular; decoders are simple objects with a decode method, which accepts a value of type unknown and returns a Result type indicating success or failure in asserting the type of the given value matches the desired type.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @scottrabin/decoder

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

33.2 kB

Total Files

29

Last publish

Collaborators

  • scottrabin