# with-normalizr

> Expose simplified functions to manipulate flattened data structure with normalizr.

Latest version **1.0.0** (published 2019-03-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install with-normalizr
pnpm add with-normalizr
yarn add with-normalizr
bun add with-normalizr
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-03-10 |
| First published | 2019-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | marcosun |
| Maintainers | marcosun |

## Links

- npm: https://www.npmjs.com/package/with-normalizr
- Repository: https://github.com/marcosun/with-normalizr
- Homepage: https://github.com/marcosun/with-normalizr#readme
- Issues: https://github.com/marcosun/with-normalizr/issues
- npm.io page: https://npm.io/package/with-normalizr

## Recent versions

- 1.0.0 (latest) — 2019-03-10

## README

# with-normalizr

## Before I have been created

With normalizr library, we could create a customer schema with the following code:
```javascript
import { schema } from 'normalizr';
const customerSchema = new schema.Entity('customer');
```
Let's say we want to transform customer object into normalised data structure, here is what normalizr official documentation says:
```javascript
import { normalize } from 'normalizr';
const customer = { id: 1, name: 'marco' };
const normalisedCustomer = normalize(customer, customerSchema);
```
At the time we need to denormalise, we could do this:
```javascript
import { denormalize } from 'normalizr';
const denormalisedCustomer = denormalize(normalisedCustomer.result, customerSchema, normalisedCustomer.entities);
```

## Why am I here?

The above is literarily everything we would use with normalizr.

I have two unhappiness. One is that when denormalise, I have to pass normalised result and entities separately to the denormalize function although these two parameters are generated by normalize function at once.

The other is redundancy. Schema is created by normalizr but when interacting with schema, however, I have to import another function from normalizr to call schema. With Object Oriented Programming in mind, I feel this approach unsatisfied.

## Now live with me

Now with with-normalizr, it becomes this:
Defining a schema:
```javascript
import { schema } from 'normalizr';
import withNormalizr from 'with-normalizr';
const customerSchema = withNormalizr(new schema.Entity('customer'));
```
Normalise:
```javascript
const customer = { id: 1, name: 'marco' };
const normalisedCustomer = customerSchema.toNormalize(customer);
```
Denormalise:
```javascript
const denormalisedCustomer = customerSchema.toDenormalize(normalisedCustomer);
```

## One more thing

Moreover, with-normalizr is an HOC on schema instance, which means all usages provided by normalizr are still working.

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