CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lodash-size

Gets the size of collections by returning length for array-like values or the number of enumerable properties for objects.

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.size

Gets the size of collections by returning the length for array-like values or the number of own enumerable properties for objects. This is a modularized build of lodash's _.size method, exported as a standalone Node.js module.

Package Information

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

Core Imports

var size = require('lodash.size');

For modern environments supporting ES modules:

import size from 'lodash.size';

Basic Usage

var size = require('lodash.size');

// Array size
size([1, 2, 3]);
// => 3

// Object size (number of own enumerable properties)
size({ 'a': 1, 'b': 2 });
// => 2

// String size
size('pebbles');
// => 7

// Null/undefined handling
size(null);
// => 0

size(undefined);
// => 0

// Empty values
size([]);
// => 0

size({});
// => 0

size('');
// => 0

Capabilities

Size Calculation

Gets the size of a collection by returning its length for array-like values or the number of own enumerable properties for objects.

/**
 * Gets the size of collection by returning its length for array-like
 * values or the number of own enumerable properties for objects.
 *
 * @param {Array|Object|string} collection The collection to inspect.
 * @returns {number} Returns the size of collection.
 */
function size(collection)

Parameters:

  • collection (Array|Object|string): The collection to inspect

Returns:

  • (number): The size of collection

Behavior:

  • For arrays and array-like objects (with numeric length property): returns the length value
  • For objects: returns the count of own enumerable properties (uses lodash.keys internally)
  • For strings: returns the string length
  • For null or undefined: returns 0
  • For values with invalid length properties: falls back to counting object properties

Examples:

// Arrays
size([1, 2, 3, 4, 5]);
// => 5

// Array-like objects
size({ 0: 'a', 1: 'b', 2: 'c', length: 3 });
// => 3

// Plain objects
size({ foo: 'bar', baz: 'qux' });
// => 2

// Strings
size('hello world');
// => 11

// Edge cases
size(null);          // => 0
size(undefined);     // => 0
size([]);           // => 0
size({});           // => 0
size('');           // => 0

// Objects with length property that isn't valid
size({ length: 'invalid', a: 1, b: 2 });
// => 2 (counts properties, ignores invalid length)

docs

index.md

tile.json