@blocklet/aigne-hub 0.7.12 → 0.7.14

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.
@@ -3,25 +3,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CREDIT_DISPLAY_DECIMAL_PLACES = void 0;
7
6
  exports.formatNumber = formatNumber;
8
7
  const trimEnd_1 = __importDefault(require("lodash/trimEnd"));
9
8
  const numbro_1 = __importDefault(require("numbro"));
10
- // Decimal places for credit display in UI (different from backend calculation precision)
11
- exports.CREDIT_DISPLAY_DECIMAL_PLACES = 6;
12
- function formatNumber(n, precision = 6, trim = true, thousandSeparated = true) {
13
- if (!n || n === '0') {
9
+ function formatNumber(n, precision = 2, trim = false, thousandSeparated = true, maxPrecision = 6) {
10
+ const num = (0, numbro_1.default)(n || 0);
11
+ const value = num.value();
12
+ if (!value) {
14
13
  return '0';
15
14
  }
16
- const num = (0, numbro_1.default)(n);
17
- const options = {
18
- thousandSeparated,
19
- ...((precision || precision === 0) && { mantissa: precision }),
15
+ const trimZeros = (valueString) => {
16
+ const [left, right] = valueString.split('.');
17
+ return right ? [left, (0, trimEnd_1.default)(right, '0')].filter(Boolean).join('.') : left;
20
18
  };
21
- const result = num.format(options);
19
+ const isZeroString = (valueString) => {
20
+ const trimmed = trimZeros(valueString);
21
+ return trimmed === '0' || trimmed === '-0';
22
+ };
23
+ let result = value.toString();
24
+ for (let p = precision; p <= Math.max(precision, maxPrecision); p += 1) {
25
+ result = num.format({
26
+ thousandSeparated,
27
+ mantissa: p,
28
+ roundingFunction: (n) => (n < 0 ? Math.ceil(n) : Math.floor(n)),
29
+ });
30
+ if (!isZeroString(result))
31
+ break;
32
+ }
22
33
  if (!trim) {
23
34
  return result;
24
35
  }
25
- const [left, right] = result.split('.');
26
- return right ? [left, (0, trimEnd_1.default)(right, '0')].filter(Boolean).join('.') : left;
36
+ return trimZeros(result);
27
37
  }
@@ -1,20 +1,31 @@
1
1
  import trimEnd from 'lodash/trimEnd';
2
2
  import numbro from 'numbro';
3
- // Decimal places for credit display in UI (different from backend calculation precision)
4
- export const CREDIT_DISPLAY_DECIMAL_PLACES = 6;
5
- export function formatNumber(n, precision = 6, trim = true, thousandSeparated = true) {
6
- if (!n || n === '0') {
3
+ export function formatNumber(n, precision = 2, trim = false, thousandSeparated = true, maxPrecision = 6) {
4
+ const num = numbro(n || 0);
5
+ const value = num.value();
6
+ if (!value) {
7
7
  return '0';
8
8
  }
9
- const num = numbro(n);
10
- const options = {
11
- thousandSeparated,
12
- ...((precision || precision === 0) && { mantissa: precision }),
9
+ const trimZeros = (valueString) => {
10
+ const [left, right] = valueString.split('.');
11
+ return right ? [left, trimEnd(right, '0')].filter(Boolean).join('.') : left;
13
12
  };
14
- const result = num.format(options);
13
+ const isZeroString = (valueString) => {
14
+ const trimmed = trimZeros(valueString);
15
+ return trimmed === '0' || trimmed === '-0';
16
+ };
17
+ let result = value.toString();
18
+ for (let p = precision; p <= Math.max(precision, maxPrecision); p += 1) {
19
+ result = num.format({
20
+ thousandSeparated,
21
+ mantissa: p,
22
+ roundingFunction: (n) => (n < 0 ? Math.ceil(n) : Math.floor(n)),
23
+ });
24
+ if (!isZeroString(result))
25
+ break;
26
+ }
15
27
  if (!trim) {
16
28
  return result;
17
29
  }
18
- const [left, right] = result.split('.');
19
- return right ? [left, trimEnd(right, '0')].filter(Boolean).join('.') : left;
30
+ return trimZeros(result);
20
31
  }
@@ -1,2 +1 @@
1
- export declare const CREDIT_DISPLAY_DECIMAL_PLACES = 6;
2
- export declare function formatNumber(n: number | string, precision?: number, trim?: boolean, thousandSeparated?: boolean): string | undefined;
1
+ export declare function formatNumber(n: number | string, precision?: number, trim?: boolean, thousandSeparated?: boolean, maxPrecision?: number): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/aigne-hub",
3
- "version": "0.7.12",
3
+ "version": "0.7.14",
4
4
  "description": "The react.js component library for AIGNE Hub",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -100,8 +100,8 @@
100
100
  "react": "^18.2.0"
101
101
  },
102
102
  "dependencies": {
103
- "@arcblock/did": "^1.27.16",
104
- "@arcblock/ux": "^3.3.8",
103
+ "@arcblock/did": "^1.28.0",
104
+ "@arcblock/ux": "^3.3.10",
105
105
  "@blocklet/error": "0.3.5",
106
106
  "@blocklet/logger": "^1.17.7",
107
107
  "@blocklet/payment-js": "^1.23.7",
@@ -113,8 +113,8 @@
113
113
  "@mui/lab": "^7.0.0-beta.14",
114
114
  "@mui/material": "^7.2.0",
115
115
  "@mui/system": "^7.2.0",
116
- "@ocap/mcrypto": "^1.27.16",
117
- "@ocap/util": "^1.27.16",
116
+ "@ocap/mcrypto": "^1.28.0",
117
+ "@ocap/util": "^1.28.0",
118
118
  "@types/express": "^5.0.3",
119
119
  "ahooks": "^3.8.1",
120
120
  "axios": "^1.7.4",