@qlibs/utils 1.2.0 → 1.3.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.
@@ -0,0 +1,2 @@
1
+ export declare function formatNumberRange(amountStart: number, amountEnd?: number): string;
2
+ export declare function formatNumber(amount: number, thousandSep?: string, decimalSep?: string, showDecimal?: boolean): string;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatNumberRange = formatNumberRange;
4
+ exports.formatNumber = formatNumber;
5
+ function formatNumberRange(amountStart, amountEnd) {
6
+ if (amountStart === amountEnd) {
7
+ return formatNumber(amountStart);
8
+ }
9
+ else if (amountStart && amountEnd) {
10
+ return (formatNumber(amountStart) +
11
+ ' - ' +
12
+ formatNumber(amountEnd));
13
+ }
14
+ else if (amountStart) {
15
+ return formatNumber(amountStart) + ' - unlimited';
16
+ }
17
+ else if (amountEnd) {
18
+ return 'up to ' + formatNumber(amountEnd);
19
+ }
20
+ else {
21
+ return '';
22
+ }
23
+ }
24
+ function formatNumber(amount, thousandSep = ',', decimalSep = '.', showDecimal = true) {
25
+ if (typeof amount === 'string')
26
+ amount = Number(amount);
27
+ if (!amount)
28
+ amount = 0;
29
+ const [intPart, decPart] = amount.toFixed(2).split('.');
30
+ let intPartWithSep = '';
31
+ for (let i = intPart.length - 1, j = 0; i >= 0; i--, j++) {
32
+ if (j > 0 && j % 3 === 0) {
33
+ intPartWithSep = thousandSep + intPartWithSep;
34
+ }
35
+ intPartWithSep = intPart[i] + intPartWithSep;
36
+ }
37
+ return (intPartWithSep + (showDecimal ? decimalSep + decPart : ''));
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlibs/utils",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "author": "QBIT Developer",
6
6
  "license": "MIT",