A simple utility to find out falsy values from an object or arrays. It returns all the keys along with values in an array. By default it will look for following falsy values:
"",
null,
undefined,
NaN
This behavior can be customized by passing options while creating finder. See options
npm install falsy-finder -S
The basic syntax is:
const createFinder = require("falsy-finder");
const finder = createFinder();
const someJsonWithNullValues = {
firstName: "firstName",
lastName: "lastName",
address: {
City: "",
Street: "London"
},
tags: [
"Hi",
"hello",
"",
null,
[
{
nested: null,
none: "vallue"
}
]
]
};
const result = finder.getFalsyValues(someJsonWithNullValues);
Result: [
{
key: "address.City",
value: ""
},
{
key: "tags.[2]",
value: ""
},
{
key: "tags.[3]",
value: null
},
{
key: "tags.[4].[0].nested",
value: null
}
];
Ths syntax using options:
const createFinder = require("falsy-finder");
const options = { falsyValues: ["my", "custom", null, "and", undefined] };
const finder = createFinder(options);
The getFinder
method supports following options:
falsyValues
: (array) The custom falsy values array to check against. - default:["", null, undefined, NaN]