-
Notifications
You must be signed in to change notification settings - Fork 207
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
just-flush-recursively / just-flush-deep / just-deep-flush / just-flush-object? #517
Labels
Comments
My current solution is this: /**
* Recursively removes null and undefined values from an object
* https://stackoverflow.com/a/54707141/1818285
* TODO: consider refactoring (avoid conversion to string)
*/
export const deepClean = <T>(obj: T): OmitNullable<T> =>
JSON.parse(
JSON.stringify(obj, (key, value: unknown) =>
value === null || value === undefined ? undefined : value,
),
) as OmitNullable<T>; It works well for relatively small objects, but obviously does not scale if a JSON is very large. I鈥檓 looking for some third-party package that would save me from copying this small helper function between repos. |
Hi @kachkaev, thanks for the nice words! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @angus-c, great repo! 馃挴
I bumped into just-flush which was very close a function I needed. I wonder if you鈥檇 be open to accept a PR with a recursive version of the function, WDYT?
It might be also useful to consider a mode when nullish items are not removed from arrays, but not 100% sure about this 馃
The text was updated successfully, but these errors were encountered: