File tree 2 files changed +65
-0
lines changed 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ import isIterateeCall from './isIterateeCall.js' ;
2
+
3
+ /**
4
+ * Creates a function like `assign`.
5
+ *
6
+ * @private
7
+ * @param {Function } assigner The function to assign values.
8
+ * @returns {Function } Returns the new assigner function.
9
+ */
10
+ function createAssigner ( assigner ) {
11
+ return ( object , ...sources ) => {
12
+ let index = - 1 ;
13
+ let length = sources . length ;
14
+ let customizer = length > 1 ? sources [ length - 1 ] : undefined ;
15
+ const guard = length > 2 ? sources [ 2 ] : undefined ;
16
+
17
+ customizer = ( assigner . length > 3 && typeof customizer == 'function' )
18
+ ? ( length -- , customizer )
19
+ : undefined ;
20
+
21
+ if ( guard && isIterateeCall ( sources [ 0 ] , sources [ 1 ] , guard ) ) {
22
+ customizer = length < 3 ? undefined : customizer ;
23
+ length = 1 ;
24
+ }
25
+ object = Object ( object ) ;
26
+ while ( ++ index < length ) {
27
+ const source = sources [ index ] ;
28
+ if ( source ) {
29
+ assigner ( object , source , index , customizer ) ;
30
+ }
31
+ }
32
+ return object ;
33
+ } ;
34
+ }
35
+
36
+ export default createAssigner ;
Original file line number Diff line number Diff line change
1
+ import isArrayLike from '../isArrayLike.js'
2
+ import isIndex from './isIndex.js'
3
+
4
+ /**
5
+ * Checks if the given arguments are from an iteratee call.
6
+ *
7
+ * @private
8
+ * @param {* } value The potential iteratee value argument.
9
+ * @param {* } index The potential iteratee index or key argument.
10
+ * @param {* } object The potential iteratee object argument.
11
+ * @returns {boolean } Returns `true` if the arguments are from an iteratee call,
12
+ * else `false`.
13
+ */
14
+
15
+ function isIterateeCall ( value , index , object ) {
16
+ if ( ! isObject ( object ) ) {
17
+ return false ;
18
+ }
19
+ const type = typeof index ;
20
+ if ( type == 'number'
21
+ ? ( isArrayLike ( object ) && isIndex ( index , object . length ) )
22
+ : ( type == 'string' && index in object )
23
+ ) {
24
+ return eq ( object [ index ] , value ) ;
25
+ }
26
+ return false ;
27
+ }
28
+
29
+ export default isIterateeCall
You can’t perform that action at this time.
0 commit comments