export class Utils {
  static Initials(fullname: string): string {
    if (fullname) {
      return fullname.replace(/\W*(\w)\w*/g, '$1').toUpperCase();
    }
  }

  /**
   * Get the days difference between two dates
   *
   * @param {Date} firstDate
   * @param {Date} secondDate
   * @returns {number} Number of days between the input dates
   * @memberof Utils
   */
  static getDatesDaysDifference(firstDate: Date, secondDate: Date): number {
    const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
    return Math.round(Math.abs((firstDate.getTime() - secondDate.getTime()) / (oneDay)));
  }

  /*
  *@first letter of the word
  *
  *
  * */

  static Initial(text: string): string {
    if (text) {
      return text.charAt(0);
    }
  }

  /**
   * Generates a data url based on the file pased in
   * @param file - js plain object containing then contentType and fileContent (in base64 format)
   */
  static fileToDataURL(file) {
    return `data:${file.contentType};base64,${file.fileContent}`;
  }
}
