@@ -17,26 +17,26 @@ describe('when the value is invalid with custom config', () => {
1717 } )
1818 it ( 'should return as follows' , ( ) => {
1919 expect ( numberFormat . format ( '' ) ) . toEqual ( '' )
20- expect ( numberFormat . format ( 'foo' ) ) . toEqual ( '$0 ' )
21- expect ( numberFormat . format ( '-foo' ) ) . toEqual ( '$0 ' )
22- expect ( numberFormat . format ( '-fo,o-' ) ) . toEqual ( '$0, ' )
23- expect ( numberFormat . format ( '-fo.o-' ) ) . toEqual ( '$0 ' )
24- expect ( numberFormat . format ( '!@#$%^&*()' ) ) . toEqual ( '$0 ' )
20+ expect ( numberFormat . format ( 'foo' ) ) . toEqual ( '' )
21+ expect ( numberFormat . format ( '-foo' ) ) . toEqual ( '' )
22+ expect ( numberFormat . format ( '-fo,o-' ) ) . toEqual ( '' )
23+ expect ( numberFormat . format ( '-fo.o-' ) ) . toEqual ( '' )
24+ expect ( numberFormat . format ( '!@#$%^&*()' ) ) . toEqual ( '' )
2525 } )
2626 it ( 'should return as follows' , ( ) => {
2727 expect ( numberFormat . clean ( ) . format ( '' ) ) . toEqual ( '' )
28- expect ( numberFormat . clean ( ) . format ( 'foo' ) ) . toEqual ( '$0 ' )
29- expect ( numberFormat . clean ( ) . format ( '-foo' ) ) . toEqual ( '$0 ' )
30- expect ( numberFormat . clean ( ) . format ( '-fo.o-' ) ) . toEqual ( '$0 ' )
31- expect ( numberFormat . clean ( ) . format ( '-fo,o-' ) ) . toEqual ( '$0 ' )
32- expect ( numberFormat . clean ( ) . format ( '!@#$%^&*()' ) ) . toEqual ( '$0 ' )
28+ expect ( numberFormat . clean ( ) . format ( 'foo' ) ) . toEqual ( '' )
29+ expect ( numberFormat . clean ( ) . format ( '-foo' ) ) . toEqual ( '' )
30+ expect ( numberFormat . clean ( ) . format ( '-fo.o-' ) ) . toEqual ( '' )
31+ expect ( numberFormat . clean ( ) . format ( '-fo,o-' ) ) . toEqual ( '' )
32+ expect ( numberFormat . clean ( ) . format ( '!@#$%^&*()' ) ) . toEqual ( '' )
3333 } )
3434 it ( 'should return as follows' , ( ) => {
3535 expect ( numberFormat . unformat ( '' ) ) . toEqual ( '' )
36- expect ( numberFormat . unformat ( 'foo' ) ) . toEqual ( '0 ' )
37- expect ( numberFormat . unformat ( '-foo' ) ) . toEqual ( '0 ' )
38- expect ( numberFormat . unformat ( '-fo, o-' ) ) . toEqual ( '0 ' )
39- expect ( numberFormat . unformat ( '!@#$%^&*()' ) ) . toEqual ( '0 ' )
36+ expect ( numberFormat . unformat ( 'foo' ) ) . toEqual ( '' )
37+ expect ( numberFormat . unformat ( '-foo' ) ) . toEqual ( '' )
38+ expect ( numberFormat . unformat ( '-fo. o-' ) ) . toEqual ( '' )
39+ expect ( numberFormat . unformat ( '!@#$%^&*()' ) ) . toEqual ( '' )
4040 } )
4141} )
4242describe ( 'format when options are custom' , ( ) => {
@@ -53,18 +53,18 @@ describe('format when options are custom', () => {
5353 expect ( numberFormat . format ( '0,10' ) ) . toEqual ( '$0,10' )
5454 expect ( numberFormat . format ( '0,0-' ) ) . toEqual ( '$0,0' )
5555 expect ( numberFormat . format ( '0,10-' ) ) . toEqual ( '-$0,10' )
56- expect ( numberFormat . format ( '12.345,54921' ) ) . toEqual ( '$12.345,54 ' )
56+ expect ( numberFormat . format ( '12.345,54921' ) ) . toEqual ( '$12.345,55 ' )
5757 expect ( numberFormat . format ( '--12.345,12345' ) ) . toEqual ( '-$12.345,12' )
58- expect ( numberFormat . format ( '12.345.54321,12945' ) ) . toEqual ( '$1.234.554.321,12 ' )
58+ expect ( numberFormat . format ( '12.345.54321,12945' ) ) . toEqual ( '$1.234.554.321,13 ' )
5959 expect ( numberFormat . format ( '-12.345,,54321-' ) ) . toEqual ( '-$12.345,54' )
6060 } )
6161 it ( 'format numerical value' , ( ) => {
62- expect ( numberFormat . format ( 0 ) ) . toEqual ( '$0,00 ' )
63- expect ( numberFormat . format ( 0. ) ) . toEqual ( '$0,00 ' )
64- expect ( numberFormat . format ( 0.0 ) ) . toEqual ( '$0,00 ' )
65- expect ( numberFormat . format ( - 0.10 ) ) . toEqual ( '-$0,10 ' )
66- expect ( numberFormat . format ( - 0.0 ) ) . toEqual ( '$0,00 ' )
67- expect ( numberFormat . format ( 0.10 ) ) . toEqual ( '$0,10 ' )
62+ expect ( numberFormat . format ( 0 ) ) . toEqual ( '$0' )
63+ expect ( numberFormat . format ( 0. ) ) . toEqual ( '$0' )
64+ expect ( numberFormat . format ( 0.0 ) ) . toEqual ( '$0' )
65+ expect ( numberFormat . format ( - 0.10 ) ) . toEqual ( '-$0,1 ' )
66+ expect ( numberFormat . format ( - 0.0 ) ) . toEqual ( '$0' )
67+ expect ( numberFormat . format ( 0.10 ) ) . toEqual ( '$0,1 ' )
6868 expect ( numberFormat . format ( 12345.54921 ) ) . toEqual ( '$12.345,55' )
6969 expect ( numberFormat . format ( 12345.12345 ) ) . toEqual ( '$12.345,12' )
7070 expect ( numberFormat . format ( 12345.54321 ) ) . toEqual ( '$12.345,54' )
@@ -91,40 +91,28 @@ describe('unformat when options are default', () => {
9191 null_value : '' ,
9292 } )
9393 it ( 'unformat string value' , ( ) => {
94- expect ( numberFormat . unformat ( '0' ) ) . toEqual ( '0' )
95- expect ( numberFormat . unformat ( '0,' ) ) . toEqual ( '0' )
96- expect ( numberFormat . unformat ( '-0,0' ) ) . toEqual ( '0' )
97- expect ( numberFormat . unformat ( '0,10' ) ) . toEqual ( ' 0.1' )
98- expect ( numberFormat . unformat ( '0,0-' ) ) . toEqual ( '0' )
99- expect ( numberFormat . unformat ( '0,10-' ) ) . toEqual ( ' -0.1' )
100- expect ( numberFormat . unformat ( '12.345,54921' ) ) . toEqual ( ' 12345.54' )
101- expect ( numberFormat . unformat ( '--12.345,12345' ) ) . toEqual ( ' -12345.12' )
102- expect ( numberFormat . unformat ( '12.345.54321,12345' ) ) . toEqual ( ' 1234554321.12' )
103- expect ( numberFormat . unformat ( '-12.345,,54321-' ) ) . toEqual ( ' -12345.54' )
94+ expect ( numberFormat . unformat ( '0' ) ) . toEqual ( 0 )
95+ expect ( numberFormat . unformat ( '0,' ) ) . toEqual ( 0 )
96+ expect ( numberFormat . unformat ( '-0,0' ) ) . toEqual ( 0 )
97+ expect ( numberFormat . unformat ( '0,10' ) ) . toEqual ( 0.1 )
98+ expect ( numberFormat . unformat ( '0,0-' ) ) . toEqual ( 0 )
99+ expect ( numberFormat . unformat ( '0,10-' ) ) . toEqual ( - 0.1 )
100+ expect ( numberFormat . unformat ( '12.345,54921' ) ) . toEqual ( 12345.55 )
101+ expect ( numberFormat . unformat ( '--12.345,12345' ) ) . toEqual ( - 12345.12 )
102+ expect ( numberFormat . unformat ( '12.345.54321,12345' ) ) . toEqual ( 1234554321.12 )
103+ expect ( numberFormat . unformat ( '-12.345,,54321-' ) ) . toEqual ( - 12345.54 )
104104 } )
105105 it ( 'unformat numerical value' , ( ) => {
106- expect ( numberFormat . unformat ( 0 ) ) . toEqual ( '0' )
107- expect ( numberFormat . unformat ( 0. ) ) . toEqual ( '0' )
108- expect ( numberFormat . unformat ( 0.0 ) ) . toEqual ( '0' )
109- expect ( numberFormat . unformat ( - 0.10 ) ) . toEqual ( '-0.1' )
110- expect ( numberFormat . unformat ( - 0.0 ) ) . toEqual ( '0' )
111- expect ( numberFormat . unformat ( 0.10 ) ) . toEqual ( '0.1' )
112- expect ( numberFormat . unformat ( 12345.54921 ) ) . toEqual ( '12345.55' )
113- expect ( numberFormat . unformat ( 12345.12345 ) ) . toEqual ( '12345.12' )
114- expect ( numberFormat . unformat ( 12345.54321 ) ) . toEqual ( '12345.54' )
115- expect ( numberFormat . unformat ( 12345.54321 ) ) . toEqual ( '12345.54' )
116- } )
117- it ( 'unformat and clean numerical value' , ( ) => {
118- expect ( numberFormat . clean ( ) . unformat ( 0 ) ) . toEqual ( '0' )
119- expect ( numberFormat . clean ( ) . unformat ( 0. ) ) . toEqual ( '0' )
120- expect ( numberFormat . clean ( ) . unformat ( 0.0 ) ) . toEqual ( '0' )
121- expect ( numberFormat . clean ( ) . unformat ( 0.10 ) ) . toEqual ( '0.1' )
122- expect ( numberFormat . clean ( ) . unformat ( - 0.0 ) ) . toEqual ( '0' )
123- expect ( numberFormat . clean ( ) . unformat ( - 0.10 ) ) . toEqual ( '-0.1' )
124- expect ( numberFormat . clean ( ) . unformat ( 12345.54921 ) ) . toEqual ( '12345.55' )
125- expect ( numberFormat . clean ( ) . unformat ( 12345.12345 ) ) . toEqual ( '12345.12' )
126- expect ( numberFormat . clean ( ) . unformat ( 12345.54321 ) ) . toEqual ( '12345.54' )
127- expect ( numberFormat . clean ( ) . unformat ( 12345.54321 ) ) . toEqual ( '12345.54' )
106+ expect ( numberFormat . unformat ( 0 ) ) . toEqual ( 0 )
107+ expect ( numberFormat . unformat ( 0. ) ) . toEqual ( 0 )
108+ expect ( numberFormat . unformat ( 0.0 ) ) . toEqual ( 0 )
109+ expect ( numberFormat . unformat ( - 0.10 ) ) . toEqual ( - 0.1 )
110+ expect ( numberFormat . unformat ( - 0.0 ) ) . toEqual ( 0 )
111+ expect ( numberFormat . unformat ( 0.10 ) ) . toEqual ( 0.1 )
112+ expect ( numberFormat . unformat ( 12345.54921 ) ) . toEqual ( 12345.55 )
113+ expect ( numberFormat . unformat ( 12345.12345 ) ) . toEqual ( 12345.12 )
114+ expect ( numberFormat . unformat ( 12345.54321 ) ) . toEqual ( 12345.54 )
115+ expect ( numberFormat . unformat ( 12345.54321 ) ) . toEqual ( 12345.54 )
128116 } )
129117} )
130118
0 commit comments