1.1.0 • Published 3 years ago

parse-ts v1.1.0

Weekly downloads
8
License
ISC
Repository
github
Last release
3 years ago

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.
1.1.0

3 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago