@k8ts/metadata
Version:
K8ts tools for working with k8ts metadata.
22 lines (18 loc) • 680 B
text/typescript
import { seq } from "doddle"
import { K8tsMetadataError } from "../error"
function comparisonKey(key: string) {
const bySlash = key.split("/")
if (bySlash.length === 1) {
return key
}
if (bySlash.length > 2) {
throw new K8tsMetadataError(`Invalid composed key ${key}, too many '/' characters.`)
}
const [dns, name] = bySlash
const dnsParts = dns.split(".").reverse()
return [...dnsParts, name].join("\uffff")
}
export function orderMetaKeyedObject(input: Record<string, string>): Record<string, any> {
const entries = seq(Object.entries(input)).orderBy(([key]) => comparisonKey(key))
return Object.fromEntries(entries)
}