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

Commit

Permalink
Display as single value if range.min equals range.max
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
eps1lon committed Oct 8, 2017
1 parent a891e0a commit c2f06c9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/eps1lon/poe-mods/compare/v0.2.1...HEAD)
### Changed
- Ranges where min and max value are equal are now displayed as single values. (Closes [#2](https://github.com/eps1lon/poe-i18n/issues/2))

## [0.2.1](https://github.com/eps1lon/poe-mods/compare/v0.2.0...v0.2.1) (2017-20-04)
### Added
Expand Down
5 changes: 5 additions & 0 deletions src/localize/__tests__/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ it('should support ranges', () => {
expect(factory('negate')([-20, -10])).toBe('(20 - 10)');
expect(factory('per_minute_to_per_second_0dp')([120, 240])).toBe('(2 - 4)');
});

it('should not display as range if min == max', () => {
expect(factory('id')([-10, -10])).toBe('-10');
expect(factory('id')([-10, -11])).toBe('(-10 - -11)');
});
6 changes: 5 additions & 1 deletion src/localize/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export default function factory<T>(

return (value: StatValue) => {
if (isRange(value)) {
return `(${formatter(value[0])} - ${formatter(value[1])})`;
if (value[0] === value[1]) {
return String(formatter(value[0]));
} else {
return `(${formatter(value[0])} - ${formatter(value[1])})`;
}
} else {
return String(formatter(value));
}
Expand Down

0 comments on commit c2f06c9

Please sign in to comment.