Skip to content

Commit

Permalink
fix(format): Fix the order of merging defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Godi committed Feb 22, 2017
1 parent 4c00244 commit 3b21764
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Formats {
}

public formatNumber(value: number, format?: Intl.NumberFormatOptions): string {
let _format = mergeDeep({}, format, this.defaults.number);
let _format = mergeDeep({}, this.defaults.number, format);
return new Intl.NumberFormat([this.locale, 'en-US'], _format).format(value);
}

Expand All @@ -58,12 +58,13 @@ export class Formats {
}

public formatDate(value: any, format?: string | Intl.DateTimeFormatOptions): string {
let _value = value === null || value === undefined || value === '' ? new Date() : new Date(value);
let shortHands = mergeDeep({}, this.defaults.date);
let options: Intl.DateTimeFormatOptions = (typeof format === 'string') ? shortHands[format] : format;
if (!options || Object.keys(options).length === 0) {
options = shortHands.dateShort;
}
return new Intl.DateTimeFormat([this.locale, 'en-US'], options).format(new Date(value));
return new Intl.DateTimeFormat([this.locale, 'en-US'], options).format(_value);
}

public format(value: string, format?: string): string {
Expand Down

0 comments on commit 3b21764

Please sign in to comment.