Files
certd/packages/ui/certd-client/src/utils/util.common.ts
T

34 lines
584 B
TypeScript
Raw Normal View History

2023-05-09 09:49:42 +08:00
import _ from "lodash";
2023-01-29 13:44:19 +08:00
export default {
2023-06-25 23:25:56 +08:00
arrayToMap(array: any) {
2023-01-29 13:44:19 +08:00
if (!array) {
return {};
}
if (!_.isArray(array)) {
return array;
}
2023-06-25 23:25:56 +08:00
const map: any = {};
2023-01-29 13:44:19 +08:00
for (const item of array) {
if (item.key) {
map[item.key] = item;
}
}
return map;
},
2023-06-25 23:25:56 +08:00
mapToArray(map: any) {
2023-01-29 13:44:19 +08:00
if (!map) {
return [];
}
if (_.isArray(map)) {
return map;
}
const array: any = [];
for (const key in map) {
const item = map[key];
item.key = key;
array.push(item);
}
return array;
}
};