Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
feat(formatters): add percent formatter
Browse files Browse the repository at this point in the history
Aimed at formatting crit chance values
  • Loading branch information
eps1lon committed Jun 19, 2018
1 parent c8adc45 commit e2a67ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/localize/formatters/__tests__/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ it('should match all the formats', () => {

expect(factory('mod_value_to_item_class')(500)).toBe('Amulets');
expect(factory('mod_value_to_item_class')(1)).toBe('Rings');

expect(factory('fraction_to_percent_2p')(1)).toBe('100.00');
expect(factory('fraction_to_percent_2p')(0.5345)).toBe('53.45');
expect(factory('fraction_to_percent_2p')(0.01234)).toBe('1.23');
});

describe('regxp', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/localize/formatters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ export const formatters: { [key: string]: Formatter } = {
inverse: () => Number.NaN,
regexp: '#',
negates: false
},
fraction_to_percent_2p: {
format: n => (n * 100).toFixed(2),
inverse: s => +s / 100,
regexp: `${NUMBER}\\.?\\d{2}`,
negates: false
}
};

Expand Down

0 comments on commit e2a67ab

Please sign in to comment.