Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add transformKeysToSnake #39

Merged
merged 9 commits into from
Mar 28, 2025

Conversation

jsertx
Copy link
Contributor

@jsertx jsertx commented Mar 3, 2025

Description:

  • Add transformKeysToSnake

New features:

  • transformKeysToSnake

PR status:

  • Version bumped
  • Change-log updated
  • Tests added or updated
  • PR keeps 100% test coverage
  • Type definition updated
  • Readme updated
  • Linter is applied
  • Const arrow functions are used instead of pure function definitions where applicable
  • Functions are listed in alphabetic order in index.js, index.d.ts and readme

@jsertx jsertx marked this pull request as draft March 3, 2025 10:34
@jsertx jsertx changed the title feat: add transformKeysToSnake + isPlainObject fix feat: add transformKeysToSnake Mar 4, 2025
@jsertx jsertx marked this pull request as ready for review March 4, 2025 15:20
Copy link

@avsek477 avsek477 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest, lgtm

avsek477
avsek477 previously approved these changes Mar 10, 2025
* @param {Object} obj
* @returns {Object}
*/
const transformKeysToSnakeCase = (obj) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have a deep/recursive flag to inform that nested objects should also be applied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you propose, the following?

const transformKeysToSnakeCase = (obj, { recursive } = {}) => {
  if (Array.isArray(obj)) {
    return obj.map(item => transformKeysToSnakeCase(item))
  }

  if (!isPlainObject(obj)) {
    return obj
  }

  return Object.fromEntries(
    Object.entries(obj).map(([k, v]) => [
      snakeCase(k),
      recursive ? transformKeysToSnakeCase(v) : v
    ])
  )
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I give the consumer more control

Copy link
Contributor

@vigan-abd vigan-abd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to update package-lock.json as well

@vigan-abd vigan-abd merged commit 5d6db78 into bitfinexcom:main Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants