lib/compiler.js
function compileCue (cue) {
  // TODO: check for malformed JSON
  if (typeof cue !== 'object') {
    throw new CompilerError('Cue malformed: not of type object');
  }

  if (typeof cue.identifier !== 'string' &&
      typeof cue.identifier !== 'number' &&
      cue.identifier !== null) {
    throw new CompilerError(`Cue malformed: identifier value is not a string.
    ${JSON.stringify(cue)}`);
  }

  if (isNaN(cue.start)) {
    throw new CompilerError(`Cue malformed: null start value.
    ${JSON.stringify(cue)}`);
  }

  if (isNaN(cue.end)) {
    throw new CompilerError(`Cue malformed: null end value.
    ${JSON.stringify(cue)}`);
  }

  if (cue.start >= cue.end) {
    throw new CompilerError(`Cue malformed: start timestamp greater than end
    ${JSON.stringify(cue)}`);
  }

  if (typeof cue.text !== 'string') {
    throw new CompilerError(`Cue malformed: null text value.
    ${JSON.stringify(cue)}`);
  }

  if (typeof cue.styles !== 'string') {
    throw new CompilerError(`Cue malformed: null styles value.
    ${JSON.stringify(cue)}`);
  }

  let output = '';

  if (cue.identifier.length > 0) {
    output += `${cue.identifier}\n`;
  }

  const startTimestamp = convertTimestamp(cue.start);
  const endTimestamp = convertTimestamp(cue.end);

  output += `${startTimestamp} --> ${endTimestamp}`;
  output += cue.styles ? ` ${cue.styles}` : '';
  output += `\n${cue.text}`;

  return output;
}
function compileCue (cue) {
  // TODO: check for malformed JSON
  if (typeof cue !== 'object') {
    throw new CompilerError('Cue malformed: not of type object');
  }

  if (typeof cue.identifier !== 'string' &&
      typeof cue.identifier !== 'number' &&
      cue.identifier !== null) {
    throw new CompilerError(`Cue malformed: identifier value is not a string.
    ${JSON.stringify(cue)}`);
  }

  if (isNaN(cue.start)) {
    throw new CompilerError(`Cue malformed: null start value.
    ${JSON.stringify(cue)}`);
  }

  if (isNaN(cue.end)) {
    throw new CompilerError(`Cue malformed: null end value.
    ${JSON.stringify(cue)}`);
  }

  if (cue.start >= cue.end) {
    throw new CompilerError(`Cue malformed: start timestamp greater than end
    ${JSON.stringify(cue)}`);
  }

  if (typeof cue.text !== 'string') {
    throw new CompilerError(`Cue malformed: null text value.
    ${JSON.stringify(cue)}`);
  }

  if (typeof cue.styles !== 'string') {
    throw new CompilerError(`Cue malformed: null styles value.
    ${JSON.stringify(cue)}`);
  }

  let output = '';

  if (cue.identifier.length > 0) {
    output += `${cue.identifier}\n`;
  }

  const startTimestamp = convertTimestamp(cue.start);
  const endTimestamp = convertTimestamp(cue.end);

  output += `${startTimestamp} --> ${endTimestamp}`;
  output += cue.styles ? ` ${cue.styles}` : '';
  output += `\n${cue.text}`;

  return output;
}
function compileCue ( cue ) { // TODO: check for malformed JSON if ( typeof cue !== 'object' ) { throw new CompilerError ( 'Cue malformed: not of type object' ) ; } if ( typeof cue . identifier !== 'string' && typeof cue . identifier !== 'number' && cue . identifier !== null ) { throw new CompilerError ( ` ${ JSON . stringify ( cue ) } ` ) ; } if ( isNaN ( cue . start ) ) { throw new CompilerError ( ` ${ JSON . stringify ( cue ) } ` ) ; } if ( isNaN ( cue . end ) ) { throw new CompilerError ( ` ${ JSON . stringify ( cue ) } ` ) ; } if ( cue . start >= cue . end ) { throw new CompilerError ( ` ${ JSON . stringify ( cue ) } ` ) ; } if ( typeof cue . text !== 'string' ) { throw new CompilerError ( ` ${ JSON . stringify ( cue ) } ` ) ; } if ( typeof cue . styles !== 'string' ) { throw new CompilerError ( ` ${ JSON . stringify ( cue ) } ` ) ; } let output = '' ; if ( cue . identifier . length > 0 ) { output += ` ${ cue . identifier } \n ` ; } const startTimestamp = convertTimestamp ( cue . start ) ; const endTimestamp = convertTimestamp ( cue . end ) ; output += ` ${ startTimestamp } ${ endTimestamp } ` ; output += cue . styles ? ` ${ cue . styles } ` : '' ; output += ` \n ${ cue . text } ` ; return output ; }
Compile a single cue block.

@param {array} cue Array of content for the cue

@returns {object} cue Cue object with start, end, text and styles.
Null if it's a note
Compile a single cue block .