all files / addon/utils/ format-util.js

100% Statements 6/6
100% Branches 9/9
100% Functions 1/1
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15      105× 68×   37×   34×        
import { assign } from '@ember/polyfills';
import { isEmpty, isNone, typeOf } from '@ember/utils';
 
export default function formatUtil(formatter, defaultOptions, date, options = {}) {
  if (isEmpty(date) || typeOf(date) !== 'date') {
    return '';
  }
  if (isNone(options) || (Object.entries(options).length === 0 && options.constructor === Object)) {
    return formatter.format(date);
  } else {
    return date.toLocaleString(undefined, assign(assign({}, defaultOptions), options));
  }
}