CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lodash-isarguments

The lodash method _.isArguments exported as a module that checks if value is likely an arguments object.

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

lodash.isarguments

The lodash method _.isArguments exported as a module that checks if a value is likely an arguments object. This is a modularized version from the lodash utility library that provides reliable cross-browser detection of JavaScript arguments objects.

Package Information

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

Core Imports

var isArguments = require('lodash.isarguments');

For ES modules:

import isArguments from 'lodash.isarguments';

Basic Usage

var isArguments = require('lodash.isarguments');

// Check arguments objects
(function() {
  console.log(isArguments(arguments)); // => true
})(1, 2, 3);

// Check non-arguments objects
console.log(isArguments([1, 2, 3])); // => false
console.log(isArguments({})); // => false
console.log(isArguments('string')); // => false
console.log(isArguments(null)); // => false

Architecture

The lodash.isarguments function implements a robust, cross-browser compatible detection strategy for JavaScript arguments objects:

Detection Strategy:

  • Primary Method: Uses Object.prototype.toString.call(value) === '[object Arguments]' when the environment supports native toStringTag for arguments objects
  • Fallback Method: In older environments without toStringTag support, falls back to checking the callee property: hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee')

Helper Functions:

  • isObjectLike: Pre-filters values to ensure they are objects (value && typeof value == 'object')
  • isLength: Validates the length property is a valid array-like length (typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER)

Cross-Browser Compatibility:

  • Automatically detects environment capabilities via support.argsTag feature detection
  • Seamlessly switches between detection methods without user intervention
  • Handles edge cases across different JavaScript engines and browser versions

Capabilities

Arguments Object Detection

Checks if a value is likely an arguments object using cross-browser compatible detection methods.

/**
 * Checks if `value` is likely an `arguments` object.
 *
 * @param {*} value - Any JavaScript value to test for arguments object characteristics.
 *                    Accepts primitives, objects, arrays, functions, null, undefined, etc.
 * @returns {boolean} Returns `true` when value is a genuine arguments object from a function call,
 *                    `false` for all other values including arrays, plain objects, and primitives.
 * 
 * @example
 * // Arguments object detection
 * (function() { return isArguments(arguments); })(); // => true
 * 
 * @example  
 * // Non-arguments objects
 * isArguments([1, 2, 3]); // => false (array)
 * isArguments({ '0': 1, length: 1 }); // => false (plain object)
 */
function isArguments(value)

Parameters:

  • value (*): The value to check

Returns:

  • (boolean): Returns true if value is correctly classified as an arguments object, else false

Implementation Details:

The function implements a sophisticated dual-path detection algorithm:

Primary Detection (Modern Environments):

  • Uses Object.prototype.toString.call(value) === '[object Arguments]' when support.argsTag is available
  • Relies on native JavaScript engine support for arguments object toStringTag
  • Combined with isObjectLike(value) pre-filtering and isLength(value.length) validation

Fallback Detection (Legacy Environments):

  • Activates when !support.argsTag (older browsers/engines without native arguments detection)
  • Checks hasOwnProperty.call(value, 'callee') - arguments objects have a callee property
  • Validates !propertyIsEnumerable.call(value, 'callee') - callee should not be enumerable
  • Still uses isObjectLike() and isLength() helper validation

Helper Function Roles:

  • isObjectLike(value): Ensures value && typeof value == 'object' to filter out primitives
  • isLength(value.length): Validates length as valid array-like index (number, >= 0, integer, <= MAX_SAFE_INTEGER)
  • Feature Detection: support.argsTag determines which detection path to use automatically

Edge Cases:

  • Returns false for arrays, even though they have similar structure
  • Returns false for objects that mimic arguments structure (e.g., { '0': 1, 'callee': function() {}, 'length': 1 })
  • Returns false for all primitive values (strings, numbers, booleans)
  • Returns false for null and undefined
  • Works correctly with arguments objects from different realms/frames

Usage Examples:

var isArguments = require('lodash.isarguments');

// Real arguments object
(function() {
  return isArguments(arguments); // => true
})();

// Array (false positive check)
isArguments([1, 2, 3]); // => false

// Object that looks like arguments
isArguments({ 
  '0': 1, 
  'callee': function() {}, 
  'length': 1 
}); // => false

// Primitive values
isArguments('string'); // => false
isArguments(42); // => false
isArguments(true); // => false
isArguments(null); // => false
isArguments(undefined); // => false

// Other objects
isArguments(new Date()); // => false
isArguments(new Error()); // => false
isArguments(/regex/); // => false
isArguments(function() {}); // => false
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.isarguments@3.1.x
Publish Source
CLI
Badge
tessl/npm-lodash-isarguments badge