You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
554 B
19 lines
554 B
import get from "lodash/get"
|
|
import has from "lodash/has"
|
|
import mapValues from "lodash/mapValues"
|
|
|
|
export function normalize(data) {
|
|
if (has(data, "hydra:member")) {
|
|
//console.log('Normalize items in collections');
|
|
// Normalize items in collections
|
|
data["hydra:member"] = data["hydra:member"].map((item) => normalize(item))
|
|
|
|
return data
|
|
}
|
|
//console.log('data', data);
|
|
|
|
// Flatten nested documents
|
|
return mapValues(data, (value) =>
|
|
Array.isArray(value) ? value.map((v) => get(v, "@id", v)) : get(value, "@id", value),
|
|
)
|
|
}
|
|
|