Function regroup

  • Given obj in which the values are themselves POJOs, restructures the object so that the first level keys become the second level keys and vice versa.

    Remarks

    All objects that are values of obj must have the same set of keys.

    Example

    import * as P from "flurp/pojo";

    const nested = {
    x: {a: 1, b: 2},
    y: {a: 3, b: 4},
    z: {a: 5, b: 6},
    };

    P.regroup(nested); // { a: {x: 1, y: 3, z: 5}, b: {x: 2, y: 4, z: 6} }

    Type Parameters

    • T extends Readonly<Record<string, unknown>>

    • U extends Record<string, T>

    Parameters

    • obj: U

    Returns {
        [k: string]: T;
    }

    • [k: string]: T