normal-it
v1.0.1
Published
Normalizes and denormalizes JSON according to schema for Redux and Flux applications
Downloads
3
Readme
Normal-it
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"
}
}
}
}