montumodi / falsy-finder

A simple utility to find out falsy values from an object or arrays.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Falsy Finder

Known Vulnerabilities Coverage Status Build Status Deps devDependency Status

NPM

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]

About

A simple utility to find out falsy values from an object or arrays.


Languages

Language:JavaScript 100.0%