1.0.1 • Published 7 years ago

normal-it v1.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

Normal-it

CircleCI codecov Dependencies

Quick Start

{
  "id": 1,
  "name": "Homer",
  "level": {
    "id": 2,
    "label": "level 1"
  }
}
import { normalize, Entity } from 'normal-it';


const Account = new Entity('accounts');
const Level = new Entity('levels');

Account.define({
  level: {
    entity: Level,
    type: 'belongsTo',
    foreignKey: 'levelId',
  },
});

const normalizedData = normalize(originalData, Account);

will produce

{
  "result": 1,
  "entities": {
    "accounts": {
      "1": {
        "id": 1,
        "name": "Homer",
        "levelId": 2
      }
    },
    "levels": {
      "2": {
        "id": 2,
        "label": "level 1"
      }
    }
  }
}