# serializr-fp

> (De)serialize complex object graphs to/from JSON

Latest version **0.2.0** (published 2018-03-05) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install serializr-fp
pnpm add serializr-fp
yarn add serializr-fp
bun add serializr-fp
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2018-03-05 |
| First published | 2018-02-17 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 60.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Dieter Geerts |
| Maintainers | dietergeerts |
| Keywords | serialize, deserialize, json, fp |

## Links

- npm: https://www.npmjs.com/package/serializr-fp
- Repository: https://github.com/dietergeerts/serializr-fp
- Homepage: https://github.com/dietergeerts/serializr-fp#readme
- Issues: https://github.com/dietergeerts/serializr-fp/issues
- npm.io page: https://npm.io/package/serializr-fp

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.2.0 (latest) — 2018-03-05
- 0.1.9 — 2018-03-02
- 0.1.8 — 2018-02-26
- 0.1.7 — 2018-02-23
- 0.1.6 — 2018-02-23
- 0.1.5 — 2018-02-23
- 0.1.4 — 2018-02-18
- 0.1.2 — 2018-02-17

## README

# serializr-fp

[![npm](https://img.shields.io/npm/v/serializr-fp.svg?style=for-the-badge)](https://www.npmjs.com/serializr-fp)
[![Codecov](https://img.shields.io/codecov/c/github/dietergeerts/serializr-fp.svg?style=for-the-badge)](https://codecov.io/gh/dietergeerts/serializr-fp)
[![Travis](https://img.shields.io/travis/dietergeerts/serializr-fp.svg?style=for-the-badge)](https://travis-ci.org/dietergeerts/serializr-fp)
[![David](https://img.shields.io/david/dietergeerts/serializr-fp.svg?style=for-the-badge)](https://david-dm.org/dietergeerts/serializr-fp)

> (De)serialize complex object graphs to/from JSON

A FP (Functional Programming) alternative to [serializr](https://github.com/mobxjs/serializr),
with a simpler approach for ease of use and better customization, configure
(de)serialization through schema's, improving readability and maintainability.

[More info about the internals and principles →](./principles.md)

## Install

```commandline
npm install serializr-fp --save
```

## Usage

```javascript
import {alias, computed, DATE_ONLY, deserialize, object, PRIMITIVE, serialize} from 'serializr-fp';

const PATIENT_SCHEMA = object({
    id: alias('_id', PRIMITIVE),
    person: object({
        firstName: PRIMITIVE, 
        lastName: PRIMITIVE,
        fullName: computed(json => `${json.firstName} ${json.lastName}`),
    }),
    dateOfBirth: alias('dob', DATE_ONLY),
});

const source = {
    id: '123',
    person: {
        firstName: 'Dieter', 
        lastName: 'Geerts', 
        fullName: 'Dieter Geerts',
    },
    dateOfBirth: new Date('1982-10-08'),
}; 

const json = PATIENT_SCHEMA.serialize(source);
const patient = PATIENT_SCHEMA.deserialize(json);

console.log(json); 
console.log(patient);

// Or you can export functions for other modules to use,
// without the need to know how (de)serialization is done.

export const deserializePatient = PATIENT_SCHEMA.deserialize;
export const serializePatient = PATIENT_SCHEMA.serialize;
```

[More useful examples →](./examples.md)

## API

[Read the API →](./API.md)

## Maintainers

[![dietergeerts](https://avatars3.githubusercontent.com/dietergeerts?v=3&s=100)](https://github.com/dietergeerts) |
:---: | 
[dietergeerts](https://github.com/dietergeerts) |

## Contribute

[![Codacy grade](https://img.shields.io/codacy/grade/9f5cae0799824989a4f3e576c0230fa2.svg?style=for-the-badge)](https://www.codacy.com/app/dietergeerts/serializr-fp)
[![Code Climate](https://img.shields.io/codeclimate/maintainability/dietergeerts/serializr-fp.svg?style=for-the-badge)](https://codeclimate.com/github/dietergeerts/serializr-fp/maintainability)
[![David](https://img.shields.io/david/dev/dietergeerts/serializr-fp.svg?style=for-the-badge)](https://david-dm.org/dietergeerts/serializr-fp)

> All contributions welcome

### Contributors

<!--START contributers-->
[<img alt="dietergeerts" src="https://avatars1.githubusercontent.com/u/7393706?v=4&s=100" width="100">](https://github.com/dietergeerts) |
:---: |
[dietergeerts](https://github.com/dietergeerts) |



<!--END contributers-->

## License

[GNU General Public License v3.0](LICENSE)

---
_Source: https://npm.io/package/serializr-fp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
