Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/bifurcate-in/docs/types/index.d"

Index

Interfaces

Type aliases

Functions

Type aliases

Binary

Binary: (value: any, key: string | symbol) => boolean

Returns a boolean indicating which group an object's own and inherited property values belongs to.

param

object value

param

object key

returns

boolean indicating whether a property value should be placed in the first or second group

Type declaration

    • (value: any, key: string | symbol): boolean
    • Parameters

      • value: any
      • key: string | symbol

      Returns boolean

Nullary

Nullary: () => boolean

Returns a boolean indicating which group an object's own and inherited property values belongs to.

returns

boolean indicating whether a property value should be placed in the first or second group

Type declaration

    • (): boolean
    • Returns boolean

Predicate

Predicate: Nullary | Unary | Binary

Returns a boolean indicating which group an object's own and inherited property values belongs to.

param

object value

param

object key

returns

boolean indicating whether a property value should be placed in the first or second group

Unary

Unary: (value: any) => boolean

Returns a boolean indicating which group an object's own and inherited property values belongs to.

param

object value

returns

boolean indicating whether a property value should be placed in the first or second group

Type declaration

    • (value: any): boolean
    • Parameters

      • value: any

      Returns boolean

Functions

Export assignment bifurcateIn

  • bifurcateIn(obj: any, predicate: Predicate): Array<Array<any>>
  • bifurcateIn(obj: any, options: Options, predicate: Predicate): Array<Array<any>>
  • Splits an object's own and inherited property values into two groups according to a predicate function.

    Notes

    • When invoked, the predicate function is provided two arguments:

      • value: object value
      • key: object key
    • If a predicate function returns a truthy value, a value is placed in the first group; otherwise, a value is placed in the second group.

    • If provided an empty object with no prototype, the function returns an empty array.

    • The function iterates over an object's own and inherited properties.

    • Key iteration order is not guaranteed, and, thus, result order is not guaranteed.

    Parameters

    • obj: any

      input object

    • predicate: Predicate

      predicate function indicating which group an element in the input object belongs to

    Returns Array < Array < any > >

    group results

    Example

    function predicate( v ) {
        return v[ 0 ] === 'b';
    }
    
    function Foo() {
        this.a = 'beep';
        this.b = 'boop';
        return this;
    }
    
    Foo.prototype = Object.create( null );
    Foo.prototype.c = 'foo';
    Foo.prototype.d = 'bar';
    
    var obj = new Foo();
    
    var out = bifurcateIn( obj, predicate );
    // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
  • Splits an object's own and inherited property values into two groups according to a predicate function.

    Notes

    • When invoked, the predicate function is provided two arguments:

      • value: object value
      • key: object key
    • If a predicate function returns a truthy value, a value is placed in the first group; otherwise, a value is placed in the second group.

    • If provided an empty object with no prototype, the function returns an empty array.

    • The function iterates over an object's own and inherited properties.

    • Key iteration order is not guaranteed, and, thus, result order is not guaranteed.

    Parameters

    • obj: any
    • options: Options

      function options

    • predicate: Predicate

      predicate function indicating which group an element in the input object belongs to

    Returns Array < Array < any > >

    group results

    Example

    function predicate( v ) {
        return v[ 0 ] === 'b';
    }
    
    function Foo() {
        this.a = 'beep';
        this.b = 'boop';
        return this;
    }
    
    Foo.prototype = Object.create( null );
    Foo.prototype.c = 'foo';
    Foo.prototype.d = 'bar';
    
    var obj = new Foo();
    
    var opts = {
        'returns': 'keys'
    };
    var out = bifurcateIn( obj, opts, predicate );
    // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ]

    Example

    function predicate( v ) {
        return v[ 0 ] === 'b';
    }
    
    function Foo() {
        this.a = 'beep';
        this.b = 'boop';
        return this;
    }
    
    Foo.prototype = Object.create( null );
    Foo.prototype.c = 'foo';
    Foo.prototype.d = 'bar';
    
    var obj = new Foo();
    
    var opts = {
        'returns': '*'
    };
    var out = bifurcateIn( obj, opts, predicate );
    // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ]