3
3
*/
4
4
export default class ObjectHelpers {
5
5
6
- /***
7
- * Groups an array by key
8
- * @param array
9
- * @param key
10
- * @returns {* }
11
- */
12
- static groupBy ( array , key ) {
13
- return array . reduce ( ( acc , item ) => {
14
- ( acc [ item [ key ] ] = acc [ item [ key ] ] || [ ] ) . push ( item ) ;
15
- return acc ;
16
- } , { } ) ;
17
- }
18
-
19
6
/***
20
7
* Makes a single level array distinct
21
8
* @param array
@@ -25,29 +12,6 @@ export default class ObjectHelpers {
25
12
return array . reduce ( ( a , b ) => ( a . includes ( b ) ) ? a : a . concat ( b ) , [ ] ) ;
26
13
}
27
14
28
- /***
29
- * Makes an object array distinct ( uses deep checking )
30
- * @param array
31
- * @returns {* }
32
- */
33
- static distinctObjectArray ( array ) {
34
- return array . reduce ( ( a , b ) => ( ! ! a . find ( x => this . deepEqual ( x , b ) ) ) ? a : a . concat ( b ) , [ ] ) ;
35
- }
36
-
37
- /***
38
- * Checks deep equality for objects
39
- * @param objA
40
- * @param objB
41
- * @returns {boolean }
42
- */
43
- static deepEqual ( objA , objB ) {
44
- const keys = Object . keys , typeA = typeof objA , typeB = typeof objB ;
45
- return objA && objB && typeA === 'object' && typeA === typeB ? (
46
- keys ( objA ) . length === keys ( objB ) . length &&
47
- keys ( objA ) . every ( key => this . deepEqual ( objA [ key ] , objB [ key ] ) )
48
- ) : ( objA === objB ) ;
49
- }
50
-
51
15
/***
52
16
* Flattens an array into a single dimension
53
17
* @param array
@@ -59,27 +23,4 @@ export default class ObjectHelpers {
59
23
) ;
60
24
}
61
25
62
- /***
63
- * Flattens an objects keys into a single dimension
64
- * @param object
65
- * @returns {* }
66
- */
67
- static objectToFlatKeys ( object ) {
68
- return this . flatten ( Object . keys ( object ) . map ( key => {
69
- if ( object [ key ] !== null && typeof object [ key ] === 'object' ) return this . objectToFlatKeys ( object [ key ] )
70
- else return key ;
71
- } ) )
72
- }
73
-
74
- /***
75
- * Gets a field from an object by string dot notation, such as `location.country.code`
76
- * @param object
77
- * @param dotNotation
78
- * @returns {* }
79
- */
80
- static getFieldFromObjectByDotNotation ( object , dotNotation ) {
81
- let props = dotNotation . split ( "." ) ;
82
- return props . reduce ( ( obj , key ) => obj [ key ] , object )
83
- }
84
-
85
26
}
0 commit comments