• Maps an object recursively

    Parameters

    Returns Promise<Record<string, any>>

    Example

    Replace keys and string values

    const myObject = {
    foo: 'bar',
    baz: {
    qux: 'quux',
    corge: {
    grault: 'garply',
    }
    }
    };

    const result = await recursiveObjectMap(myObject, (key, value) => {
    return {
    newKey: `My Key: ${key}`,
    newValue: typeof value === 'string' ? `My Value: ${value}` : value,
    }
    }
    console.log({result})
    // {
    // "My Key: foo": "My Value: bar",
    // "My Key: baz": {
    // "My Key: qux": "My Value: quux",
    // "My Key: corge": {
    // "My Key: grault": "My Value: garply"
    // }
    // }
    // }

Generated using TypeDoc