CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lodash-es

Lodash utility library exported as ES6 modules for modern JavaScript applications with tree-shaking support.

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

collection.mddocs/

Collection Functions

Iteration and transformation utilities that work with arrays, objects, and other collections, including mapping, filtering, reducing, and grouping operations.

Capabilities

Collection Transformation

Core functions for transforming collections through mapping, filtering, and reduction operations.

/**
 * Creates an array of values by running each element through iteratee
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The function invoked per iteration
 * @returns {Array} Returns the new mapped array
 */
function map(collection, iteratee);

/**
 * Iterates over elements of collection, returning an array of all elements predicate returns truthy for
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} predicate - The function invoked per iteration
 * @returns {Array} Returns the new filtered array
 */
function filter(collection, predicate);

/**
 * Reduces collection to a value which is the accumulated result of running each element through iteratee
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The function invoked per iteration
 * @param {*} accumulator - The initial value
 * @returns {*} Returns the accumulated value
 */
function reduce(collection, iteratee, accumulator);

/**
 * Like reduce but iterates over elements from right to left
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The function invoked per iteration
 * @param {*} accumulator - The initial value
 * @returns {*} Returns the accumulated value
 */
function reduceRight(collection, iteratee, accumulator);

/**
 * The opposite of filter; returns elements predicate does NOT return truthy for
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} predicate - The function invoked per iteration
 * @returns {Array} Returns the new filtered array
 */
function reject(collection, predicate);

Collection Iteration

Functions for iterating over collections with various patterns.

/**
 * Iterates over elements of collection and invokes iteratee for each element
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The function invoked per iteration
 * @returns {Array|Object} Returns collection
 */
function forEach(collection, iteratee);

/**
 * Like forEach but iterates over elements from right to left
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The function invoked per iteration
 * @returns {Array|Object} Returns collection
 */
function forEachRight(collection, iteratee);

/**
 * Alias for forEach
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The function invoked per iteration
 * @returns {Array|Object} Returns collection
 */
function each(collection, iteratee);

/**
 * Alias for forEachRight
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The function invoked per iteration
 * @returns {Array|Object} Returns collection
 */
function eachRight(collection, iteratee);

Collection Testing

Functions for testing collection elements against predicates.

/**
 * Checks if predicate returns truthy for all elements of collection
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} predicate - The function invoked per iteration
 * @returns {boolean} Returns true if all elements pass the predicate check
 */
function every(collection, predicate);

/**
 * Checks if predicate returns truthy for any element of collection
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} predicate - The function invoked per iteration
 * @returns {boolean} Returns true if any element passes the predicate check
 */
function some(collection, predicate);

/**
 * Checks if value is in collection
 * @param {Array|Object|string} collection - The collection to inspect
 * @param {*} value - The value to search for
 * @param {number} fromIndex - The index to search from
 * @returns {boolean} Returns true if value is found
 */
function includes(collection, value, fromIndex);

Collection Search

Functions for finding elements within collections.

/**
 * Iterates over elements of collection, returning the first element predicate returns truthy for
 * @param {Array|Object} collection - The collection to inspect
 * @param {Function} predicate - The function invoked per iteration
 * @param {number} fromIndex - The index to search from
 * @returns {*} Returns the matched element, else undefined
 */
function find(collection, predicate, fromIndex);

/**
 * Like find but iterates over elements from right to left
 * @param {Array|Object} collection - The collection to inspect
 * @param {Function} predicate - The function invoked per iteration
 * @param {number} fromIndex - The index to search from
 * @returns {*} Returns the matched element, else undefined
 */
function findLast(collection, predicate, fromIndex);

Collection Grouping

Functions for organizing collection elements into groups.

/**
 * Creates an object composed of keys generated from the results of running each element through iteratee
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The iteratee to transform keys
 * @returns {Object} Returns the composed aggregate object
 */
function groupBy(collection, iteratee);

/**
 * Creates an object composed of keys generated from the results of running each element through iteratee
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The iteratee to transform keys
 * @returns {Object} Returns the composed aggregate object
 */
function keyBy(collection, iteratee);

/**
 * Creates an object with the same keys as object and values generated by running each property through iteratee
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The iteratee to transform keys
 * @returns {Object} Returns the composed aggregate object
 */
function countBy(collection, iteratee);

/**
 * Creates an array of elements split into two groups
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} predicate - The function invoked per iteration
 * @returns {Array} Returns the array of grouped elements
 */
function partition(collection, predicate);

Flat Mapping

Functions that combine mapping and flattening operations.

/**
 * Creates a flattened array of values by running each element through iteratee
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The iteratee to transform elements
 * @returns {Array} Returns the new flattened array
 */
function flatMap(collection, iteratee);

/**
 * Like flatMap but recursively flattens the mapped results
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The iteratee to transform elements
 * @returns {Array} Returns the new flattened array
 */
function flatMapDeep(collection, iteratee);

/**
 * Like flatMap but recursively flattens the mapped results up to depth times
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function} iteratee - The iteratee to transform elements
 * @param {number} depth - The maximum recursion depth
 * @returns {Array} Returns the new flattened array
 */
