Have ideas to improve npm?Join in the discussion! »

    falsy-finder

    5.12.0 • Public • Published

    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]

    Install

    npm i falsy-finder

    DownloadsWeekly Downloads

    32

    Version

    5.12.0

    License

    ISC

    Unpacked Size

    31.8 kB

    Total Files

    12

    Last publish

    Collaborators

    • avatar