Skip to content

isNonEmpty

Checks if a plain object has at least one own enumerable string-keyed property. null and undefined are treated as empty objects and return false.

Symbol-keyed properties are not counted. Use Object.getOwnPropertySymbols separately if symbol keys matter for your use case.

Available since v2.0.3

import { isNonEmpty } from '@helpers4/object';
// or, from the all-in-one package (same code, one install):
import { isNonEmpty } from 'helpers4/object';
isNonEmpty(value: Record<PropertyKey, unknown> | null | undefined): value is Record<PropertyKey, unknown>
ParameterTypeDescription
valueRecord<PropertyKey, unknown> | null | undefinedThe object to check

value is Record<PropertyKey, unknown> — true if the object has at least one own enumerable string-keyed property; false for empty, null, or undefined. Acts as a type guard: the if branch narrows Record<PropertyKey, unknown> | null | undefined to Record<PropertyKey, unknown>.

Check if an object has own string-keyed properties

Section titled “Check if an object has own string-keyed properties”

Returns true when at least one own enumerable string key is present.

isNonEmpty({ a: 1 })        // => true
isNonEmpty({ a: undefined }) // => true  (key exists)
isNonEmpty({})              // => false

Use isNonEmpty before looping to avoid processing empty objects.

function processConfig(config: Record<string, unknown>): void {
  if (!isNonEmpty(config)) {
    console.warn('Config is empty');
    return;
  }
  for (const key of Object.keys(config)) {
    // process each key
  }
}

View source on GitHub