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

function.mddocs/

Function Functions

Function composition, decoration, and control flow utilities including debouncing, throttling, currying, and memoization.

Capabilities

Function Timing Control

Functions for controlling when and how often functions execute.

/**
 * Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked
 * @param {Function} func - The function to debounce
 * @param {number} wait - The number of milliseconds to delay
 * @param {Object} options - The options object
 * @param {boolean} options.leading - Specify invoking on the leading edge of the timeout
 * @param {number} options.maxWait - The maximum time func is allowed to be delayed before it's invoked
 * @param {boolean} options.trailing - Specify invoking on the trailing edge of the timeout
 * @returns {Function} Returns the new debounced function
 */
function debounce(func, wait, options);

/**
 * Creates a throttled function that only invokes func at most once per every wait milliseconds
 * @param {Function} func - The function to throttle
 * @param {number} wait - The number of milliseconds to throttle invocations to
 * @param {Object} options - The options object
 * @param {boolean} options.leading - Specify invoking on the leading edge of the timeout
 * @param {boolean} options.trailing - Specify invoking on the trailing edge of the timeout
 * @returns {Function} Returns the new throttled function
 */
function throttle(func, wait, options);

/**
 * Defers invoking the func until the current call stack has cleared
 * @param {Function} func - The function to defer
 * @param {...*} args - The arguments to invoke func with
 * @returns {number} Returns the timer id
 */
function defer(func, ...args);

/**
 * Invokes func after wait milliseconds
 * @param {Function} func - The function to delay
 * @param {number} wait - The number of milliseconds to delay invocation
 * @param {...*} args - The arguments to invoke func with
 * @returns {number} Returns the timer id
 */
function delay(func, wait, ...args);

Function Invocation Control

Functions for controlling how many times and when functions are invoked.

/**
 * Creates a function that invokes func once it's called n or more times
 * @param {number} n - The number of calls before func is invoked
 * @param {Function} func - The function to restrict
 * @returns {Function} Returns the new restricted function
 */
function after(n, func);

/**
 * Creates a function that invokes func, with up to n calls, while it's called less than n times
 * @param {number} n - The number of calls at which func is no longer invoked
 * @param {Function} func - The function to restrict
 * @returns {Function} Returns the new restricted function
 */
function before(n, func);

/**
 * Creates a function that is restricted to invoking func once
 * @param {Function} func - The function to restrict
 * @returns {Function} Returns the new restricted function
 */
function once(func);

Function Argument Manipulation

Functions for manipulating function arguments and arity.

/**
 * Creates a function that invokes func with up to n arguments, ignoring any additional arguments
 * @param {Function} func - The function to cap arguments for
 * @param {number} n - The arity cap
 * @returns {Function} Returns the new capped function
 */
function ary(func, n);

/**
 * Creates a function that accepts up to one argument, ignoring any additional arguments
 * @param {Function} func - The function to cap arguments for
 * @returns {Function} Returns the new capped function
 */
function unary(func);

/**
 * Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives
 * @param {Function} func - The function to bind
 * @param {*} thisArg - The this binding of func
 * @param {...*} partials - The arguments to be partially applied
 * @returns {Function} Returns the new bound function
 */
function bind(func, thisArg, ...partials);

/**
 * Creates a function that invokes func with partials prepended to the arguments it receives
 * @param {Function} func - The function to partially apply arguments to
 * @param {...*} partials - The arguments to be partially applied
 * @returns {Function} Returns the new partially applied function
 */
function partial(func, ...partials);

/**
 * Like partial but partials are appended to the arguments it receives
 * @param {Function} func - The function to partially apply arguments to
 * @param {...*} partials - The arguments to be partially applied
 * @returns {Function} Returns the new partially applied function
 */
function partialRight(func, ...partials);

/**
 * Creates a function that invokes func with arguments arranged according to the specified indexes
 * @param {Function} func - The function to rearrange arguments for
 * @param {...(number|number[])} indexes - The arranged argument indexes
 * @returns {Function} Returns the new function
 */
