kitsu-core
Version:
Simple, lightweight & framework agnostic JSON:API (de)serialsation components
20 lines (18 loc) • 614 B
JavaScript
function deattribute(data) {
if (typeof data === 'object' && data !== null) {
if (Array.isArray(data)) data.map(el => deattribute(el));else if (typeof data.attributes === 'object' && !Array.isArray(data.attributes) && data.attributes !== null) {
for (const key of Object.keys(data.attributes)) {
if (!data.attributes.attributes) {
data[key] = data.attributes[key];
}
}
if (data.attributes.attributes) {
data.attributes = data.attributes.attributes;
} else {
delete data.attributes;
}
}
}
return data;
}
export { deattribute };