function flatMapDepth(collection, iteratee, depth);

Collection Sorting

Functions for sorting collection elements.

/**
 * Creates an array of elements, sorted in ascending order by the results of running each element through iteratee
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function|Function[]} iteratees - The iteratees to sort by
 * @returns {Array} Returns the new sorted array
 */
function sortBy(collection, ...iteratees);

/**
 * Creates an array of elements, sorted by multiple criteria
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function[]} iteratees - The iteratees to sort by
 * @param {string[]} orders - The sort orders of iteratees
 * @returns {Array} Returns the new sorted array
 */
function orderBy(collection, iteratees, orders);

Collection Sampling

Functions for randomly sampling elements from collections.

/**
 * Gets a random element from collection
 * @param {Array|Object} collection - The collection to sample
 * @returns {*} Returns the random element
 */
function sample(collection);

/**
 * Gets n random elements at unique keys from collection up to the size of collection
 * @param {Array|Object} collection - The collection to sample
 * @param {number} n - The number of elements to sample
 * @returns {Array} Returns the random elements
 */
function sampleSize(collection, n);

/**
 * Creates an array of shuffled values, using a version of the Fisher-Yates shuffle
 * @param {Array|Object} collection - The collection to shuffle
 * @returns {Array} Returns the new shuffled array
 */
function shuffle(collection);

Collection Size and Invocation

Utility functions for collection size and method invocation.

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

/**
 * Invokes the method at path of each element in collection
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Array|Function|string} path - The path of the method to invoke or the function invoked per iteration
 * @param {...*} args - The arguments to invoke each method with
 * @returns {Array} Returns the array of results
 */
function invokeMap(collection, path, ...args);

Usage Examples

Basic Collection Operations

import { map, filter, reduce, groupBy } from "lodash-es";

const users = [
  { name: "Alice", age: 25, department: "engineering" },
  { name: "Bob", age: 30, department: "sales" },
  { name: "Charlie", age: 35, department: "engineering" },
  { name: "Diana", age: 28, department: "marketing" }
];

// Transform collection
const names = map(users, "name"); // ["Alice", "Bob", "Charlie", "Diana"]
const ages = map(users, user => user.age * 2); // [50, 60, 70, 56]

// Filter collection
const engineers = filter(users, { department: "engineering" });
const seniors = filter(users, user => user.age >= 30);

// Reduce collection
const totalAge = reduce(users, (sum, user) => sum + user.age, 0); // 118
const avgAge = totalAge / users.length; // 29.5

// Group collection
const byDepartment = groupBy(users, "department");
/* {
  engineering: [Alice, Charlie],
  sales: [Bob],
  marketing: [Diana]
} */

Advanced Collection Operations

import { partition, sortBy, orderBy, countBy, every, some } from "lodash-es";

const products = [
  { name: "Laptop", price: 999, category: "electronics", inStock: true },
  { name: "Book", price: 29, category: "books", inStock: false },
  { name: "Phone", price: 699, category: "electronics", inStock: true },
  { name: "Notebook", price: 5, category: "books", inStock: true }
];

// Partition into two groups
const [inStock, outOfStock] = partition(products, "inStock");

// Sort by single criterion
const byPrice = sortBy(products, "price");

// Sort by multiple criteria
const sorted = orderBy(products, ["category", "price"], ["asc", "desc"]);

// Count by category
const counts = countBy(products, "category");
// { electronics: 2, books: 2 }

// Test all elements
const allAffordable = every(products, product => product.price < 1000); // true
const someExpensive = some(products, product => product.price > 500); // true

Iteratee Shorthand

import { map, filter, find, sortBy } from "lodash-es";

const users = [
  { name: "Alice", profile: { age: 25, active: true } },
  { name: "Bob", profile: { age: 30, active: false } },
  { name: "Charlie", profile: { age: 35, active: true } }
];

// Property string shorthand
const names = map(users, "name"); // ["Alice", "Bob", "Charlie"]

// Deep property path shorthand
const ages = map(users, "profile.age"); // [25, 30, 35]

// Object match shorthand
const activeUsers = filter(users, { "profile.active": true });

// Array match shorthand
const specificUser = find(users, ["name", "Bob"]);

// Sort by nested property
const sortedByAge = sortBy(users, "profile.age");

Chaining Collections

import { chain } from "lodash-es";

const sales = [
  { product: "Laptop", amount: 999, region: "North" },
  { product: "Phone", amount: 699, region: "South" },
  { product: "Laptop", amount: 999, region: "South" },
  { product: "Tablet", amount: 399, region: "North" }
];

const result = chain(sales)
  .groupBy("region")
  .mapValues(regionSales => 
    chain(regionSales)
      .sumBy("amount")
      .value()
  )
  .value();
// { North: 1398, South: 1698 }

docs

array.md

collection.md

date.md

function.md

index.md

lang.md

math.md

number.md

object.md

seq.md

string.md

util.md

tile.json