@keplr-wallet/unit 0.9.10 → 0.9.11-rc.1

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.
Files changed (68) hide show
  1. package/build/coin-pretty.d.ts +13 -3
  2. package/build/coin-pretty.js +36 -25
  3. package/build/coin-pretty.js.map +1 -1
  4. package/build/coin-pretty.spec.js +194 -9
  5. package/build/coin-pretty.spec.js.map +1 -1
  6. package/build/coin-utils.js +8 -4
  7. package/build/coin-utils.js.map +1 -1
  8. package/build/coin-utils.spec.js +16 -0
  9. package/build/coin-utils.spec.js.map +1 -1
  10. package/build/coin.js +1 -1
  11. package/build/coin.js.map +1 -1
  12. package/build/coin.spec.js +15 -0
  13. package/build/coin.spec.js.map +1 -1
  14. package/build/dec-utils.d.ts +8 -1
  15. package/build/dec-utils.js +22 -20
  16. package/build/dec-utils.js.map +1 -1
  17. package/build/dec-utils.spec.js +19 -0
  18. package/build/dec-utils.spec.js.map +1 -1
  19. package/build/decimal.d.ts +18 -9
  20. package/build/decimal.js +63 -27
  21. package/build/decimal.js.map +1 -1
  22. package/build/decimal.spec.js +218 -2
  23. package/build/decimal.spec.js.map +1 -1
  24. package/build/index.d.ts +1 -0
  25. package/build/index.js +1 -0
  26. package/build/index.js.map +1 -1
  27. package/build/int-pretty.d.ts +16 -4
  28. package/build/int-pretty.js +74 -36
  29. package/build/int-pretty.js.map +1 -1
  30. package/build/int-pretty.spec.js +261 -94
  31. package/build/int-pretty.spec.js.map +1 -1
  32. package/build/int.d.ts +14 -2
  33. package/build/int.js +48 -0
  34. package/build/int.js.map +1 -1
  35. package/build/int.spec.d.ts +1 -0
  36. package/build/int.spec.js +133 -0
  37. package/build/int.spec.js.map +1 -0
  38. package/build/price-pretty.d.ts +13 -3
  39. package/build/price-pretty.js +37 -26
  40. package/build/price-pretty.js.map +1 -1
  41. package/build/price-pretty.spec.js +59 -2
  42. package/build/price-pretty.spec.js.map +1 -1
  43. package/build/rate-pretty.d.ts +57 -0
  44. package/build/rate-pretty.js +128 -0
  45. package/build/rate-pretty.js.map +1 -0
  46. package/build/rate-pretty.spec.d.ts +1 -0
  47. package/build/rate-pretty.spec.js +38 -0
  48. package/build/rate-pretty.spec.js.map +1 -0
  49. package/package.json +2 -2
  50. package/src/coin-pretty.spec.ts +304 -11
  51. package/src/coin-pretty.ts +56 -29
  52. package/src/coin-utils.spec.ts +32 -0
  53. package/src/coin-utils.ts +12 -4
  54. package/src/coin.spec.ts +20 -0
  55. package/src/coin.ts +1 -1
  56. package/src/dec-utils.spec.ts +39 -0
  57. package/src/dec-utils.ts +25 -20
  58. package/src/decimal.spec.ts +269 -2
  59. package/src/decimal.ts +84 -54
  60. package/src/index.ts +1 -0
  61. package/src/int-pretty.spec.ts +296 -101
  62. package/src/int-pretty.ts +87 -34
  63. package/src/int.spec.ts +178 -0
  64. package/src/int.ts +66 -2
  65. package/src/price-pretty.spec.ts +106 -2
  66. package/src/price-pretty.ts +50 -30
  67. package/src/rate-pretty.spec.ts +52 -0
  68. package/src/rate-pretty.ts +165 -0
@@ -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 the precision of IntPretty", () => {
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
- precision: 0,
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
- precision: 0,
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
- precision: 0,
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
- precision: 0,
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
- precision: 2,
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
- precision: 2,
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
- precision: 2,
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
- precision: 2,
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
- precision: 2,
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
- precision: 2,
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
- precision: 2,
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
- precision: 2,
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.precision).toBe(param.precision);
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
- let pretty = new int_pretty_1.IntPretty(new decimal_1.Dec("10.001"));
91
- expect(pretty.options.precision).toBe(3);
92
- expect(pretty.toString()).toBe("10.001");
93
- let newPretty = pretty.precision(4);
94
- expect(newPretty.options.precision).toBe(4);
95
- // Max decimals not changed
96
- expect(newPretty.toString()).toBe("1.000");
97
- expect(newPretty.maxDecimals(4).toString()).toBe("1.0001");
98
- newPretty = pretty.increasePrecision(1);
99
- expect(newPretty.options.precision).toBe(4);
100
- expect(newPretty.toString()).toBe("1.000");
101
- expect(newPretty.maxDecimals(4).toString()).toBe("1.0001");
102
- newPretty = pretty.precision(2);
103
- expect(newPretty.options.precision).toBe(2);
104
- expect(newPretty.toString()).toBe("100.010");
105
- newPretty = pretty.decreasePrecision(1);
106
- expect(newPretty.options.precision).toBe(2);
107
- expect(newPretty.toString()).toBe("100.010");
108
- newPretty = pretty.decreasePrecision(6);
109
- expect(newPretty.options.precision).toBe(-3);
110
- expect(newPretty.toString()).toBe("10,001,000.000");
111
- pretty = new int_pretty_1.IntPretty(new int_1.Int(0));
112
- expect(pretty.decreasePrecision(3).toString()).toBe("0");
113
- expect(pretty.increasePrecision(3).toString()).toBe("0");
114
- expect(() => {
115
- pretty.precision(-18);
116
- }).not.toThrow();
117
- expect(() => {
118
- pretty.precision(18);
119
- }).not.toThrow();
120
- expect(() => {
121
- pretty.precision(-19);
122
- }).toThrow();
123
- expect(() => {
124
- pretty.precision(19);
125
- }).toThrow();
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