parse-ts
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

parse-ts

Validate json with types!

You ever take json data from the server and want to verify it matches some interface? This library is for you!

Depends on fp-ts

Installation

npm i -S parse-ts

Example

// example interface
interface Rec {
  a: number;
  b: string;
  c: number[];
  d: boolean;
};

// Validator spec
const rec: RecordSpec<Rec> = {
  a: num,
  b: str,
  c: arrayOf(num),
  d: bool,
};

const someData = JSON.parse(`{"a": 1, "b": "hi", "c": [1], "d": false}`);

// usage
record(rec)(someData); // => Option<Rec>

Check out unit tests for more usage examples.

Docs

Source has JSDoc with examples.

See Also

  • io-ts Similar to parse-ts but more powerful. Worth a look if you want more than simple JSON parsing.

Readme

Keywords

none

Package Sidebar

Install

npm i parse-ts

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

30 kB

Total Files

19

Last publish

Collaborators

  • jethrolarson