src/common/mapper.js
function csvToMapping(csvString) {
  const lines = csvString.split(/\n|\r|\r\n/);
  const header = lines.shift().split(',');
  const key = header.shift();
  const now = new Date();
  const headerIdx = [];
  const fields = [];
  header.forEach((h, i) => {
    if (h === '') return;
    headerIdx.push(i);
    fields.push({key: h, format: 'text'});
  });
  const mapping = {
    created: now.toString(),
    fields: fields,
    key: key,
    mapping: {}
  };
  lines.forEach(line => {
    const values = line.split(',');
    const k = values.shift();
    mapping.mapping[k] = Array(headerIdx.length);
    headerIdx.forEach(i => {
      mapping.mapping[k][i] = values[i];
    });
  });
  return mapping;
}
function csvToMapping(csvString) {
  const lines = csvString.split(/\n|\r|\r\n/);
  const header = lines.shift().split(',');
  const key = header.shift();
  const now = new Date();
  const headerIdx = [];
  const fields = [];
  header.forEach((h, i) => {
    if (h === '') return;
    headerIdx.push(i);
    fields.push({key: h, format: 'text'});
  });
  const mapping = {
    created: now.toString(),
    fields: fields,
    key: key,
    mapping: {}
  };
  lines.forEach(line => {
    const values = line.split(',');
    const k = values.shift();
    mapping.mapping[k] = Array(headerIdx.length);
    headerIdx.forEach(i => {
      mapping.mapping[k][i] = values[i];
    });
  });
  return mapping;
}
function csvToMapping ( csvString ) { const lines = csvString . split ( / \n|\r|\r\n / ) ; const header = lines . shift ( ) . split ( ',' ) ; const key = header . shift ( ) ; const now = new Date ( ) ; const headerIdx = [ ] ; const fields = [ ] ; header . forEach ( ( h , i ) => { if ( h === '' ) return ; headerIdx . push ( i ) ; fields . push ( { key : h , format : 'text' } ) ; } ) ; const mapping = { created : now . toString ( ) , fields : fields , key : key , mapping : { } } ; lines . forEach ( line => { const values = line . split ( ',' ) ; const k = values . shift ( ) ; mapping . mapping [ k ] = Array ( headerIdx . length ) ; headerIdx . forEach ( i => { mapping . mapping [ k ] [ i ] = values [ i ] ; } ) ; } ) ; return mapping ; }
Convert csv text to field mapping
@param {string} csvString - csv data text
@return {object} field mapping
Convert csv text to field mapping