function rearg(func, ...indexes);

/**
 * Creates a function that invokes func with the transform results of the provided functions
 * @param {Function} func - The function to wrap
 * @param {...(Function|Function[])} transforms - The argument transforms
 * @returns {Function} Returns the new function
 */
function overArgs(func, ...transforms);

Function Currying

Functions for creating curried versions of functions.

/**
 * Creates a function that accepts arguments of func and either invokes func returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining func arguments
 * @param {Function} func - The function to curry
 * @param {number} arity - The arity of func
 * @returns {Function} Returns the new curried function
 */
function curry(func, arity);

/**
 * Like curry but arguments are applied to func in the manner of _.partialRight instead of _.partial
 * @param {Function} func - The function to curry
 * @param {number} arity - The arity of func
 * @returns {Function} Returns the new curried function
 */
function curryRight(func, arity);

Function Composition and Flow

Functions for composing and chaining function calls.

/**
 * Creates a function that invokes func with arguments flipped
 * @param {Function} func - The function to flip arguments for
 * @returns {Function} Returns the new flipped function
 */
function flip(func);

/**
 * Creates a function that negates the result of the predicate func
 * @param {Function} predicate - The predicate to negate
 * @returns {Function} Returns the new negated function
 */
function negate(predicate);

/**
 * Creates a function that invokes the given functions with the this binding of the created function and returns their results
 * @param {...(Function|Function[])} funcs - The functions to invoke
 * @returns {Function} Returns the new function
 */
function over(...funcs);

/**
 * Creates a function that checks if all of the provided functions return truthy when invoked with the arguments it receives
 * @param {...(Function|Function[])} predicates - The predicates to check
 * @returns {Function} Returns the new function
 */
function overEvery(...predicates);

/**
 * Creates a function that checks if any of the provided functions return truthy when invoked with the arguments it receives
 * @param {...(Function|Function[])} predicates - The predicates to check
 * @returns {Function} Returns the new function
 */
function overSome(...predicates);

Function Binding

Functions for binding functions to objects and methods.

/**
 * Binds methods of an object to the object itself, overwriting the existing method
 * @param {Object} object - The object to bind and assign the bound methods to
 * @param {...(string|string[])} methodNames - The object method names to bind
 * @returns {Object} Returns object
 */
function bindAll(object, ...methodNames);

/**
 * Creates a function that invokes the method at object[key] with partials prepended to the arguments it receives
 * @param {Object} object - The object to invoke the method on
 * @param {string} key - The key of the method
 * @param {...*} partials - The arguments to be partially applied
 * @returns {Function} Returns the new bound function
 */
function bindKey(object, key, ...partials);

Conditional Function Creation

Functions for creating conditional and rule-based functions.

/**
 * Creates a function that iterates over pairs and invokes the corresponding function of the first predicate to return truthy
 * @param {Array} pairs - The predicate-function pairs
 * @returns {Function} Returns the new composite function
 */
function cond(pairs);

/**
 * Creates a function that invokes the method at a given path on source
 * @param {Array|string} path - The path of the method to invoke
 * @param {...*} args - The arguments to invoke the method with
 * @returns {Function} Returns the new invoker function
 */
function method(path, ...args);

/**
 * Creates a function that invokes the method at path of a given object
 * @param {Object} object - The object to query
 * @param {...*} args - The arguments to invoke the method with
 * @returns {Function} Returns the new invoker function
 */
function methodOf(object, ...args);

Function Flow Control

Functions for creating function pipelines and composition.

/**
 * Creates a function that returns the result of invoking the given functions with the this binding, where each successive invocation is supplied the return value of the previous
 * @param {...(Function|Function[])} funcs - The functions to invoke
 * @returns {Function} Returns the new composite function
 */
function flow(...funcs);

/**
 * Creates a function that returns the result of invoking the given functions with the this binding, where each successive invocation is supplied the return value of the previous (right-to-left)
 * @param {...(Function|Function[])} funcs - The functions to invoke
 * @returns {Function} Returns the new composite function
 */
