Skip to content

feat: add removeAllFalsy option #128

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

Merged
merged 2 commits into from
Jan 10, 2025

Conversation

JoshuaKGoldberg
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg commented Jan 8, 2025

🚥 Fixes #126

🧰 Changes

Adds and documents an optional removeAllFalsy flag in a new optional options object. If true, '' and null will also be removed from objects.

🧬 QA & Testing

I added unit tests and ran them.

@erunion erunion added the enhancement New feature or request label Jan 8, 2025
@erunion erunion self-requested a review January 8, 2025 17:12
src/index.ts Outdated
@@ -6,30 +6,43 @@ function isEmptyObject(obj: unknown) {
return typeof obj === 'object' && obj !== null && !Object.keys(obj).length;
}

export interface RemovalOptions {
Copy link
Member

Choose a reason for hiding this comment

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

Having a default and secondary export in the same file gets really messy in CJS dist builds, causing types to get screwed up, do you mind either not exporting this or moving it to a separate file and exposing that in the exports config?

"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./package.json": "./package.json"
},

We have a custom ESLint plugin that has the rule that's being flagged for this case below. There's some more details about why it can be problematic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I removed the second export and filed readmeio/standards#919. Thanks for the tip!

@erunion erunion merged commit f96a61b into readmeio:main Jan 10, 2025
4 checks passed
@erunion
Copy link
Member

erunion commented Jan 10, 2025

Published to v6.0.0, thanks again!

https://github.com/readmeio/remove-undefined-objects/releases/tag/6.0.0

@JoshuaKGoldberg JoshuaKGoldberg deleted the remove-all-falsy branch January 10, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Option to remove '' and null
2 participants