@keplr-wallet/unit 0.9.10 → 0.9.12-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/coin-pretty.d.ts +13 -3
- package/build/coin-pretty.js +36 -25
- package/build/coin-pretty.js.map +1 -1
- package/build/coin-pretty.spec.js +194 -9
- package/build/coin-pretty.spec.js.map +1 -1
- package/build/coin-utils.js +8 -4
- package/build/coin-utils.js.map +1 -1
- package/build/coin-utils.spec.js +16 -0
- package/build/coin-utils.spec.js.map +1 -1
- package/build/coin.js +1 -1
- package/build/coin.js.map +1 -1
- package/build/coin.spec.js +15 -0
- package/build/coin.spec.js.map +1 -1
- package/build/dec-utils.d.ts +8 -1
- package/build/dec-utils.js +22 -20
- package/build/dec-utils.js.map +1 -1
- package/build/dec-utils.spec.js +19 -0
- package/build/dec-utils.spec.js.map +1 -1
- package/build/decimal.d.ts +22 -9
- package/build/decimal.js +102 -29
- package/build/decimal.js.map +1 -1
- package/build/decimal.spec.js +296 -3
- package/build/decimal.spec.js.map +1 -1
- package/build/etc.d.ts +4 -0
- package/build/etc.js +66 -0
- package/build/etc.js.map +1 -0
- package/build/etc.spec.d.ts +1 -0
- package/build/etc.spec.js +66 -0
- package/build/etc.spec.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/int-pretty.d.ts +16 -4
- package/build/int-pretty.js +74 -36
- package/build/int-pretty.js.map +1 -1
- package/build/int-pretty.spec.js +261 -94
- package/build/int-pretty.spec.js.map +1 -1
- package/build/int.d.ts +17 -12
- package/build/int.js +69 -16
- package/build/int.js.map +1 -1
- package/build/int.spec.d.ts +1 -0
- package/build/int.spec.js +161 -0
- package/build/int.spec.js.map +1 -0
- package/build/price-pretty.d.ts +13 -3
- package/build/price-pretty.js +37 -26
- package/build/price-pretty.js.map +1 -1
- package/build/price-pretty.spec.js +59 -2
- package/build/price-pretty.spec.js.map +1 -1
- package/build/rate-pretty.d.ts +57 -0
- package/build/rate-pretty.js +128 -0
- package/build/rate-pretty.js.map +1 -0
- package/build/rate-pretty.spec.d.ts +1 -0
- package/build/rate-pretty.spec.js +38 -0
- package/build/rate-pretty.spec.js.map +1 -0
- package/package.json +3 -3
- package/src/coin-pretty.spec.ts +304 -11
- package/src/coin-pretty.ts +56 -29
- package/src/coin-utils.spec.ts +32 -0
- package/src/coin-utils.ts +12 -4
- package/src/coin.spec.ts +20 -0
- package/src/coin.ts +1 -1
- package/src/dec-utils.spec.ts +39 -0
- package/src/dec-utils.ts +25 -20
- package/src/decimal.spec.ts +361 -3
- package/src/decimal.ts +135 -56
- package/src/etc.spec.ts +73 -0
- package/src/etc.ts +73 -0
- package/src/index.ts +1 -0
- package/src/int-pretty.spec.ts +296 -101
- package/src/int-pretty.ts +87 -34
- package/src/int.spec.ts +212 -0
- package/src/int.ts +94 -26
- package/src/price-pretty.spec.ts +106 -2
- package/src/price-pretty.ts +50 -30
- package/src/rate-pretty.spec.ts +52 -0
- package/src/rate-pretty.ts +165 -0
package/build/int-pretty.spec.js
CHANGED
@@ -4,181 +4,245 @@ const int_pretty_1 = require("./int-pretty");
|
|
4
4
|
const int_1 = require("./int");
|
5
5
|
const decimal_1 = require("./decimal");
|
6
6
|
describe("Test IntPretty", () => {
|
7
|
-
it("Test
|
7
|
+
it("Test creation of IntPretty", () => {
|
8
|
+
expect(new int_pretty_1.IntPretty(new decimal_1.Dec("1.1")).toDec().equals(new decimal_1.Dec("1.1"))).toBe(true);
|
9
|
+
expect(new int_pretty_1.IntPretty(new decimal_1.Dec("1.1")).maxDecimals(2).toString()).toBe("1.10");
|
10
|
+
expect(new int_pretty_1.IntPretty("1.1").toDec().equals(new decimal_1.Dec("1.1"))).toBe(true);
|
11
|
+
expect(new int_pretty_1.IntPretty("1.1").maxDecimals(2).toString()).toBe("1.10");
|
12
|
+
expect(new int_pretty_1.IntPretty(1.1).toDec().equals(new decimal_1.Dec("1.1"))).toBe(true);
|
13
|
+
expect(new int_pretty_1.IntPretty(1.1).maxDecimals(2).toString()).toBe("1.10");
|
14
|
+
expect(new int_pretty_1.IntPretty(new int_1.Int(1)).toDec().equals(new decimal_1.Dec("1.0"))).toBe(true);
|
15
|
+
expect(new int_pretty_1.IntPretty(new int_1.Int(1)).maxDecimals(2).toString()).toBe("1.00");
|
16
|
+
});
|
17
|
+
it("Test the maxDecimals of IntPretty", () => {
|
8
18
|
const params = [
|
9
19
|
{
|
10
20
|
arg: new int_1.Int(0),
|
11
|
-
|
21
|
+
maxDecimals: 0,
|
12
22
|
dec: new decimal_1.Dec(0),
|
13
23
|
str: "0",
|
14
24
|
},
|
15
25
|
{
|
16
26
|
arg: new decimal_1.Dec(0),
|
17
|
-
|
27
|
+
maxDecimals: 0,
|
18
28
|
dec: new decimal_1.Dec(0),
|
19
29
|
str: "0",
|
20
30
|
},
|
21
31
|
{
|
22
32
|
arg: new int_1.Int(100),
|
23
|
-
|
33
|
+
maxDecimals: 0,
|
24
34
|
dec: new decimal_1.Dec(100),
|
25
35
|
str: "100",
|
26
36
|
},
|
27
37
|
{
|
28
38
|
arg: new decimal_1.Dec(100),
|
29
|
-
|
39
|
+
maxDecimals: 0,
|
30
40
|
dec: new decimal_1.Dec(100),
|
31
41
|
str: "100",
|
32
42
|
},
|
33
43
|
{
|
34
44
|
arg: new decimal_1.Dec("0.01"),
|
35
|
-
|
45
|
+
maxDecimals: 2,
|
36
46
|
dec: new decimal_1.Dec("0.01"),
|
37
47
|
str: "0.01",
|
38
48
|
},
|
39
49
|
{
|
40
50
|
arg: new decimal_1.Dec("-0.01"),
|
41
|
-
|
51
|
+
maxDecimals: 2,
|
42
52
|
dec: new decimal_1.Dec("-0.01"),
|
43
53
|
str: "-0.01",
|
44
54
|
},
|
45
55
|
{
|
46
56
|
arg: new decimal_1.Dec("1.01"),
|
47
|
-
|
57
|
+
maxDecimals: 2,
|
48
58
|
dec: new decimal_1.Dec("1.01"),
|
49
59
|
str: "1.01",
|
50
60
|
},
|
51
61
|
{
|
52
62
|
arg: new decimal_1.Dec("-1.01"),
|
53
|
-
|
63
|
+
maxDecimals: 2,
|
54
64
|
dec: new decimal_1.Dec("-1.01"),
|
55
65
|
str: "-1.01",
|
56
66
|
},
|
57
67
|
{
|
58
68
|
arg: new decimal_1.Dec("10.01"),
|
59
|
-
|
69
|
+
maxDecimals: 2,
|
60
70
|
dec: new decimal_1.Dec("10.01"),
|
61
71
|
str: "10.01",
|
62
72
|
},
|
63
73
|
{
|
64
74
|
arg: new decimal_1.Dec("-10.01"),
|
65
|
-
|
75
|
+
maxDecimals: 2,
|
66
76
|
dec: new decimal_1.Dec("-10.01"),
|
67
77
|
str: "-10.01",
|
68
78
|
},
|
69
79
|
{
|
70
80
|
arg: new decimal_1.Dec("10.0100"),
|
71
|
-
|
81
|
+
maxDecimals: 2,
|
72
82
|
dec: new decimal_1.Dec("10.01"),
|
73
83
|
str: "10.01",
|
74
84
|
},
|
75
85
|
{
|
76
86
|
arg: new decimal_1.Dec("-10.0100"),
|
77
|
-
|
87
|
+
maxDecimals: 2,
|
78
88
|
dec: new decimal_1.Dec("-10.01"),
|
79
89
|
str: "-10.01",
|
80
90
|
},
|
81
91
|
];
|
82
92
|
for (const param of params) {
|
83
93
|
const pretty = new int_pretty_1.IntPretty(param.arg);
|
84
|
-
expect(pretty.options.
|
94
|
+
expect(pretty.options.maxDecimals).toBe(param.maxDecimals);
|
85
95
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
86
96
|
expect(pretty.toString()).toBe(param.str);
|
87
97
|
}
|
88
98
|
});
|
89
99
|
it("Test modifying the precision of IntPretty", () => {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
100
|
+
const tests = [
|
101
|
+
{
|
102
|
+
base: new decimal_1.Dec("10.001"),
|
103
|
+
delta: 0,
|
104
|
+
right: false,
|
105
|
+
res: new decimal_1.Dec("10.001"),
|
106
|
+
resStr: "10.001",
|
107
|
+
otherTest: (int) => {
|
108
|
+
expect(int.maxDecimals(4).toString()).toBe("10.0010");
|
109
|
+
},
|
110
|
+
},
|
111
|
+
{
|
112
|
+
base: new decimal_1.Dec("10.001"),
|
113
|
+
delta: 1,
|
114
|
+
right: false,
|
115
|
+
res: new decimal_1.Dec("1.0001"),
|
116
|
+
resStr: "1.000",
|
117
|
+
otherTest: (int) => {
|
118
|
+
expect(int.maxDecimals(4).toString()).toBe("1.0001");
|
119
|
+
},
|
120
|
+
},
|
121
|
+
{
|
122
|
+
base: new decimal_1.Dec("10.001"),
|
123
|
+
delta: 1,
|
124
|
+
right: true,
|
125
|
+
res: new decimal_1.Dec("100.010"),
|
126
|
+
resStr: "100.010",
|
127
|
+
otherTest: (int) => {
|
128
|
+
expect(int.maxDecimals(4).toString()).toBe("100.0100");
|
129
|
+
},
|
130
|
+
},
|
131
|
+
{
|
132
|
+
base: new decimal_1.Dec("10.001"),
|
133
|
+
delta: 6,
|
134
|
+
right: true,
|
135
|
+
res: new decimal_1.Dec("10001000"),
|
136
|
+
resStr: "10,001,000.000",
|
137
|
+
},
|
138
|
+
{
|
139
|
+
base: new decimal_1.Dec("0"),
|
140
|
+
delta: 3,
|
141
|
+
right: false,
|
142
|
+
res: new decimal_1.Dec("0"),
|
143
|
+
resStr: "0",
|
144
|
+
},
|
145
|
+
{
|
146
|
+
base: new decimal_1.Dec("0"),
|
147
|
+
delta: 3,
|
148
|
+
right: true,
|
149
|
+
res: new decimal_1.Dec("0"),
|
150
|
+
resStr: "0",
|
151
|
+
},
|
152
|
+
{
|
153
|
+
base: new decimal_1.Dec("100.01"),
|
154
|
+
delta: 20,
|
155
|
+
right: true,
|
156
|
+
res: new decimal_1.Dec("10001000000000000000000"),
|
157
|
+
resStr: "10,001,000,000,000,000,000,000.00",
|
158
|
+
},
|
159
|
+
{
|
160
|
+
base: new decimal_1.Dec("100.01"),
|
161
|
+
delta: 20,
|
162
|
+
right: false,
|
163
|
+
res: new decimal_1.Dec("0.000000000000000001"),
|
164
|
+
resStr: "0.00",
|
165
|
+
otherTest: (int) => {
|
166
|
+
expect(int.trim(true).toString()).toBe("0");
|
167
|
+
},
|
168
|
+
},
|
169
|
+
];
|
170
|
+
for (const test of tests) {
|
171
|
+
let pretty = new int_pretty_1.IntPretty(test.base);
|
172
|
+
if (test.right) {
|
173
|
+
pretty = pretty.moveDecimalPointRight(test.delta);
|
174
|
+
}
|
175
|
+
else {
|
176
|
+
pretty = pretty.moveDecimalPointLeft(test.delta);
|
177
|
+
}
|
178
|
+
expect(pretty.toDec().equals(test.res)).toBeTruthy();
|
179
|
+
expect(pretty.toString()).toBe(test.resStr);
|
180
|
+
if (test.otherTest) {
|
181
|
+
test.otherTest(pretty);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
for (const test of tests) {
|
185
|
+
let pretty = new int_pretty_1.IntPretty(test.base);
|
186
|
+
if (test.right) {
|
187
|
+
pretty = pretty.decreasePrecision(test.delta);
|
188
|
+
}
|
189
|
+
else {
|
190
|
+
pretty = pretty.increasePrecision(test.delta);
|
191
|
+
}
|
192
|
+
expect(pretty.toDec().equals(test.res)).toBeTruthy();
|
193
|
+
expect(pretty.toString()).toBe(test.resStr);
|
194
|
+
if (test.otherTest) {
|
195
|
+
test.otherTest(pretty);
|
196
|
+
}
|
197
|
+
}
|
126
198
|
});
|
127
199
|
it("Test the add calcutation of IntPretty", () => {
|
128
200
|
const params = [
|
129
201
|
{
|
130
202
|
base: new int_1.Int(0),
|
131
203
|
target: new int_1.Int(0),
|
132
|
-
precision: 0,
|
133
204
|
dec: new decimal_1.Dec(0),
|
134
205
|
str: "0",
|
135
206
|
},
|
136
207
|
{
|
137
208
|
base: new decimal_1.Dec(0),
|
138
209
|
target: new int_1.Int(0),
|
139
|
-
precision: 0,
|
140
210
|
dec: new decimal_1.Dec(0),
|
141
211
|
str: "0",
|
142
212
|
},
|
143
213
|
{
|
144
214
|
base: new int_1.Int(0),
|
145
215
|
target: new decimal_1.Dec(0),
|
146
|
-
precision: 0,
|
147
216
|
dec: new decimal_1.Dec(0),
|
148
217
|
str: "0",
|
149
218
|
},
|
150
219
|
{
|
151
220
|
base: new int_1.Int(1),
|
152
221
|
target: new decimal_1.Dec(1),
|
153
|
-
precision: 0,
|
154
222
|
dec: new decimal_1.Dec(2),
|
155
223
|
str: "2",
|
156
224
|
},
|
157
225
|
{
|
158
226
|
base: new int_1.Int(1),
|
159
227
|
target: new decimal_1.Dec(-1),
|
160
|
-
precision: 0,
|
161
228
|
dec: new decimal_1.Dec(0),
|
162
229
|
str: "0",
|
163
230
|
},
|
164
231
|
{
|
165
232
|
base: new int_1.Int(100),
|
166
233
|
target: new decimal_1.Dec(-1),
|
167
|
-
precision: 0,
|
168
234
|
dec: new decimal_1.Dec("99"),
|
169
235
|
str: "99",
|
170
236
|
},
|
171
237
|
{
|
172
238
|
base: new decimal_1.Dec("100.001"),
|
173
239
|
target: new decimal_1.Dec(-1),
|
174
|
-
precision: 3,
|
175
240
|
dec: new decimal_1.Dec("99.001"),
|
176
241
|
str: "99.001",
|
177
242
|
},
|
178
243
|
{
|
179
244
|
base: new decimal_1.Dec("100.00100"),
|
180
245
|
target: new decimal_1.Dec("-1.001"),
|
181
|
-
precision: 0,
|
182
246
|
dec: new decimal_1.Dec("99"),
|
183
247
|
// Max decimals should be remain
|
184
248
|
str: "99.000",
|
@@ -186,7 +250,6 @@ describe("Test IntPretty", () => {
|
|
186
250
|
{
|
187
251
|
base: new decimal_1.Dec("100.00100"),
|
188
252
|
target: new decimal_1.Dec("-0.00100"),
|
189
|
-
precision: 0,
|
190
253
|
dec: new decimal_1.Dec("100"),
|
191
254
|
// Max decimals should be remain
|
192
255
|
str: "100.000",
|
@@ -194,7 +257,6 @@ describe("Test IntPretty", () => {
|
|
194
257
|
{
|
195
258
|
base: new decimal_1.Dec("0.00100"),
|
196
259
|
target: new decimal_1.Dec("-1.00100"),
|
197
|
-
precision: 0,
|
198
260
|
dec: new decimal_1.Dec("-1"),
|
199
261
|
// Max decimals should be remain
|
200
262
|
str: "-1.000",
|
@@ -202,14 +264,12 @@ describe("Test IntPretty", () => {
|
|
202
264
|
{
|
203
265
|
base: new decimal_1.Dec("100.00100"),
|
204
266
|
target: new decimal_1.Dec("1.01"),
|
205
|
-
precision: 3,
|
206
267
|
dec: new decimal_1.Dec("101.011"),
|
207
268
|
str: "101.011",
|
208
269
|
},
|
209
270
|
];
|
210
271
|
for (const param of params) {
|
211
272
|
const pretty = new int_pretty_1.IntPretty(param.base).add(new int_pretty_1.IntPretty(param.target));
|
212
|
-
expect(pretty.options.precision).toBe(param.precision);
|
213
273
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
214
274
|
expect(pretty.toString()).toBe(param.str);
|
215
275
|
}
|
@@ -219,56 +279,48 @@ describe("Test IntPretty", () => {
|
|
219
279
|
{
|
220
280
|
base: new int_1.Int(0),
|
221
281
|
target: new int_1.Int(0),
|
222
|
-
precision: 0,
|
223
282
|
dec: new decimal_1.Dec(0),
|
224
283
|
str: "0",
|
225
284
|
},
|
226
285
|
{
|
227
286
|
base: new decimal_1.Dec(0),
|
228
287
|
target: new int_1.Int(0),
|
229
|
-
precision: 0,
|
230
288
|
dec: new decimal_1.Dec(0),
|
231
289
|
str: "0",
|
232
290
|
},
|
233
291
|
{
|
234
292
|
base: new int_1.Int(0),
|
235
293
|
target: new decimal_1.Dec(0),
|
236
|
-
precision: 0,
|
237
294
|
dec: new decimal_1.Dec(0),
|
238
295
|
str: "0",
|
239
296
|
},
|
240
297
|
{
|
241
298
|
base: new int_1.Int(1),
|
242
299
|
target: new decimal_1.Dec(1),
|
243
|
-
precision: 0,
|
244
300
|
dec: new decimal_1.Dec(0),
|
245
301
|
str: "0",
|
246
302
|
},
|
247
303
|
{
|
248
304
|
base: new int_1.Int(1),
|
249
305
|
target: new decimal_1.Dec(-1),
|
250
|
-
precision: 0,
|
251
306
|
dec: new decimal_1.Dec(2),
|
252
307
|
str: "2",
|
253
308
|
},
|
254
309
|
{
|
255
310
|
base: new int_1.Int(100),
|
256
311
|
target: new decimal_1.Dec(-1),
|
257
|
-
precision: 0,
|
258
312
|
dec: new decimal_1.Dec("101"),
|
259
313
|
str: "101",
|
260
314
|
},
|
261
315
|
{
|
262
316
|
base: new decimal_1.Dec("100.001"),
|
263
317
|
target: new decimal_1.Dec(-1),
|
264
|
-
precision: 3,
|
265
318
|
dec: new decimal_1.Dec("101.001"),
|
266
319
|
str: "101.001",
|
267
320
|
},
|
268
321
|
{
|
269
322
|
base: new decimal_1.Dec("100.00100"),
|
270
323
|
target: new decimal_1.Dec("1.001"),
|
271
|
-
precision: 0,
|
272
324
|
dec: new decimal_1.Dec("99"),
|
273
325
|
// Max decimals should be remain
|
274
326
|
str: "99.000",
|
@@ -276,7 +328,6 @@ describe("Test IntPretty", () => {
|
|
276
328
|
{
|
277
329
|
base: new decimal_1.Dec("100.00100"),
|
278
330
|
target: new decimal_1.Dec("0.00100"),
|
279
|
-
precision: 0,
|
280
331
|
dec: new decimal_1.Dec("100"),
|
281
332
|
// Max decimals should be remain
|
282
333
|
str: "100.000",
|
@@ -284,21 +335,18 @@ describe("Test IntPretty", () => {
|
|
284
335
|
{
|
285
336
|
base: new decimal_1.Dec("0.00100"),
|
286
337
|
target: new decimal_1.Dec("-1.00100"),
|
287
|
-
precision: 3,
|
288
338
|
dec: new decimal_1.Dec("1.002"),
|
289
339
|
str: "1.002",
|
290
340
|
},
|
291
341
|
{
|
292
342
|
base: new decimal_1.Dec("100.00100"),
|
293
343
|
target: new decimal_1.Dec("-1.01"),
|
294
|
-
precision: 3,
|
295
344
|
dec: new decimal_1.Dec("101.011"),
|
296
345
|
str: "101.011",
|
297
346
|
},
|
298
347
|
];
|
299
348
|
for (const param of params) {
|
300
349
|
const pretty = new int_pretty_1.IntPretty(param.base).sub(new int_pretty_1.IntPretty(param.target));
|
301
|
-
expect(pretty.options.precision).toBe(param.precision);
|
302
350
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
303
351
|
expect(pretty.toString()).toBe(param.str);
|
304
352
|
}
|
@@ -308,56 +356,48 @@ describe("Test IntPretty", () => {
|
|
308
356
|
{
|
309
357
|
base: new int_1.Int(0),
|
310
358
|
target: new int_1.Int(0),
|
311
|
-
precision: 0,
|
312
359
|
dec: new decimal_1.Dec(0),
|
313
360
|
str: "0",
|
314
361
|
},
|
315
362
|
{
|
316
363
|
base: new decimal_1.Dec(0),
|
317
364
|
target: new int_1.Int(0),
|
318
|
-
precision: 0,
|
319
365
|
dec: new decimal_1.Dec(0),
|
320
366
|
str: "0",
|
321
367
|
},
|
322
368
|
{
|
323
369
|
base: new int_1.Int(0),
|
324
370
|
target: new decimal_1.Dec(0),
|
325
|
-
precision: 0,
|
326
371
|
dec: new decimal_1.Dec(0),
|
327
372
|
str: "0",
|
328
373
|
},
|
329
374
|
{
|
330
375
|
base: new int_1.Int(1),
|
331
376
|
target: new decimal_1.Dec(1),
|
332
|
-
precision: 0,
|
333
377
|
dec: new decimal_1.Dec(1),
|
334
378
|
str: "1",
|
335
379
|
},
|
336
380
|
{
|
337
381
|
base: new int_1.Int(1),
|
338
382
|
target: new decimal_1.Dec(-1),
|
339
|
-
precision: 0,
|
340
383
|
dec: new decimal_1.Dec(-1),
|
341
384
|
str: "-1",
|
342
385
|
},
|
343
386
|
{
|
344
387
|
base: new int_1.Int(100),
|
345
388
|
target: new decimal_1.Dec(-1),
|
346
|
-
precision: 0,
|
347
389
|
dec: new decimal_1.Dec("-100"),
|
348
390
|
str: "-100",
|
349
391
|
},
|
350
392
|
{
|
351
393
|
base: new decimal_1.Dec("100.001"),
|
352
394
|
target: new decimal_1.Dec(-1),
|
353
|
-
precision: 3,
|
354
395
|
dec: new decimal_1.Dec("-100.001"),
|
355
396
|
str: "-100.001",
|
356
397
|
},
|
357
398
|
{
|
358
399
|
base: new decimal_1.Dec("100.00100"),
|
359
400
|
target: new decimal_1.Dec("1.001"),
|
360
|
-
precision: 6,
|
361
401
|
dec: new decimal_1.Dec("100.101001"),
|
362
402
|
// Max decimals should be remain
|
363
403
|
str: "100.101",
|
@@ -365,7 +405,6 @@ describe("Test IntPretty", () => {
|
|
365
405
|
{
|
366
406
|
base: new decimal_1.Dec("100.00100"),
|
367
407
|
target: new decimal_1.Dec("0.00100"),
|
368
|
-
precision: 6,
|
369
408
|
dec: new decimal_1.Dec("0.100001"),
|
370
409
|
// Max decimals should be remain
|
371
410
|
str: "0.100",
|
@@ -373,7 +412,6 @@ describe("Test IntPretty", () => {
|
|
373
412
|
{
|
374
413
|
base: new decimal_1.Dec("100.00100"),
|
375
414
|
target: new decimal_1.Dec("-1.00100"),
|
376
|
-
precision: 6,
|
377
415
|
dec: new decimal_1.Dec("-100.101001"),
|
378
416
|
// Max decimals should be remain
|
379
417
|
str: "-100.101",
|
@@ -381,7 +419,6 @@ describe("Test IntPretty", () => {
|
|
381
419
|
{
|
382
420
|
base: new decimal_1.Dec("100.00100"),
|
383
421
|
target: new decimal_1.Dec("-0.00100"),
|
384
|
-
precision: 6,
|
385
422
|
dec: new decimal_1.Dec("-0.100001"),
|
386
423
|
// Max decimals should be remain
|
387
424
|
str: "-0.100",
|
@@ -389,7 +426,6 @@ describe("Test IntPretty", () => {
|
|
389
426
|
];
|
390
427
|
for (const param of params) {
|
391
428
|
const pretty = new int_pretty_1.IntPretty(param.base).mul(new int_pretty_1.IntPretty(param.target));
|
392
|
-
expect(pretty.options.precision).toBe(param.precision);
|
393
429
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
394
430
|
expect(pretty.toString()).toBe(param.str);
|
395
431
|
}
|
@@ -402,42 +438,36 @@ describe("Test IntPretty", () => {
|
|
402
438
|
{
|
403
439
|
base: new int_1.Int(1),
|
404
440
|
target: new decimal_1.Dec(1),
|
405
|
-
precision: 0,
|
406
441
|
dec: new decimal_1.Dec(1),
|
407
442
|
str: "1",
|
408
443
|
},
|
409
444
|
{
|
410
445
|
base: new int_1.Int(1),
|
411
446
|
target: new decimal_1.Dec(-1),
|
412
|
-
precision: 0,
|
413
447
|
dec: new decimal_1.Dec(-1),
|
414
448
|
str: "-1",
|
415
449
|
},
|
416
450
|
{
|
417
451
|
base: new int_1.Int(100),
|
418
452
|
target: new decimal_1.Dec(-1),
|
419
|
-
precision: 0,
|
420
453
|
dec: new decimal_1.Dec("-100"),
|
421
454
|
str: "-100",
|
422
455
|
},
|
423
456
|
{
|
424
457
|
base: new decimal_1.Dec("100.001"),
|
425
458
|
target: new decimal_1.Dec(-1),
|
426
|
-
precision: 3,
|
427
459
|
dec: new decimal_1.Dec("-100.001"),
|
428
460
|
str: "-100.001",
|
429
461
|
},
|
430
462
|
{
|
431
463
|
base: new decimal_1.Dec("300.00300"),
|
432
464
|
target: new decimal_1.Dec("3"),
|
433
|
-
precision: 3,
|
434
465
|
dec: new decimal_1.Dec("100.001"),
|
435
466
|
str: "100.001",
|
436
467
|
},
|
437
468
|
{
|
438
469
|
base: new decimal_1.Dec("100.00500"),
|
439
470
|
target: new decimal_1.Dec("0.02"),
|
440
|
-
precision: 2,
|
441
471
|
dec: new decimal_1.Dec("5000.25"),
|
442
472
|
// Max decimals should be remain
|
443
473
|
str: "5,000.250",
|
@@ -445,7 +475,6 @@ describe("Test IntPretty", () => {
|
|
445
475
|
{
|
446
476
|
base: new decimal_1.Dec("300.00300"),
|
447
477
|
target: new decimal_1.Dec("4"),
|
448
|
-
precision: 5,
|
449
478
|
dec: new decimal_1.Dec("75.00075"),
|
450
479
|
// Max decimals should be remain
|
451
480
|
str: "75.000",
|
@@ -453,7 +482,6 @@ describe("Test IntPretty", () => {
|
|
453
482
|
];
|
454
483
|
for (const param of params) {
|
455
484
|
const pretty = new int_pretty_1.IntPretty(param.base).quo(new int_pretty_1.IntPretty(param.target));
|
456
|
-
expect(pretty.options.precision).toBe(param.precision);
|
457
485
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
458
486
|
expect(pretty.toString()).toBe(param.str);
|
459
487
|
}
|
@@ -474,5 +502,144 @@ describe("Test IntPretty", () => {
|
|
474
502
|
expect(pretty.maxDecimals(9).trim(true).toString()).toBe("0.0123456");
|
475
503
|
expect(pretty.shrink(true).toString()).toBe("0.0123456");
|
476
504
|
});
|
505
|
+
it("Test inequalitySymbol of IntPretty", () => {
|
506
|
+
const tests = [
|
507
|
+
{
|
508
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("0")),
|
509
|
+
maxDecimals: 3,
|
510
|
+
inequalitySymbolSeparator: " ",
|
511
|
+
resStr: "0.000",
|
512
|
+
},
|
513
|
+
{
|
514
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("-0")),
|
515
|
+
maxDecimals: 3,
|
516
|
+
inequalitySymbolSeparator: " ",
|
517
|
+
resStr: "0.000",
|
518
|
+
},
|
519
|
+
{
|
520
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("0.1")),
|
521
|
+
maxDecimals: 3,
|
522
|
+
inequalitySymbolSeparator: " ",
|
523
|
+
resStr: "0.100",
|
524
|
+
},
|
525
|
+
{
|
526
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("1234.123456")),
|
527
|
+
maxDecimals: 3,
|
528
|
+
inequalitySymbolSeparator: " ",
|
529
|
+
resStr: "1,234.123",
|
530
|
+
},
|
531
|
+
{
|
532
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("0.123456")),
|
533
|
+
maxDecimals: 3,
|
534
|
+
inequalitySymbolSeparator: " ",
|
535
|
+
resStr: "0.123",
|
536
|
+
},
|
537
|
+
{
|
538
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("0.123456")).moveDecimalPointLeft(2),
|
539
|
+
maxDecimals: 3,
|
540
|
+
inequalitySymbolSeparator: " ",
|
541
|
+
resStr: "0.001",
|
542
|
+
},
|
543
|
+
{
|
544
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("0.123456")).moveDecimalPointLeft(3),
|
545
|
+
maxDecimals: 3,
|
546
|
+
inequalitySymbolSeparator: " ",
|
547
|
+
resStr: "< 0.001",
|
548
|
+
},
|
549
|
+
{
|
550
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("0.123456")),
|
551
|
+
maxDecimals: 0,
|
552
|
+
inequalitySymbolSeparator: " ",
|
553
|
+
resStr: "< 1",
|
554
|
+
},
|
555
|
+
{
|
556
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("1.123456")),
|
557
|
+
maxDecimals: 0,
|
558
|
+
inequalitySymbolSeparator: " ",
|
559
|
+
resStr: "1",
|
560
|
+
},
|
561
|
+
{
|
562
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("0.0001")),
|
563
|
+
maxDecimals: 3,
|
564
|
+
inequalitySymbolSeparator: " ",
|
565
|
+
resStr: "< 0.001",
|
566
|
+
},
|
567
|
+
{
|
568
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("0.0001")),
|
569
|
+
maxDecimals: 3,
|
570
|
+
inequalitySymbolSeparator: "",
|
571
|
+
resStr: "<0.001",
|
572
|
+
},
|
573
|
+
{
|
574
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("0.001")),
|
575
|
+
maxDecimals: 3,
|
576
|
+
inequalitySymbolSeparator: " ",
|
577
|
+
resStr: "0.001",
|
578
|
+
},
|
579
|
+
{
|
580
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("-1234.123456")),
|
581
|
+
maxDecimals: 3,
|
582
|
+
inequalitySymbolSeparator: " ",
|
583
|
+
resStr: "-1,234.123",
|
584
|
+
},
|
585
|
+
{
|
586
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("-0.123456")),
|
587
|
+
maxDecimals: 3,
|
588
|
+
inequalitySymbolSeparator: " ",
|
589
|
+
resStr: "-0.123",
|
590
|
+
},
|
591
|
+
{
|
592
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("-0.0001")),
|
593
|
+
maxDecimals: 3,
|
594
|
+
inequalitySymbolSeparator: " ",
|
595
|
+
resStr: "> -0.001",
|
596
|
+
},
|
597
|
+
{
|
598
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("-0.0001")),
|
599
|
+
maxDecimals: 3,
|
600
|
+
inequalitySymbolSeparator: "",
|
601
|
+
resStr: ">-0.001",
|
602
|
+
},
|
603
|
+
{
|
604
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("-0.001")),
|
605
|
+
maxDecimals: 3,
|
606
|
+
inequalitySymbolSeparator: " ",
|
607
|
+
resStr: "-0.001",
|
608
|
+
},
|
609
|
+
{
|
610
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("-0.123456")),
|
611
|
+
maxDecimals: 0,
|
612
|
+
inequalitySymbolSeparator: " ",
|
613
|
+
resStr: "> -1",
|
614
|
+
},
|
615
|
+
{
|
616
|
+
base: new int_pretty_1.IntPretty(new decimal_1.Dec("-1.123456")),
|
617
|
+
maxDecimals: 0,
|
618
|
+
inequalitySymbolSeparator: " ",
|
619
|
+
resStr: "-1",
|
620
|
+
},
|
621
|
+
];
|
622
|
+
for (const test of tests) {
|
623
|
+
expect(test.base
|
624
|
+
.maxDecimals(test.maxDecimals)
|
625
|
+
.inequalitySymbol(true)
|
626
|
+
.inequalitySymbolSeparator(test.inequalitySymbolSeparator)
|
627
|
+
.toString()).toBe(test.resStr);
|
628
|
+
}
|
629
|
+
});
|
630
|
+
it("Test toStringWithSymbols() of IntPretty", () => {
|
631
|
+
expect(new int_pretty_1.IntPretty(new decimal_1.Dec(-123.45)).toStringWithSymbols("$", "SUFFIX")).toBe("-$123.45SUFFIX");
|
632
|
+
expect(new int_pretty_1.IntPretty(new decimal_1.Dec(-123.45))
|
633
|
+
.maxDecimals(0)
|
634
|
+
.toStringWithSymbols("$", "SUFFIX")).toBe("-$123SUFFIX");
|
635
|
+
expect(new int_pretty_1.IntPretty(new decimal_1.Dec(-0.045))
|
636
|
+
.maxDecimals(1)
|
637
|
+
.inequalitySymbol(true)
|
638
|
+
.toStringWithSymbols("$", "SUFFIX")).toBe("> -$0.1SUFFIX");
|
639
|
+
expect(new int_pretty_1.IntPretty(new decimal_1.Dec(0.045))
|
640
|
+
.maxDecimals(1)
|
641
|
+
.inequalitySymbol(true)
|
642
|
+
.toStringWithSymbols("$", "SUFFIX")).toBe("< $0.1SUFFIX");
|
643
|
+
});
|
477
644
|
});
|
478
645
|
//# sourceMappingURL=int-pretty.spec.js.map
|