clean-deep
clean-deep copied to clipboard
Allow to skip specific keys
It's useful if there is an option which prevents to remove specific keys which contain values like,
[], {}, null, ""
// Example:
let obj = { a: "", b: "xyz" }
let res = cleenDeep(obj, {
skipKeys: [ "a" ]
})
// Output
// res:
{
a: "",
b: "xyz"
}
@pranavwani interesting concept, but at that point I think I'd prefer a more generic approach, like:
const obj = { a: "", b: "xyz" };
const res = cleanDeep(obj, {
cleanIf: (key, value) => key !== 'a'
});
// Output
// res:
{
a: "",
b: "xyz"
}
I'll give this one a think :)
Better option to handle property :+1:
I like the skipKeys option for typed reasons, it might be less generic, but it could allow for better typing, for example it could allow only the valid keys of the object passed, and then the return type could only be partial on the keys passed. ts-essentials has some types that should make doing that reasonably easy from a type perspective. Ultimately though my reason for wanting this is just to have the same output type as input, it's the optional keys I want to strip in the first place.