humps icon indicating copy to clipboard operation
humps copied to clipboard

Camelize keys & uppercase

Open aliceclv opened this issue 2 years ago • 2 comments

I noticed that some uppercased keys were camelized in a weird way:

humps.camelizeKeys({ "USERNAME":  "foo" }) // returns { uSERNAME: "foo" }

I've used a custom function & lodash to prevent this from happening, but I was wondering if that was the expected behaviour from humps.

    // Use lowercase instead of camelization for uppercase-only keys
    // (to prevent USERNAME from becoming uSERNAME)
    humps.camelizeKeys(data, function (key, convert, options) {
      return /^[A-Z0-9_]+$/.test(key) ? lowerCase(key) : convert(key, options);
    });

aliceclv avatar Jan 26 '22 15:01 aliceclv