(fromToday = true, daysBefore = 1)
| 17 | } |
| 18 | |
| 19 | export const getPixParticipants = async (fromToday = true, daysBefore = 1) => { |
| 20 | const date = fromToday |
| 21 | ? buildDate() |
| 22 | : buildDate(getNow().subtract(daysBefore, 'day')); |
| 23 | |
| 24 | const url = `${API_URL}${date}.csv`; |
| 25 | const csvPix = await axios.get(url, { |
| 26 | headers: { |
| 27 | Accept: 'text/csv', |
| 28 | 'accept-encoding': '*', |
| 29 | }, |
| 30 | responseType: 'arraybuffer', |
| 31 | }); |
| 32 | const contentType = csvPix.headers['content-type'] || ''; |
| 33 | const charsetMatch = contentType.match(/charset=([^;]+)/i); |
| 34 | const charset = (charsetMatch && charsetMatch[1].toLowerCase()) || 'latin1'; // fallback |
| 35 | |
| 36 | const decoder = new TextDecoder(charset === 'utf-8' ? 'utf-8' : 'latin1'); |
| 37 | const normalized = decoder.decode(csvPix.data); |
| 38 | return normalized; |
| 39 | }; |
| 40 | |
| 41 | /** |
| 42 | * Parse dos dados obtidos do Banco Central |
no test coverage detected