asDict args, handles multiple entities, values
parent
f738875905
commit
c77bb8a425
|
@ -8,14 +8,23 @@ export function listingAsOrdered(listing: ListingResult): OrderedListing {
|
|||
.sort(([_, a], [__, b]) => a.attribute.localeCompare(b.attribute));
|
||||
}
|
||||
|
||||
export function asDict(attributes: OrderedListing): {
|
||||
[key: string]: string;
|
||||
} {
|
||||
const result = {} as { [key: string]: string };
|
||||
attributes
|
||||
.map(([_, attribute]) => attribute)
|
||||
.forEach((attribute) => {
|
||||
result[attribute.attribute] = attribute.value.c;
|
||||
});
|
||||
export function asDict(attributes: IEntry[]) {
|
||||
const result = {} as { [key: string]: { [key: string]: unknown } };
|
||||
attributes.forEach((entry) => {
|
||||
if (!result[entry.entity]) {
|
||||
result[entry.entity] = {};
|
||||
}
|
||||
if (result[entry.entity][entry.attribute]) {
|
||||
if (!Array.isArray(result[entry.entity][entry.attribute])) {
|
||||
result[entry.entity][entry.attribute] = [
|
||||
result[entry.entity][entry.attribute],
|
||||
];
|
||||
}
|
||||
(result[entry.entity][entry.attribute] as unknown[]).push(entry.value.c);
|
||||
} else {
|
||||
result[entry.entity][entry.attribute] = entry.value.c;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue