@megha-ui/react 1.2.104 → 1.2.106
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const formatValue: (value: string | number, type: string, locale?: string, options?: Intl.NumberFormatOptions) => string | number;
|
|
1
|
+
export declare const formatValue: (value: string | number | Date, type: string, locale?: string, options?: Intl.NumberFormatOptions) => string | number;
|
|
@@ -20,12 +20,13 @@ const formatCurrency = (value, locale = "sv-SE", currency = "SEK", options = {})
|
|
|
20
20
|
const formatValue = (value, type = "number", locale = "sv-SE", options = {
|
|
21
21
|
currency: "SEK"
|
|
22
22
|
}) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
23
25
|
if (type === "number") {
|
|
24
26
|
const num = parseFloat(value.toString());
|
|
25
27
|
return formatNumber(num, locale, options);
|
|
26
28
|
}
|
|
27
|
-
else if (type === "date") {
|
|
28
|
-
const date = new Date(value);
|
|
29
|
+
else if (type === "date" && !isNaN(date.getTime())) {
|
|
29
30
|
return formatDate(date, locale, options);
|
|
30
31
|
}
|
|
31
32
|
else if (type === "currency") {
|
|
@@ -33,7 +34,7 @@ const formatValue = (value, type = "number", locale = "sv-SE", options = {
|
|
|
33
34
|
return formatCurrency(num, locale, options.currency, options);
|
|
34
35
|
}
|
|
35
36
|
else {
|
|
36
|
-
return value;
|
|
37
|
+
return typeof value === "number" ? value : (_b = (_a = value === null || value === void 0 ? void 0 : value.toString) === null || _a === void 0 ? void 0 : _a.call(value)) !== null && _b !== void 0 ? _b : "";
|
|
37
38
|
}
|
|
38
39
|
};
|
|
39
40
|
exports.formatValue = formatValue;
|
package/package.json
CHANGED