sindresorhus / camelcase-keys

Convert object keys to camel case
MIT License
691 stars 95 forks source link

Arrow functions breaking for angular project in IE #62

Closed rdandnayak closed 4 years ago

rdandnayak commented 4 years ago

while running an angular project i face this problem image

and the reason is image

seems like Arrow functions are not understandable by IE11

sindresorhus commented 4 years ago

Duplicate of #20

cassmtnr commented 3 years ago

Alternative function for Frontend projects:

function pascalToCamelCase(input) {
    let output, inputKey, outputKey, value;

    if (input instanceof Array) {
        return input.map((v) => (typeof v === 'object' ? pascalToCamelCase(v) : v));
    } else {
        output = {};
        for (inputKey in input) {
            if (input.hasOwnProperty(inputKey)) {
                outputKey = (
                    inputKey.charAt(0).toLowerCase() + inputKey.slice(1) ||
                    inputKey
                ).toString();

                value = input[inputKey];
                if (
                    value instanceof Array ||
                    (value !== null && value.constructor === Object)
                ) {
                    value = pascalToCamelCase(value);
                }
                output[outputKey] = value;
            }
        }
    }
    return output;
}

export default pascalToCamelCase;