function flowRight(...funcs);

/**
 * Creates a function that invokes object[src] with the this binding and arguments of the created function
 * @param {Object} object - The object to query
 * @param {string} src - The property name of the method to invoke
 * @returns {Function} Returns the new invoker function
 */
function conforms(source);

Framework Integration

Functions for adding methods to the lodash wrapper and extending functionality.

/**
 * Adds all own enumerable string keyed function properties of a source object to the destination object
 * @param {Object} object - The destination object
 * @param {Object} source - The object of functions to add
 * @param {Object} options - The options object
 * @param {string} options.chain - Specify whether mixins are chainable
 * @returns {Function} Returns func
 */
function mixin(object, source, options);

Function Memoization

Functions for caching function results.

/**
 * Creates a function that memoizes the result of func
 * @param {Function} func - The function to have its output memoized
 * @param {Function} resolver - The function to resolve the cache key
 * @returns {Function} Returns the new memoized function
 */
function memoize(func, resolver);

Function Rest Parameters

Functions for handling rest parameters and spreading arguments.

/**
 * Creates a function that invokes func with the this binding of the created function and an array of arguments much like Function#apply
 * @param {Function} func - The function to spread arguments over
 * @param {number} start - The start position of the spread
 * @returns {Function} Returns the new function
 */
function spread(func, start);

/**
 * Creates a function that accepts one or more arguments of func that when invoked returns the result of invoking func with all arguments from start and beyond provided as an array
 * @param {Function} func - The function to apply a rest parameter to
 * @param {number} start - The start position of the rest parameter
 * @returns {Function} Returns the new function
 */
function rest(func, start);

Function Wrapping

Functions for wrapping and decorating other functions.

/**
 * Creates a function that provides value to wrapper as its first argument
 * @param {*} value - The value to wrap
 * @param {Function} wrapper - The wrapper function
 * @returns {Function} Returns the new function
 */
function wrap(value, wrapper);

Usage Examples

Debouncing and Throttling

import { debounce, throttle } from "lodash-es";

// Debounce example - search input
const searchAPI = (query) => {
  console.log("Searching for:", query);
  // Make API call
};

const debouncedSearch = debounce(searchAPI, 300);

// Only calls searchAPI 300ms after the last input
document.getElementById("search").addEventListener("input", (e) => {
  debouncedSearch(e.target.value);
});

// Throttle example - scroll handler
const handleScroll = () => {
  console.log("Scroll position:", window.scrollY);
  // Update UI based on scroll
};

const throttledScroll = throttle(handleScroll, 100);

// Only calls handleScroll at most once every 100ms
window.addEventListener("scroll", throttledScroll);

// Advanced debounce with options
const saveData = debounce(
  (data) => {
    console.log("Saving:", data);
    // Save to server
  },
  1000,
  {
    leading: false,  // Don't call on leading edge
    trailing: true,  // Call on trailing edge (default)
    maxWait: 5000   // Force call after 5 seconds max
  }
);

Function Invocation Control

import { once, after, before } from "lodash-es";

// Execute only once
const initialize = once(() => {
  console.log("App initialized");
  // Expensive initialization logic
});

initialize(); // "App initialized"
initialize(); // Won't execute again
initialize(); // Won't execute again

// Execute after n calls
const readyAfterThree = after(3, () => {
  console.log("Ready after 3 calls");
});

readyAfterThree(); // Nothing happens
readyAfterThree(); // Nothing happens
readyAfterThree(); // "Ready after 3 calls"

// Execute while less than n calls
const limitedFunction = before(3, (x) => {
  console.log("Called with:", x);
  return x * 2;
});

limitedFunction(1); // "Called with: 1", returns 2
limitedFunction(2); // "Called with: 2", returns 4
limitedFunction(3); // Nothing happens, returns undefined

Currying and Partial Application

import { curry, partial, partialRight } from "lodash-es";

// Currying
const add = (a, b, c) => a + b + c;
const curriedAdd = curry(add);

