Files
threshold-ui/addons/api/addon/transforms/object-as-array.js
T

30 lines
593 B
JavaScript
Raw Normal View History

/**
2026-01-28 17:09:06 -08:00
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
2025-04-03 09:32:44 -07:00
export default class ObjectAsArrayTransform {
2023-02-01 13:46:23 -05:00
deserialize(serialized) {
const obj = serialized || {};
return Object.entries(obj).map(([key, value]) => ({ key, value }));
}
2025-04-03 09:32:44 -07:00
2023-02-01 13:46:23 -05:00
serialize(deserialized) {
const array = deserialized || [];
if (!array.length) {
return null;
}
return array.reduce((result, currentValue) => {
const { key, value } = currentValue;
result[key] = value;
return result;
}, {});
}
2025-04-03 09:32:44 -07:00
static create() {
return new this();
}
2023-02-01 13:46:23 -05:00
}