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: options for custom key transformation and glue empty string #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

DavideArena
Copy link

@DavideArena DavideArena commented Nov 22, 2024

Hello,

i was using Flattie because is very lightweight and works perfectly, but it was missing some features which were needed in my use case. So i decided to make this PR, hoping if someone else could be happy.

I've added a new parameter options in flattie function, which is supposed to contains these new options, but maybe others in the future.

New options:

  • transformKey: is a function getting in input pfx and key of the current key the function iter is processing. It's useful when you have to make transformation like camel case, uppercase, lowercase ecc...plus i decided to expose the actual prefix too in order to know if i'm processing root fields or not, but probably could be useful for something else too.
  • allowGlueEmptyString: a boolean value which allows the empty string value on glue parameter. I decided to add a custom option to force this and not change the actual glue || '.' behaviour in order to not make a breaking change. This is really useful when you have to flat without adding anything to original strings.

I've run the bench on my MacBookPro M1 using node v20.10.0:

Load Time:
flat: 0.258ms
flatten-object: 0.375ms
flat-obj: 0.129ms
flattie: 0.35ms

Benchmark:
flat x 979,270 ops/sec ±0.36% (95 runs sampled)
flatten-object x 458,339 ops/sec ±0.23% (99 runs sampled)
flat-obj x 722,398 ops/sec ±1.40% (94 runs sampled)
flattie x 1,337,977 ops/sec ±0.70% (91 runs sampled)

But i don't know how you handle the update of those data in readme.md, so i didn't add for now, in case let me know how you want to go.

Thanks!

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.

1 participant