// Use curried function
const add5 = curriedAdd(5);
const add5And3 = add5(3);
const result = add5And3(2); // 10

// Or chain immediately
const result2 = curriedAdd(1)(2)(3); // 6

// Partial application
const greet = (greeting, name, punctuation) => 
  `${greeting} ${name}${punctuation}`;

const sayHello = partial(greet, "Hello");
const hello = sayHello("Alice", "!"); // "Hello Alice!"

const addExclamation = partialRight(greet, "!");
const excited = addExclamation("Hi", "Bob"); // "Hi Bob!"

// Placeholder support
const greetAlice = partial(greet, partial.placeholder, "Alice");
const hiAlice = greetAlice("Hi", "!"); // "Hi Alice!"

Function Composition

import { flow, flowRight, over, overEvery, overSome } from "lodash-es";

// Function flow (left to right)
const addThenMultiply = flow(
  (x) => x + 1,
  (x) => x * 2,
  (x) => x - 3
);

const result = addThenMultiply(5); // ((5 + 1) * 2) - 3 = 9

// Function composition (right to left)
const multiplyThenAdd = flowRight(
  (x) => x - 3,
  (x) => x * 2,
  (x) => x + 1
);

// Over - call multiple functions with same arguments
const logAndReturn = over(
  console.log,
  (x) => x * 2
);

const doubled = logAndReturn(5); // Logs 5, returns [undefined, 10]

// OverEvery - all predicates must be true
const isPositiveEven = overEvery(
  (x) => x > 0,
  (x) => x % 2 === 0
);

console.log(isPositiveEven(4)); // true
console.log(isPositiveEven(-4)); // false

// OverSome - at least one predicate must be true
const isStringOrNumber = overSome(
  (x) => typeof x === "string",
  (x) => typeof x === "number"
);

console.log(isStringOrNumber("hello")); // true
console.log(isStringOrNumber(42)); // true
console.log(isStringOrNumber({})); // false

Memoization

import { memoize } from "lodash-es";

// Expensive recursive function
const fibonacci = memoize((n) => {
  if (n < 2) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
});

console.log(fibonacci(40)); // Fast after memoization

// Custom resolver
const getUserData = memoize(
  (user) => {
    console.log("Fetching data for:", user.id);
    // Expensive API call
    return { data: `User ${user.id} data` };
  },
  (user) => user.id // Cache key resolver
);

const user1 = { id: 1, name: "Alice" };
const user2 = { id: 1, name: "Alice Updated" };

getUserData(user1); // "Fetching data for: 1"
getUserData(user2); // Uses cache (same ID)

// Clear cache
fibonacci.cache.clear();

Advanced Function Manipulation

import { ary, flip, negate, wrap, spread, rest } from "lodash-es";

// Limit function arity
const sum = (...numbers) => numbers.reduce((a, b) => a + b, 0);
const binarySum = ary(sum, 2);

console.log(sum(1, 2, 3, 4)); // 10
console.log(binarySum(1, 2, 3, 4)); // 3 (only uses first 2 args)

// Flip arguments
const divide = (a, b) => a / b;
const flippedDivide = flip(divide);

console.log(divide(10, 2)); // 5
console.log(flippedDivide(10, 2)); // 0.2 (2 / 10)

// Negate predicate
const isEven = (x) => x % 2 === 0;
const isOdd = negate(isEven);

console.log(isEven(4)); // true
console.log(isOdd(4)); // false

// Wrap functions
const greetWrapper = wrap("Hello", (greeting, name) => 
  `${greeting} ${name}!`
);

console.log(greetWrapper("World")); // "Hello World!"

// Spread arguments
const arraySum = (arr) => arr.reduce((a, b) => a + b, 0);
const spreadSum = spread(arraySum);

console.log(spreadSum(1, 2, 3, 4)); // 10

// Rest parameters
const logAll = rest((prefix, ...args) => {
  console.log(prefix, args);
});

logAll("Numbers:", 1, 2, 3); // "Numbers: [1, 2, 3]"

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