Options
All
  • Public
  • Public/Protected
  • All
Menu

Module iteratee

Index

Functions Util

Util Functions

  • default(func: any): ((...args: any[]) => any)
  • Creates a function that invokes func with the arguments of the created function. If func is a property name, the created function returns the property value for a given element. If func is an array or object, the created function returns true for elements that contain the equivalent source properties, otherwise it returns false.

    since

    5.5.0

    example
    var users = [
    { 'user': 'barney', 'age': 36, 'active': true },
    { 'user': 'fred', 'age': 40, 'active': false }
    ];

    // The `matches` iteratee shorthand.
    filter(users, iteratee({ 'user': 'barney', 'active': true }));
    // => [{ 'user': 'barney', 'age': 36, 'active': true }]

    // The `matchesProperty` iteratee shorthand.
    filter(users, iteratee(['user', 'fred']));
    // => [{ 'user': 'fred', 'age': 40 }]

    // The `property` iteratee shorthand.
    map(users, iteratee('user'));
    // => ['barney', 'fred']

    // Create custom iteratee shorthands.
    iteratee = wrap(iteratee, function(iteratee, func) {
    return !isRegExp(func) ? iteratee(func) : function(string) {
    return func.test(string);
    };
    });

    filter(['abc', 'def'], /ef/);
    // => ['def']

    Parameters

    • func: any

      The value to convert to a callback.

    Returns ((...args: any[]) => any)

    Returns the callback.

      • (...args: any[]): any
      • Creates a function that invokes func with the arguments of the created function. If func is a property name, the created function returns the property value for a given element. If func is an array or object, the created function returns true for elements that contain the equivalent source properties, otherwise it returns false.

        since

        5.5.0

        category

        Util

        example
        var users = [
        { 'user': 'barney', 'age': 36, 'active': true },
        { 'user': 'fred', 'age': 40, 'active': false }
        ];

        // The `matches` iteratee shorthand.
        filter(users, iteratee({ 'user': 'barney', 'active': true }));
        // => [{ 'user': 'barney', 'age': 36, 'active': true }]

        // The `matchesProperty` iteratee shorthand.
        filter(users, iteratee(['user', 'fred']));
        // => [{ 'user': 'fred', 'age': 40 }]

        // The `property` iteratee shorthand.
        map(users, iteratee('user'));
        // => ['barney', 'fred']

        // Create custom iteratee shorthands.
        iteratee = wrap(iteratee, function(iteratee, func) {
        return !isRegExp(func) ? iteratee(func) : function(string) {
        return func.test(string);
        };
        });

        filter(['abc', 'def'], /ef/);
        // => ['def']

        Parameters

        • Rest ...args: any[]

        Returns any

        Returns the callback.