1
1
import identity from './identity' ;
2
+ import _get from '../utils/get' ;
2
3
3
- function matcher ( object ) {
4
- return ( compareObject ) => {
5
- if ( compareObject === object ) return true ;
4
+ const defaultStrategy = {
5
+ get : _get ,
6
+ } ;
6
7
7
- return Object . keys ( object )
8
- . every ( ( key ) => object [ key ] === compareObject [ key ] ) ;
9
- } ;
10
- }
11
8
12
- function propChecker ( prop ) {
13
- return ( object ) => object && ! ! object [ prop ] ;
14
- }
9
+ export function createIteratee ( s = defaultStrategy ) {
10
+ function matcher ( object ) {
11
+ return ( compareObject ) => {
12
+ if ( compareObject === object ) return true ;
15
13
16
- export default function iteratee ( value ) {
17
- if ( typeof value === 'function' ) {
18
- return value ;
14
+ return Object . keys ( object )
15
+ . every ( ( key ) => s . get ( object , key ) === s . get ( compareObject , key ) ) ;
16
+ } ;
19
17
}
20
18
21
- if ( value === null ) {
22
- return identity ;
19
+ function propChecker ( prop ) {
20
+ return ( object ) => object && ! ! s . get ( object , prop ) ;
23
21
}
24
22
25
- if ( typeof value === 'object' ) {
26
- return matcher ( value ) ;
27
- }
23
+ return ( value ) => {
24
+ if ( typeof value === 'function' ) {
25
+ return value ;
26
+ }
28
27
29
- return propChecker ( value ) ;
28
+ if ( value === null ) {
29
+ return identity ;
30
+ }
31
+
32
+ if ( typeof value === 'object' ) {
33
+ return matcher ( value ) ;
34
+ }
35
+
36
+ return propChecker ( value ) ;
37
+ } ;
30
38
}
31
39
40
+ const iteratee = createIteratee ( ) ;
41
+
32
42
export function iterateeValue ( data , value ) {
33
43
if ( typeof value === 'function' ) {
34
44
return value ( data ) ;
@@ -42,3 +52,5 @@ export function iterateeValue(data, value) {
42
52
43
53
return iteratee ( value ) ( data ) ;
44
54
}
55
+
56
+ export default iteratee ;
0 commit comments