index.js
function convert(source) {
  let currentKey = "",
      currentValue = "",
      objectNames = [],
      output = {},
      parentObj = {},
      lines = source.split(NEW_LINE),
      splitAt;

  let currentObj = output;
  let parents = [];

  for (let i = 0; i < lines.length; i++) {
    let line = lines[i];
    if (line.charAt(0) === " ") {
      currentObj[currentKey] += line.substr(1);

    } else {
      splitAt = line.indexOf(":");

      if (splitAt < 0) {
        continue;
      }

      currentKey = line.substr(0, splitAt);
      currentValue = line.substr(splitAt + 1);

      switch (currentKey) {
        case "BEGIN":
          parents.push(parentObj);
          parentObj = currentObj;
          if (parentObj[currentValue] == null) {
            parentObj[currentValue] = [];
          }
          // Create a new object, store the reference for future uses
          currentObj = {};
          parentObj[currentValue].push(currentObj);
          break;
        case "END":
          currentObj = parentObj;
          parentObj = parents.pop();
          break;
        default:
          if(currentObj[currentKey]) {
            if(!Array.isArray(currentObj[currentKey])) {
              currentObj[currentKey] = [currentObj[currentKey]];
            }
            currentObj[currentKey].push(currentValue);
          } else {
            currentObj[currentKey] = currentValue;
          }
      }
    }
  }
  return output;
}
function convert(source) {
  let currentKey = "",
      currentValue = "",
      objectNames = [],
      output = {},
      parentObj = {},
      lines = source.split(NEW_LINE),
      splitAt;

  let currentObj = output;
  let parents = [];

  for (let i = 0; i < lines.length; i++) {
    let line = lines[i];
    if (line.charAt(0) === " ") {
      currentObj[currentKey] += line.substr(1);

    } else {
      splitAt = line.indexOf(":");

      if (splitAt < 0) {
        continue;
      }

      currentKey = line.substr(0, splitAt);
      currentValue = line.substr(splitAt + 1);

      switch (currentKey) {
        case "BEGIN":
          parents.push(parentObj);
          parentObj = currentObj;
          if (parentObj[currentValue] == null) {
            parentObj[currentValue] = [];
          }
          // Create a new object, store the reference for future uses
          currentObj = {};
          parentObj[currentValue].push(currentObj);
          break;
        case "END":
          currentObj = parentObj;
          parentObj = parents.pop();
          break;
        default:
          if(currentObj[currentKey]) {
            if(!Array.isArray(currentObj[currentKey])) {
              currentObj[currentKey] = [currentObj[currentKey]];
            }
            currentObj[currentKey].push(currentValue);
          } else {
            currentObj[currentKey] = currentValue;
          }
      }
    }
  }
  return output;
}
function convert ( source ) { let currentKey = "" , currentValue = "" , objectNames = [ ] , output = { } , parentObj = { } , lines = source . split ( NEW_LINE ) , splitAt ; let currentObj = output ; let parents = [ ] ; for ( let i = 0 ; i < lines . length ; i ++ ) { let line = lines [ i ] ; if ( line . charAt ( 0 ) === " " ) { currentObj [ currentKey ] += line . substr ( 1 ) ; } else { splitAt = line . indexOf ( ":" ) ; if ( splitAt < 0 ) { continue ; } currentKey = line . substr ( 0 , splitAt ) ; currentValue = line . substr ( splitAt + 1 ) ; switch ( currentKey ) { case "BEGIN" : parents . push ( parentObj ) ; parentObj = currentObj ; if ( parentObj [ currentValue ] == null ) { parentObj [ currentValue ] = [ ] ; } // Create a new object, store the reference for future uses currentObj = { } ; parentObj [ currentValue ] . push ( currentObj ) ; break ; case "END" : currentObj = parentObj ; parentObj = parents . pop ( ) ; break ; default : if ( currentObj [ currentKey ] ) { if ( ! Array . isArray ( currentObj [ currentKey ] ) ) { currentObj [ currentKey ] = [ currentObj [ currentKey ] ] ; } currentObj [ currentKey ] . push ( currentValue ) ; } else { currentObj [ currentKey ] = currentValue ; } } } } return output ; }
Take ical string data and convert to JSON

@param {string} source
@returns {Object}
Take ical string data and convert to JSON