Skip to content

Conversation

eaglethrost
Copy link
Contributor

@eaglethrost eaglethrost commented Sep 10, 2025

🚥 Resolves ISSUE_ID

🧰 Changes

  • This PR is part of the work for the readme ticket CX-1511 Add support for allowEmptyValue and should get merged first before the changes in the oas repo
  • Adds an optional preserveEmptyArray option & separate logic to check if the current value in an object is an array.

🧬 QA & Testing

  • Pass in preserveEmptyArray in the removalOptions & pass in an object that has empty arrays, or arrays that contain undefined & null values

test('should not remove empty arrays when preserveEmptyArray is true', () => {
expect(removeUndefinedObjects({ value: [] }, { preserveEmptyArray: true })).toStrictEqual({ value: [] });
expect(removeUndefinedObjects({ value: [undefined] }, { preserveEmptyArray: true })).toStrictEqual({ value: [] });
expect(removeUndefinedObjects({ value: [null] }, { preserveEmptyArray: true })).toStrictEqual({ value: [] });
Copy link
Member

Choose a reason for hiding this comment

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

Can you add another case in here for an array with non-falsy values to assert that it is left alone. Also can you add some more examples for arrays in a nested object?

@erunion erunion requested a review from kanadgupta September 10, 2025 16:47
@erunion erunion added the enhancement New feature or request label Sep 10, 2025
@erunion
Copy link
Member

erunion commented Sep 10, 2025

Can you also update the README for this new option?

Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

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

echoing @erunion's feedback here on the test coverage and README docs, otherwise LGTM!

Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

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

i believe tests are failing due to my changes in #150, sorry about that 😅 mind fixing that up? running npm run prettier locally should do the trick!

Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

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

i'm happy with this, will defer to @erunion for final approval + merge!

README.md Outdated
import removeUndefinedObjects from 'remove-undefined-objects';

console.log(
removeUndefinedObjects({ key1: [], key2: [undefined], key3: { key4: 'a', key5: [] } }, { preserveEmptyArray: true }),
Copy link
Member

Choose a reason for hiding this comment

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

similar comment to here — can you add another example that's using the exact same object but with preserveEmptyArray set to false so it illustrates the difference?

@erunion erunion merged commit 6bc9175 into readmeio:main Sep 11, 2025
5 checks passed
@erunion
Copy link
Member

erunion commented Sep 12, 2025

Published to v7.0.0

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.

3 participants