Files
2025-12-10 05:23:24 +07:00

37 lines
929 B
TypeScript

export interface Item {
value: string
label: string
code?: string
priority?: number
}
export function recStrToItem(input: Record<string, string>): Item[] {
const items: Item[] = []
let idx = 0
for (const key in input) {
if (input.hasOwnProperty(key)) {
items.push({
value: key || 'unknown-' + idx,
label: input[key] || 'unknown-' + idx,
})
}
idx++
}
return items
}
export function objectsToItems(input: object[], key = 'id', label = 'name'): Item[] {
const items: Item[] = []
for (const item of input) {
if (item.hasOwnProperty(key) && item.hasOwnProperty(label)) {
items.push({
value: item[key as keyof typeof item], // the hasOwnProperty check should be enough
label: item[label as keyof typeof item], // the hasOwnProperty check should be enough
})
}
}
return items
}
export { default as Combobox } from './combobox.vue'