CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lodash-isobject

Checks if a value is the ECMAScript language type of Object (arrays, functions, objects, regexes, etc.)

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Lodash isObject

The lodash.isobject package provides the isObject utility function from lodash v2.4.1. This function checks if a value is the ECMAScript language type of Object, including arrays, functions, objects, regexes, and other object types, but excluding null and primitives.

Package Information

  • Package Name: lodash.isobject
  • Package Type: npm
  • Language: JavaScript
  • Installation: In v2.4.1, this functionality is part of the main lodash package: npm install lodash@2.4.1

Core Imports

For lodash v2.4.1 (the main lodash package):

const _ = require('lodash');
// Use _.isObject(value)

ES6 modules (if using a bundler with lodash):

import _ from 'lodash';
// Use _.isObject(value)

Direct function access:

const { isObject } = require('lodash');
// Use isObject(value)

Basic Usage

const _ = require('lodash');

// Check objects
_.isObject({});
// => true

_.isObject({ name: 'Alice', age: 30 });
// => true

// Check arrays (they are objects in JavaScript)
_.isObject([1, 2, 3]);
// => true

_.isObject([]);
// => true

// Check functions (they are objects in JavaScript)
_.isObject(function() {});
// => true

// Check regex (objects in JavaScript)
_.isObject(/abc/);
// => true

// Check dates (objects in JavaScript)
_.isObject(new Date());
// => true

// Check wrapper objects
_.isObject(new Number(0));
// => true

_.isObject(new String(''));
// => true

// Check primitives (not objects)
_.isObject(1);
// => false

_.isObject('hello');
// => false

_.isObject(true);
// => false

// Check null (not an object per ECMAScript spec)
_.isObject(null);
// => false

// Check undefined
_.isObject(undefined);
// => false

Capabilities

Object Type Checking

Determines if a value is the ECMAScript language type of Object. This includes arrays, functions, objects, regexes, Date objects, and wrapper objects, but excludes null and primitives.

/**
 * Checks if value is the language type of Object.
 * (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
 *
 * @param {*} value The value to check.
 * @returns {boolean} Returns true if the value is an object, else false.
 */
function isObject(value)

Behavior:

  • Returns true for: objects {}, arrays [], functions, regexes /pattern/, Date objects, wrapper objects (new Number(0), new String(''))
  • Returns false for: null, primitives (numbers, strings, booleans), undefined

Implementation Details:

  • Uses internal objectTypes lookup table to map typeof results to boolean values
  • Handles V8 engine bug workarounds for consistent behavior across environments
  • Follows ECMAScript specification for Object type determination

Usage Examples:

const _ = require('lodash');

// Type checking in conditional logic
function processValue(value) {
  if (_.isObject(value)) {
    // Handle objects, arrays, functions, etc.
    console.log('Processing object-type value');
    return Object.keys(value).length;
  } else {
    // Handle primitives
    console.log('Processing primitive value');
    return String(value).length;
  }
}

// Filtering arrays by object type
const mixedArray = [1, 'hello', {}, [], function() {}, null, true];
const objectsOnly = mixedArray.filter(_.isObject);
// Result: [{}, [], function() {}]

// Validation in data processing
function validateInput(data) {
  if (!_.isObject(data)) {
    throw new Error('Input must be an object');
  }
  // Process the object...
}

Types

Since this is a JavaScript library without TypeScript definitions in v2.4.1, type information is provided as JSDoc comments:

/**
 * Internal lookup table used by isObject to determine object types
 * Maps typeof results to boolean values indicating whether they represent objects
 */
var objectTypes = {
  'boolean': false,
  'function': true,
  'object': true,
  'number': false,
  'string': false,
  'undefined': false
};

Error Handling

The isObject function does not throw errors. It safely handles all JavaScript values including:

  • null and undefined values
  • All primitive types
  • All object types
  • Edge cases and unusual values

The function always returns a boolean value and never throws exceptions.

Browser and Environment Support

This function works in all JavaScript environments supported by lodash v2.4.1:

  • All modern browsers
  • Node.js
  • Rhino
  • Other JavaScript engines

The implementation includes specific workarounds for V8 engine bugs to ensure consistent behavior across different environments.

docs

index.md

tile.json