@opexa/portal-components 0.0.1052 → 0.0.1053

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,5 +1,5 @@
1
1
  import { cache } from 'react';
2
- import { parseDecimal } from './parseDecimal.js';
2
+ import { safeParseFloat } from './safeParseFloat.js';
3
3
  const defaultConfig = {
4
4
  locale: 'en-US',
5
5
  compact: false,
@@ -40,7 +40,7 @@ export const formatNumber = cache((value, config) => {
40
40
  }
41
41
  : {}),
42
42
  });
43
- let parsed = parseDecimal(value, 0);
43
+ let parsed = safeParseFloat(value, 0);
44
44
  if (truncate) {
45
45
  parsed = truncateDecimals(parsed, maxDecimalPlaces);
46
46
  }
@@ -0,0 +1,2 @@
1
+ export declare function safeParseFloat(value: unknown, fallback: number): number;
2
+ export declare function safeParseFloat(value: unknown): number | undefined;
@@ -0,0 +1,19 @@
1
+ import * as z from 'zod';
2
+ const definition = z
3
+ .union([
4
+ z.number().transform((val) => {
5
+ return Number.isNaN(val) ? null : val;
6
+ }),
7
+ z.string().transform((val) => {
8
+ const parsed = Number.parseFloat(val);
9
+ if (Number.isNaN(parsed))
10
+ return null;
11
+ return parsed;
12
+ }),
13
+ ])
14
+ .optional()
15
+ .nullable()
16
+ .catch(null);
17
+ export function safeParseFloat(value, fallback) {
18
+ return definition.parse(value) ?? fallback;
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opexa/portal-components",
3
- "version": "0.0.1052",
3
+ "version": "0.0.1053",
4
4
  "exports": {
5
5
  "./ui/*": {
6
6
  "types": "./dist/ui/*/index.d.ts",