Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Interfaces

Type aliases

Functions

Type aliases

Binary

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

Specifies which group a property belongs to.

param

object value

param

object key

returns

group key

Type declaration

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

      • value: any
      • key: string | symbol

      Returns string | symbol

Indicator

Indicator: Nullary | Unary | Binary

Specifies which group a property belongs to.

param

object value

param

object key

returns

group key

Nullary

Nullary: () => string | symbol

Specifies which group a property belongs to.

returns

group key

Type declaration

    • (): string | symbol
    • Returns string | symbol

Unary

Unary: (value: any) => string | symbol

Specifies which group a property belongs to.

param

object value

returns

group key

Type declaration

    • (value: any): string | symbol
    • Parameters

      • value: any

      Returns string | symbol

Functions

Export assignment groupIn

  • Groups an object's own and inherited property values according to an indicator function.

    Notes

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

      • value: object value
      • key: object key
    • The value returned by an indicator function should be a value which can be serialized as an object key.

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

    • 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

    • indicator: Indicator

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

    Returns any

    group results

    Example

    function indicator( v ) {
        return v[ 0 ];
    }
    
    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 = groupIn( obj, indicator );
    // e.g., returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
  • Groups an object's own and inherited property values according to an indicator function.

    Notes

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

      • value: object value
      • key: object key
    • The value returned by an indicator function should be a value which can be serialized as an object key.

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

    • 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

    • options: Options

      function options

    • indicator: Indicator

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

    Returns any

    group results

    Example

    function indicator( v ) {
        return v[ 0 ];
    }
    
    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 = groupIn( obj, opts, indicator );
    // e.g., returns { 'b': [ 'a', 'b', 'd' ], 'f': [ 'c' ] }

    Example

    function indicator( v ) {
        return v[ 0 ];
    }
    
    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 = groupIn( obj, opts, indicator );
    // e.g., returns { 'b': [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], 'f': [ [ 'c', 'foo' ] ] }