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

Commit

Permalink
Refactored formatters
Browse files Browse the repository at this point in the history
Combined toI, toS and regexp method into a single object so
that mistakes a more obv since related methods
are closer together. This also enabled
us to extract more complex formatters into single files which might be
neccessary for mod_value_to_item_class
  • Loading branch information
eps1lon committed May 29, 2018
1 parent 93fe118 commit aba95ff
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 189 deletions.
188 changes: 0 additions & 188 deletions src/localize/formatters.ts

This file was deleted.

19 changes: 19 additions & 0 deletions src/localize/formatters/Formatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* formats a given numberic value to string
*/
export default interface Formatter {
/**
*
* @param n
*/
format(n: number): string;
/**
* inverse of #format
* @param s returnval from #format()
*/
inverse(s: string): number;
/**
* RegExp to match the value in the formatted string
*/
regexp: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import factory, {
formatters,
inverseFactory,
regexpFactory
} from '../formatters';
} from '../';

it('should throw if the specified formatter doesnt exist', () => {
expect(() => factory('foobar')).toThrowError("'foobar' not found");
Expand Down
11 changes: 11 additions & 0 deletions src/localize/formatters/__tests__/regexp_util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {NUMBER} from '../regexp_util';

it('can match hole numbers', () => {
const regexp = new RegExp(`^${NUMBER}$`);
expect(regexp.test(`${5}`)).toBe(true);
expect(regexp.test(`${-123}`)).toBe(true);
expect(regexp.test(`${-0}`)).toBe(true);
expect(regexp.test(`${+0}`)).toBe(true);
expect(regexp.test(`${-9.5}`)).toBe(false);
expect(regexp.test(`${13.5}`)).toBe(false);
})
Loading

0 comments on commit aba95ff

Please sign in to comment.