pragmatic-fp-ts
Version:
Opinionated functional programming library with easy use in mind
12 lines (9 loc) • 336 B
text/typescript
import { Dictionary, getValueOr } from "./main.ts";
// inverts key->value to value->key object
export function invertObj(obj: Dictionary): Dictionary<string> {
const dict = getValueOr({}, obj);
return Object.keys(dict).reduce((accum: Dictionary<string>, key) => {
accum[String(dict[key])] = key;
return accum;
}, {});
}