File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ yarn add populate-array
11
11
```
12
12
13
13
## Import
14
+
14
15
``` javascript
15
16
// ES6:
16
17
import {populateArray } from ' populate-array' ;
@@ -44,39 +45,38 @@ for (const user of users) {
44
45
populateArray (users , ' country' , {
45
46
each: getCountryFn
46
47
});
47
-
48
48
// Result:
49
- // @formatter:off
49
+
50
50
[
51
- {
52
- id: 1 ,
53
- name: ' John Doe' ,
54
- country: {
55
- name: ' United States' ,
56
- iso2: ' US'
51
+ {
52
+ id: 1 ,
53
+ name: ' John Doe' ,
54
+ country: {
55
+ name: ' United States' ,
56
+ iso2: ' US'
57
+ }
57
58
}
58
- }
59
- // ... and so on
59
+ // ... and so on
60
60
]
61
- // @formatter:on
62
61
```
63
62
64
63
## Arguments
64
+
65
65
The populateArray function takes three arguments:
66
66
67
67
- ` array ` : The array of objects to populate.
68
68
- ` path ` : The path of the objects to populate.
69
69
- ` options ` : The options object.
70
70
71
71
** Path Note:**
72
- This package makes use of ` lodash.get ` to get the value of a key in an object and ` lodash.set ` to set the value of a key in an object.
72
+ This package makes use of ` lodash.get ` to get the value of a key in an object and ` lodash.set ` to set the value of a key
73
+ in an object.
73
74
So nested keys are supported. e.g. ` user.address.city ` using dot notation.
74
75
75
76
## Just that?
76
77
77
78
No!! ☺️ There's more to the ` populateArray ` function, and they are packed in its options.
78
79
79
-
80
80
## Options
81
81
82
82
- [ as] ( #as )
You can’t perform that action at this time.
0 commit comments