-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
29 lines (25 loc) · 1.01 KB
/
utils.ts
File metadata and controls
29 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { DADescription } from "./describe/DADescription.js";
import { DODescription } from "./describe/DODescription.js";
import { ReportControlDescription } from "./describe/ReportControl.js";
import { SDODescription } from "./describe/SDODescription.js";
type SortedObjects =
| DADescription
| SDODescription
| ReportControlDescription
| DODescription;
/** @returns Alphabetically sorted object keys */
export function sortRecord(object: Record<string, SortedObjects>) {
return Object.keys(object)
.sort()
.reduce((sortedRecord: Record<string, SortedObjects>, key) => {
sortedRecord[key] = object[key];
return sortedRecord;
}, {});
}
/** @returns DOType/DAType/EnumType reference by the elements type attribute */
export function referencedDataType(element: Element): Element | undefined {
const elementType = element.getAttribute("type");
return Array.from(element.closest("DataTypeTemplates")?.children ?? []).find(
(sibling) => sibling.getAttribute("id") === elementType,
)!;
}