export function fileConvertSize(aSize){ aSize = Math.abs(parseInt(aSize, 10)); const def = [[1, 'octets', 0], [1024, 'ko', 0], [1024*1024, 'Mo', 1], [1024*1024*1024, 'Go', 2], [1024*1024*1024*1024, 'To', 2]]; for (let i=0; i<def.length; i++) { if (aSize<def[i][0]) { return (aSize/def[i-1][0]).toFixed(def[i-1][2]) + ' ' + def[i-1][1]; } } } export function fileConvertSizeToMo(aSize){ aSize = Math.abs(parseInt(aSize, 10)); const def = [1024*1024, 'Mo', 1]; return (aSize/def[0]).toFixed(def[2]); } export function csvToJson(csv, delimiter) { const result = []; const allLines = csv.split('\n'); const headers = allLines[0].split(delimiter).map(el => { return el.replace('\r', ''); }); const [, ...lines] = allLines; for (const line of lines) { const obj = {}; const currentLine = line.split(delimiter); for (let i = 0; i < headers.length; i++) { obj[headers[i]] = currentLine[i]; } result.push(obj); } return JSON.parse(JSON.stringify(result)); }