-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
104 lines (87 loc) · 2.46 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const { FormatMoney } = require('./dist/format-money.js');
const fm1 = new FormatMoney({
decimals: 2
});
console.log(fm1.from(12345.67, { symbol: '$' }), 'typeof: ' + typeof fm1.from(12345.67, { symbol: '$' }));
console.log(fm1.un('€12,345.67'), 'typeof: ' + typeof fm1.un('€12,345.67'));
console.log(fm1.un('€12.345,67', { decimalPoint: ',' }), 'typeof: ' + typeof fm1.un('€12.345,67', { decimalPoint: ',' }));
//
const array0 = [
1,
12,
123,
1234,
12345,
123456,
1234567,
12345678,
123456789,
1234567890,
12345678901,
123456789012,
1234567890123,
12345678901234,
123456789012345,
1234567890123456,
'text',
undefined,
null,
'',
];
array0.forEach(element => {
console.log(element, ' -> ' , fm1.from(element), 'typeof: ' + typeof fm1.from(element));
});
//
const fm2 = new FormatMoney({ symbol: '$' });
console.log(fm2.from(12345.67, { symbol: '€' }), 'typeof: ' + typeof fm2.from(12345.67, { symbol: '€' }));
//
const fm3 = new FormatMoney({ symbol: '$' });
console.log(fm3.from(12345.67, { append: true }), 'typeof: ' + typeof fm3.from(12345.67, { append: true }));
// Fragment
const fm4 = new FormatMoney({ symbol: '$' });
console.log(fm4.from(12345.67, { append: true }, true), 'typeof: ' + typeof fm4.from(12345.67, { append: true }, true));
const fm5 = new FormatMoney({ symbol: '$' });
console.log(fm5.from(-12345.67, { append: true }, true), 'typeof: ' + typeof fm5.from(-12345.67, { append: true }, true));
console.log(fm5.from(-12345.67, { grouping: false, decimals: 2 }, true), 'typeof: ' + typeof fm5.from(-12345.67, { grouping: false, decimals: 2 }, true));
console.log(fm5.from('1234567.890', { grouping: false, decimals: 2 }, true), 'typeof: ' + typeof fm5.from('1234567.890', { grouping: true, decimals: 2 }, true));
//
const un1 = new FormatMoney();
const un2 = new FormatMoney({'decimalPoint': ','});
const array1 = [
'$12,345.67',
'12,345.67',
'$12 345.67',
'12 345.67',
'$12,345.67 USD',
'12,345.67 USD',
'$12 345.67 USD',
'12 345.67 USD',
123,
123.45,
'text',
undefined,
null,
'',
];
const array2 = [
'$12.345,67',
'12.345,67',
'$12 345,67',
'12 345,67',
'$12.345,67 USD',
'12.345,67 USD',
'$12 345,67 USD',
'12 345,67 USD',
123,
123.45,
'text',
undefined,
null,
'',
];
array1.forEach(element => {
console.log(un1.un(element), 'typeof: ' + typeof un1.un(element));
});
array2.forEach(element => {
console.log(un2.un(element), 'typeof: ' + typeof un2.un(element));
});