<commit_before># json-api-normalizer
Utility to normalize JSON API data for redux applications

[![npm version](https://img.shields.io/npm/v/json-api-normalizer.svg?style=flat)](https://www.npmjs.com/package/json-api-normalizer)
[![Downloads](http://img.shields.io/npm/dm/json-api-normalizer.svg?style=flat-square)](https://npmjs.org/package/json-api-normalizer)
[![Build Status](https://img.shields.io/travis/yury-dymov/json-api-normalizer/master.svg?style=flat)](https://travis-ci.org/yury-dymov/json-api-normalizer)
[![Coverage Status](https://coveralls.io/repos/github/yury-dymov/json-api-normalizer/badge.svg?branch=master)](https://coveralls.io/github/yury-dymov/json-api-normalizer?branch=master)


# Description
json-api-normalizer helps awesome [JSON API](http://jsonapi.org/) and [redux](http://redux.js.org/) work together.
Unlike [normalizr](https://github.com/paularmstrong/normalizr) json-api-normalizer supports JSON API specification, which means that you don't have to care about schemes. It also converts collections into maps, which is a lot more suitable for redux.

Demo - [https://yury-dymov.github.io/json-api-react-redux-example/](https://yury-dymov.github.io/json-api-react-redux-example/)

Demo sources - [https://github.com/yury-dymov/json-api-react-redux-example](https://github.com/yury-dymov/json-api-react-redux-example)

Works great together with [redux-object](https://github.com/yury-dymov/redux-object), which helps to fetch and denormalize data from the store.

# Example
```JavaScript
import normalize from 'json-api-normalizer';

const json = {
  data: [{
    "type": "post-block",
    "relationships": {
      "question": {
        "data": {
          "type": "question",
          "id": "295"
        }
      }
    },
    "id": "2620",
    "attributes": {
      "text": "I am great!",
      "id": 2620
    }
  }],
  included: [{
    "type": "question",
    "id": "295",
    "attributes": {
      "text": "How are you?",
      id: 295
    }
  }]    
};

console.log(normalize(json));
/* Output:
{
  question: {
    "295": {
      attributes: {
        id: 295,
        text: "How are you?"
      }
    }
  },
  postBlock: {
    "2620": {
      attributes: {
        id: 2620,
        text: "I am great!"
      },
      relationships: {
        question: {
          type: "question",
          id: "295"
        }      
      }
    }
  }
}
*/
```

# Data Representation Feature
One-to-Many relationship is merged into one map like this

```JavaScript
const json = {
  data: [{
    type: "post-block",
    id: "1",
    attributes: { ... },
    relationships: {
      posts: {
        data: [{
          type: "post",
          id: "1"
        }, {
          type: "post",
          id: "2"          
        }]
      }
    },
    ...
  }]
}

console.log(normalize(json));
/* Output:
{
  postBlock: {
    "1": {
      ...,
      relationships: {
        posts: {
          type: "post",
          id: "1,2"           <----- this!
        }
      }
    }
  }
}
*/
```

This approach makes redux state updates a lot easier as during merge new string with IDs will replace the old one. Otherwise, it would require some extra efforts to delete outdated relationships from the store.

# Options<commit_msg>docs update<commit_after># json-api-normalizer
Utility to normalize JSON API data for redux applications

[![npm version](https://img.shields.io/npm/v/json-api-normalizer.svg?style=flat)](https://www.npmjs.com/package/json-api-normalizer)
[![Downloads](http://img.shields.io/npm/dm/json-api-normalizer.svg?style=flat-square)](https://npmjs.org/package/json-api-normalizer)
[![Build Status](https://img.shields.io/travis/yury-dymov/json-api-normalizer/master.svg?style=flat)](https://travis-ci.org/yury-dymov/json-api-normalizer)
[![Coverage Status](https://coveralls.io/repos/github/yury-dymov/json-api-normalizer/badge.svg?branch=master)](https://coveralls.io/github/yury-dymov/json-api-normalizer?branch=master)


# Description
json-api-normalizer helps awesome [JSON API](http://jsonapi.org/) and [redux](http://redux.js.org/) work together.
Unlike [normalizr](https://github.com/paularmstrong/normalizr) json-api-normalizer supports JSON API specification, which means that you don't have to care about schemes. It also converts collections into maps, which is a lot more suitable for redux.

Demo - [https://yury-dymov.github.io/json-api-react-redux-example/](https://yury-dymov.github.io/json-api-react-redux-example/)

Demo sources - [https://github.com/yury-dymov/json-api-react-redux-example](https://github.com/yury-dymov/json-api-react-redux-example)

Works great together with [redux-object](https://github.com/yury-dymov/redux-object), which helps to fetch and denormalize data from the store.

# Example
```JavaScript
import normalize from 'json-api-normalizer';

const json = {
  data: [{
    "type": "post-block",
    "relationships": {
      "question": {
        "data": {
          "type": "question",
          "id": "295"
        }
      }
    },
    "id": "2620",
    "attributes": {
      "text": "I am great!",
      "id": 2620
    }
  }],
  included: [{
    "type": "question",
    "id": "295",
    "attributes": {
      "text": "How are you?",
      id: 295
    }
  }]    
};

console.log(normalize(json));
/* Output:
{
  question: {
    "295": {
      attributes: {
        id: 295,
        text: "How are you?"
      }
    }
  },
  postBlock: {
    "2620": {
      attributes: {
        id: 2620,
        text: "I am great!"
      },
      relationships: {
        question: {
          type: "question",
          id: "295"
        }      
      }
    }
  }
}
*/
```

# Options
{'fraction_non_alphanumeric': 0.1686746987951807, 'fraction_numerical': 0.013111268603827072, 'mean_word_length': 2.620910840282232, 'pattern_counts': {'":': 33, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 26, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '392163', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1906, 'n_words': 368}