(username, format)
| 95 | } |
| 96 | |
| 97 | export async function fetchDataForAllYears(username, format) { |
| 98 | const years = await fetchYears(username); |
| 99 | return Promise.all( |
| 100 | years.map((year) => fetchDataForYear(year.href, year.text, format)) |
| 101 | ).then((resp) => { |
| 102 | return { |
| 103 | years: (() => { |
| 104 | const obj = {}; |
| 105 | const arr = resp.map((year) => { |
| 106 | const { contributions, ...rest } = year; |
| 107 | _.setWith(obj, [rest.year], rest, Object); |
| 108 | return rest; |
| 109 | }); |
| 110 | return format === "nested" ? obj : arr; |
| 111 | })(), |
| 112 | contributions: |
| 113 | format === "nested" |
| 114 | ? resp.reduce((acc, curr) => _.merge(acc, curr.contributions)) |
| 115 | : resp |
| 116 | .reduce((list, curr) => [...list, ...curr.contributions], []) |
| 117 | .sort((a, b) => { |
| 118 | if (a.date < b.date) return 1; |
| 119 | else if (a.date > b.date) return -1; |
| 120 | return 0; |
| 121 | }) |
| 122 | }; |
| 123 | }); |
| 124 | } |
no test coverage detected