import { lowerFirstLetter } from '../../../helpers/stringHelpers';

const removeSpaces = (string: string) => {
  return string.replace(/\s/g, '');
};

export const parseBodyText = (body: string) => {
  return body.split(/\r\n|\n|\r/).reduce((accum: any, currentVal) => {
    const items = currentVal.trim().split(': ');
    if (items.length === 2) {
      accum[removeSpaces(lowerFirstLetter(items[0]))] = items[1];
    }

    return accum;
  }, {});
};
