npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

v_is_empty_value

v2.1.10

Published

Simple checker functions for empty values. Can check if a value is empty or not. [ isEmpty(val) / isNotEmpty(val) ]

Downloads

33

Readme

👨‍💻 v_is_empty_value

Simple checker for Empty/NotEmpty values. Checking Numbers, Null, NaN, Strings, Objects, Arrays...Will also detect instance of Date() object and return "not-empty" value for it.

Codacy Badge CodeQL njsscan sarif

General Information

It provides 4 functions to check if a value is empty or not. These are named as follows:

  • isEmpty(v) : Checks if a value is empty. Returns true if the value is empty, else false.
  • isNotEmpty(v) : Checks if a value is not empty. Returns true if the value is not empty, else false.
  • isEmptyNested(v) : Checks if a nested value is empty.
    • It will check nested values in Objects and Arrays.
    • It will use recursion to check nested values.
    • Uses isEmpty(v) to check if a value is empty under the hood.
    • Returns true if the nested value is empty, else false.
  • isNotEmptyNested(v) : Checks if a nested value is not empty. Returns true if the nested value is not empty, else false.

    NOTE: This basically does the opposite of isEmptyNested(v).

Base Example

// import { isEmpty, isNotEmpty, isEmptyNested, isNotEmptyNested } from 'v_is_empty_value'
const { isEmpty, isNotEmpty, isEmptyNested, isNotEmptyNested } = require('v_is_empty_value')

isEmpty(v) // Checks if a value is empty.

isNotEmpty(v) // Checks if a value is not empty.

isEmptyNested(v) // Checks if a nested value is empty.

isNotEmptyNested(v) // Checks if a nested value is not empty.

☑ Things it confirms Empty

  • Undefined / Empty
console.log(isEmpty()) // prints "true"
console.log(isNotEmpty()) // prints "false"
  • Empty String
console.log(isEmpty('')) // prints "true"
console.log(isNotEmpty('')) // prints "false"
  • null
console.log(isEmpty(null)) // prints "true"
console.log(isNotEmpty(null)) // prints "false"
  • Undefined
console.log(isEmpty(undefined)) // prints "true"
console.log(isNotEmpty(undefined)) // prints "false"
  • Empty Object
console.log(isEmpty({})) // prints "true"
console.log(isNotEmpty({})) // prints "false"
  • Empty Array
console.log(isEmpty([])) // prints "true"
console.log(isNotEmpty([])) // prints "false"

☑ Few things it confirms NOT Empty

  • String with some length/value.
isEmpty('demo_password_123456') // prints "false"
isNotEmpty('demo_password_123456') // prints "true"
  • NaN
console.log(isEmpty(NaN)) // prints "false"
console.log(isNotEmpty(NaN)) // prints "true"
  • Date instance.
isEmpty(new Date()) // prints "false"
isNotEmpty(new Date()) // prints "true"
  • Error instance.
isEmpty(new Error()) // prints "false"
isNotEmpty(new Error()) // prints "true"
  • Promise instance.
isEmpty(new Promise((resolve, reject) => resolve(true))) // prints "false"
isNotEmpty(new Promise((resolve, reject) => resolve(true))) // prints "true"
  • Number instance.
console.log(Number()) // prints "0"
console.log(isEmpty(Number())) // prints "false"
console.log(isNotEmpty(Number())) // prints "true"

Note: It will return false for 0 and -0 as well.

  • Nested Object : confirms not empty even though it has empty values.
const nestedEmptyObject = {
  demo: null,
  yea: undefined,
  iKnowMan: {
    wtf: null,
    moreNull: null
  }
}

// NOTE: Returns "false" just because "iKnowMan" is an object.
console.log(isEmpty(nestedEmptyObject)) // prints "false"
console.log(isNotEmpty(nestedEmptyObject)) // prints "true"

// NOTE: Better use "isEmptyNested(v)" to check nested values.
console.log(isEmptyNested(nestedEmptyObject)) // prints "true"
console.log(isNotEmptyNested(nestedEmptyObject)) // prints "false"

📜 More Info:
Check the test cases for more examples.


🚀 Performance Benchmark

This will basically run the functions mentioned for 25mil. times and will print the time taken for each function to complete.

📋 Test setup:

  • AMD Ryzen 7 2700X Eight-Core Processor 3.70 GHz
  • 16 GB 3000 MHz DDR4
  • Patriot P300 256GB M.2 NVMe
  • Windows 10 Pro 64-bit
  • Node.js v20.10.0

📊 Current performance:

  • isEmpty(v) : ~ 40,000 ops/ms [ 40 mil. ops/sec ]
  • isNotEmpty(v) : ~ 32,000 ops/ms [ 32 mil. ops/sec ]
  • isEmptyNested(v) : ~ 30,000 ops/ms [ 30 mil. ops/sec ]
  • isNotEmptyNested(v) : ~ 31,000 ops/ms [ 31 mil. ops/sec ]

📑 Related links :