-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Update sumObjects
to coerce numeric strings, preserve Arrays in return
#324
Conversation
🦋 Changeset detectedLatest commit: e369f8d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @brandonmcconnell. Could you run pnpm format
to fix the lint issues (prettier formatting) which will allow the CI tests to run, and add a few more tests...
- Using the accessor as a function (ex.
sumObjects(data, d => ...)
) - Using the accessor as a string (ex.
sumObjects(data, 'value')
)- data:
[{ foo: { value: 123 }, bar: { value: 234 } }, { foo: { value: 987 }, ... }]
- data:
- Data as an array of arrays
Thanks!
const result = rollup( | ||
items.flatMap((x) => entries(x ?? {})), | ||
(values) => sum(values, (d) => { | ||
const value = Number(getProp(d[1])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should also get the key
as the second argument (d[0]
and maybe the whole object as the third (d
), similar to just-map-values
Changed made
sumObjects
to automatically coerce numeric strings to numberssumObjects
to return the summed values as an Array if all processed items are arrays