index.js (2317B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 /** 22 * Group an object's own and inherited property values according to an indicator function. 23 * 24 * @module @stdlib/utils/group-in 25 * 26 * @example 27 * var groupIn = require( '@stdlib/utils/group-in' ); 28 * 29 * function indicator( v ) { 30 * return v[ 0 ]; 31 * } 32 * 33 * function Foo() { 34 * this.a = 'beep'; 35 * this.b = 'boop'; 36 * return this; 37 * } 38 * 39 * Foo.prototype = Object.create( null ); 40 * Foo.prototype.c = 'foo'; 41 * Foo.prototype.d = 'bar'; 42 * 43 * var obj = new Foo(); 44 * 45 * var out = groupIn( obj, indicator ); 46 * // e.g., returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] } 47 * 48 * @example 49 * var groupIn = require( '@stdlib/utils/group-in' ); 50 * 51 * function indicator( v ) { 52 * return v[ 0 ]; 53 * } 54 * 55 * function Foo() { 56 * this.a = 'beep'; 57 * this.b = 'boop'; 58 * return this; 59 * } 60 * 61 * Foo.prototype = Object.create( null ); 62 * Foo.prototype.c = 'foo'; 63 * Foo.prototype.d = 'bar'; 64 * 65 * var obj = new Foo(); 66 * 67 * var opts = { 68 * 'returns': 'keys' 69 * }; 70 * var out = groupIn( obj, opts, indicator ); 71 * // e.g., returns { 'b': [ 'a', 'b', 'd' ], 'f': [ 'c' ] } 72 * 73 * @example 74 * var groupIn = require( '@stdlib/utils/group-in' ); 75 * 76 * function indicator( v ) { 77 * return v[ 0 ]; 78 * } 79 * 80 * function Foo() { 81 * this.a = 'beep'; 82 * this.b = 'boop'; 83 * return this; 84 * } 85 * 86 * Foo.prototype = Object.create( null ); 87 * Foo.prototype.c = 'foo'; 88 * Foo.prototype.d = 'bar'; 89 * 90 * var obj = new Foo(); 91 * 92 * var opts = { 93 * 'returns': '*' 94 * }; 95 * var out = groupIn( obj, opts, indicator ); 96 * // e.g., returns { 'b': [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], 'f': [ [ 'c', 'foo' ] ] } 97 */ 98 99 // MODULES // 100 101 var groupIn = require( './main.js' ); 102 103 104 // EXPORTS // 105 106 module.exports = groupIn;