feat: options for custom key transformation and glue empty string #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
inflattie
function, which is supposed to contains these new options, but maybe others in the future.New options:
transformKey
: is a function getting in inputpfx
andkey
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 actualglue || '.'
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!