@qlibs/utils 1.4.1 → 1.5.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.
- package/dist/utils/number.d.ts +3 -0
- package/dist/utils/number.js +40 -0
- package/package.json +1 -1
package/dist/utils/number.d.ts
CHANGED
@@ -1,3 +1,6 @@
|
|
1
1
|
export declare function formatNumberRange(amountStart: number, amountEnd?: number, locale?: string): string;
|
2
|
+
export declare function formatPriceRange(amountStart: number, amountEnd?: number | undefined, currency?: 'IDR' | 'USD' | 'EUR'): string;
|
3
|
+
export declare function formatPrice(num: string, currency?: 'IDR' | 'USD' | 'EUR'): string;
|
4
|
+
export declare function parseFormattedPrice(formattedString: string, currency?: 'IDR' | 'USD' | 'EUR'): number;
|
2
5
|
export declare function formatNumber(num: string | number | undefined, locale?: string, currency?: 'IDR' | 'USD' | 'EUR'): string;
|
3
6
|
export declare function parseFormattedNumber(formattedString: string, locale?: string, currency?: 'IDR' | 'USD' | 'EUR'): number;
|
package/dist/utils/number.js
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.formatNumberRange = formatNumberRange;
|
4
|
+
exports.formatPriceRange = formatPriceRange;
|
5
|
+
exports.formatPrice = formatPrice;
|
6
|
+
exports.parseFormattedPrice = parseFormattedPrice;
|
4
7
|
exports.formatNumber = formatNumber;
|
5
8
|
exports.parseFormattedNumber = parseFormattedNumber;
|
6
9
|
function formatNumberRange(amountStart, amountEnd, locale = 'id-ID') {
|
@@ -22,6 +25,43 @@ function formatNumberRange(amountStart, amountEnd, locale = 'id-ID') {
|
|
22
25
|
return '';
|
23
26
|
}
|
24
27
|
}
|
28
|
+
function formatPriceRange(amountStart, amountEnd, currency = 'IDR') {
|
29
|
+
if (amountStart === amountEnd) {
|
30
|
+
return formatNumber(amountStart, currency);
|
31
|
+
}
|
32
|
+
else if (amountStart && amountEnd) {
|
33
|
+
return (formatNumber(amountStart, currency) +
|
34
|
+
' - ' +
|
35
|
+
formatNumber(amountEnd, currency));
|
36
|
+
}
|
37
|
+
else if (amountStart) {
|
38
|
+
return formatNumber(amountStart, currency) + ' - unlimited';
|
39
|
+
}
|
40
|
+
else if (amountEnd) {
|
41
|
+
return 'up to ' + formatNumber(amountEnd, currency);
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
return '';
|
45
|
+
}
|
46
|
+
}
|
47
|
+
function formatPrice(num, currency = 'IDR') {
|
48
|
+
if (currency === 'USD') {
|
49
|
+
return formatNumber(num, 'en-US', 'USD');
|
50
|
+
}
|
51
|
+
else if (currency === 'EUR') {
|
52
|
+
return formatNumber(num, 'de-DE', 'EUR');
|
53
|
+
}
|
54
|
+
return formatNumber(num, 'id-ID', 'IDR');
|
55
|
+
}
|
56
|
+
function parseFormattedPrice(formattedString, currency = 'IDR') {
|
57
|
+
if (currency === 'USD') {
|
58
|
+
return parseFormattedNumber(formattedString, 'en-US', currency);
|
59
|
+
}
|
60
|
+
else if (currency === 'EUR') {
|
61
|
+
return parseFormattedNumber(formattedString, 'de-DE', currency);
|
62
|
+
}
|
63
|
+
return parseFormattedNumber(formattedString, 'id-ID', currency);
|
64
|
+
}
|
25
65
|
function formatNumber(num, locale = 'id-ID', currency) {
|
26
66
|
if (!num) {
|
27
67
|
num = 0;
|