or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

lodash.isplainobject

lodash.isplainobject provides the lodash isPlainObject utility function as a standalone module for checking if a value is a plain object (an object created by the Object constructor or one with a [[Prototype]] of null). The function performs sophisticated type checking by examining the object's prototype chain and constructor function, handling edge cases like host objects in older Internet Explorer versions.

Package Information

  • Package Name: lodash.isplainobject
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.isplainobject

Core Imports

var isPlainObject = require('lodash.isplainobject');

For ES modules:

import isPlainObject from 'lodash.isplainobject';

Basic Usage

var isPlainObject = require('lodash.isplainobject');

// Check plain objects
console.log(isPlainObject({})); // => true
console.log(isPlainObject({ x: 0, y: 0 })); // => true
console.log(isPlainObject(Object.create(null))); // => true

// Check non-plain objects
console.log(isPlainObject([1, 2, 3])); // => false
console.log(isPlainObject(function() {})); // => false
console.log(isPlainObject(null)); // => false
console.log(isPlainObject(new Date())); // => false

// Check constructor function instances
function Foo() {
  this.a = 1;
}
console.log(isPlainObject(new Foo())); // => false

Capabilities

Plain Object Detection

Checks if a value is a plain object, that is, an object created by the Object constructor or one with a [[Prototype]] of null.

/**
 * Checks if value is a plain object, that is, an object created by the
 * Object constructor or one with a [[Prototype]] of null.
 * 
 * @param {*} value The value to check.
 * @returns {boolean} Returns true if value is a plain object, else false.
 */
function isPlainObject(value);

Parameters:

  • value (*): The value to check

Returns:

  • boolean: Returns true if value is a plain object, else false

Behavior:

  • Returns true for objects created via object literals ({})
  • Returns true for Object.create(null)
  • Returns true for objects created via new Object()
  • Returns false for arrays, functions, DOM elements
  • Returns false for instances of custom constructor functions
  • Returns false for null, undefined, primitives
  • Handles edge cases like host objects in older IE versions

Usage Examples:

var isPlainObject = require('lodash.isplainobject');

// Plain objects return true
isPlainObject({});                    // => true
isPlainObject({ x: 0, y: 0 });        // => true  
isPlainObject(Object.create(null));   // => true
isPlainObject(new Object());          // => true

// Non-plain objects return false
isPlainObject([1, 2, 3]);             // => false (arrays)
isPlainObject(function() {});         // => false (functions)
isPlainObject(null);                  // => false (null)
isPlainObject(undefined);             // => false (undefined)
isPlainObject(42);                    // => false (numbers)
isPlainObject('hello');               // => false (strings)
isPlainObject(true);                  // => false (booleans)
isPlainObject(new Date());            // => false (Date instances)
isPlainObject(/regex/);               // => false (RegExp instances)

// Constructor function instances return false
function CustomConstructor() {
  this.prop = 'value';
}
isPlainObject(new CustomConstructor()); // => false

// Class instances return false  
class MyClass {
  constructor() {
    this.prop = 'value';
  }
}
isPlainObject(new MyClass());         // => false