format(date, pattern) {
    // Fallback pattern is set in constructor
    if (!pattern) {
      pattern = this.pattern ? this.pattern : 'YYYY-MM-DD hh:mm:ss';
    }

    pattern = pattern.replace(/\[.+]|\[|]/g, '');
    const hasTwelveFlag = /t+/gi.test(pattern);
    let parsedDate;

    if (date instanceof Date) {
      parsedDate = parseDate(date, hasTwelveFlag);
    } else {
      if (date < 0) {
        // parseInterval don't support for negative values
        date = -date;
        pattern = `-${pattern}`;
      }
      parsedDate = parseInterval(date, pattern);
    }
    // remove [] and everything inside it

    const masks = getMasks(this, parsedDate);

    const masksArr = [];
    for (const mask in masks) {
      if (Object.prototype.hasOwnProperty.call(masks, mask)) {
        masksArr.push(mask);
      }
    }
    const dateTimeRegex = new RegExp(masksArr.join('|'), 'g');

    const result = pattern.replace(dateTimeRegex, (m) => {
      let r;
      let mask;
      for (mask in masks) {
        if (Object.prototype.hasOwnProperty.call(masks, mask)) {
          r = new RegExp(mask);
          if (r.test(m)) {
            break;
          }
        }
      }
      if (!r) {
        return '';
      }
      let value;
      for (const submask in masks[mask]) {
        if (submask === m || submask.toLowerCase() === m) {
          value = masks[mask][submask];
          if (typeof value === 'undefined') {
            value = masks[mask][submask.toLowerCase()];
          }
          break;
        }
      }
      if (typeof value === 'undefined') {
        value = masks[mask].def;
      }

      if (typeof value === 'function') {
        value = value(m);
      }
      return value;
    });
    return result;
  }
/**
   * Formats a date according to given pattern
   * @param {Date} date The date to format.
   * @param {String} pattern The desired format of the date
   * var d = new Date(2013, 8, 15, 13, 55, 40, 987);
   * var n = new DateFormatter();
   * @example
   * m.format( d, 'YYYY-MM-DD hh:mm:ss.ffff') // 2013-08-15 13:55:40.9870
   * m.format( d, 'h:m:s tt') // 1:55:40 pm
   * m.format( d, 'h:m:s TT') // 1:55:40 PM
   * m.format( d, 'M/D/YYYY') // 8/15/2013
   * m.format( d, 'WWWW DD MMM') // Thursday 15 Aug
   * m.format( d, 'WWW DD MMMM @ hh:mm:ss') // Thu 15 August @ 13:55:40
   */
Formats a date according to given pattern
@param {Date} date The date to format.
Formats a date according to given pattern @param { Date } date The date to format .
format(date, pattern) {
    if (!pattern) {
      pattern = this.pattern ? this.pattern : 'YYYY-MM-DD hh:mm:ss';
    }
    pattern = pattern.replace(/\[.+]|\[|]/g, '');
    const hasTwelveFlag = /t+/gi.test(pattern);
    let parsedDate;
    if (date instanceof Date) {
      parsedDate = parseDate(date, hasTwelveFlag);
    } else {
      if (date < 0) {
        date = -date;
        pattern = `-${pattern}`;
      }
      parsedDate = parseInterval(date, pattern);
    }
    const masks = getMasks(this, parsedDate);
    const masksArr = [];
    for (const mask in masks) {
      if (Object.prototype.hasOwnProperty.call(masks, mask)) {
        masksArr.push(mask);
      }
    }
    const dateTimeRegex = new RegExp(masksArr.join('|'), 'g');
    const result = pattern.replace(dateTimeRegex, (m) => {
      let r;
      let mask;
      for (mask in masks) {
        if (Object.prototype.hasOwnProperty.call(masks, mask)) {
          r = new RegExp(mask);
          if (r.test(m)) {
            break;
          }
        }
      }
      if (!r) {
        return '';
      }
      let value;
      for (const submask in masks[mask]) {
        if (submask === m || submask.toLowerCase() === m) {
          value = masks[mask][submask];
          if (typeof value === 'undefined') {
            value = masks[mask][submask.toLowerCase()];
          }
          break;
        }
      }
      if (typeof value === 'undefined') {
        value = masks[mask].def;
      }
      if (typeof value === 'function') {
        value = value(m);
      }
      return value;
    });
    return result;
  }
format ( date , pattern ) { if ( ! pattern ) { pattern = this . pattern ? this . pattern : 'YYYY-MM-DD hh:mm:ss' ; } pattern = pattern . replace ( / \[.+]|\[|] / g , '' ) ; const hasTwelveFlag = / t+ / gi . test ( pattern ) ; let parsedDate ; if ( date instanceof Date ) { parsedDate = parseDate ( date , hasTwelveFlag ) ; } else { if ( date < 0 ) { date = - date ; pattern = ` ${ pattern } ` ; } parsedDate = parseInterval ( date , pattern ) ; } const masks = getMasks ( this , parsedDate ) ; const masksArr = [ ] ; for ( const mask in masks ) { if ( Object . prototype . hasOwnProperty . call ( masks , mask ) ) { masksArr . push ( mask ) ; } } const dateTimeRegex = new RegExp ( masksArr . join ( '|' ) , 'g' ) ; const result = pattern . replace ( dateTimeRegex , ( m ) => { let r ; let mask ; for ( mask in masks ) { if ( Object . prototype . hasOwnProperty . call ( masks , mask ) ) { r = new RegExp ( mask ) ; if ( r . test ( m ) ) { break ; } } } if ( ! r ) { return '' ; } let value ; for ( const submask in masks [ mask ] ) { if ( submask === m || submask . toLowerCase ( ) === m ) { value = masks [ mask ] [ submask ] ; if ( typeof value === 'undefined' ) { value = masks [ mask ] [ submask . toLowerCase ( ) ] ; } break ; } } if ( typeof value === 'undefined' ) { value = masks [ mask ] . def ; } if ( typeof value === 'function' ) { value = value ( m ) ; } return value ; } ) ; return result ; }
Formats a date according to given pattern
 @param {Date} date The date to format.
Formats a date according to given pattern @param { Date } date The date to format .
// Fallback pattern is set in constructor // parseInterval don't support for negative values // remove [] and everything inside it