falsy-finder
v5.13.0
Published
This little utility helps in finding null, undefined etc values from objects and arrays.
Downloads
22
Maintainers
Readme
Falsy Finder
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
How to install
npm install falsy-finder -S
Getting Started
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);
Options
The getFinder
method supports following options:
falsyValues
: (array) The custom falsy values array to check against. - default:["", null, undefined, NaN]