Function dataFormatter

  • Data formatter - rename/customise keyname and values as you require, even nested keys and nested values can be defined.

    Parameters

    • obj: AnyObject = {}

      data to be formatted

    • formatter: string = ""

      key:valuePath, each key value is separated by comma

    • options: FormatterOptions = {}

    Returns AnyObject

    return modified object along with the provided object

    Example

    "alterName:key" or "alterName:nested.key" or "nested.alterName:key" or "nested.alterName:nested.key"
    

    Example

    const payload = {
    id: "some-id",
    data: {
    theme: "dark"
    },
    portion: {
    id: "portion-id",
    data: {
    name: "section-wrapper"
    }
    }
    };
    const a = dataFormatter(payload, "pid:id,theme:data.theme,prtn.id:portion.id,prtn.name:portion.data.name,something:block", { oldData: false });

    console.log(a);
    output:
    {
    pid: 'some-id',
    theme: 'dark',
    prtn: { id: 'portion-id', name: 'section' },
    ERRORS: { block: 'not found' }
    }

Generated using TypeDoc