a-calc 3.0.0-beta.20260124.1 → 3.0.0-beta.20260124.2

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/calc.d.ts CHANGED
@@ -67,18 +67,29 @@ type If_DirectReturn<Arg1, Arg2> =
67
67
  If_NumOrStr<Arg1> & Not<If_IncludesVar<Arg1>>
68
68
  >;
69
69
 
70
- type CalcConfig<Fmt extends string, Err> =
70
+ /**
71
+ * calc/calc_space 运行时选项类型(可以包含数据和配置)
72
+ */
73
+ type CalcRuntimeOptions<Fmt extends string, Err> =
71
74
  any[] | Partial<{
72
- _error: Err,
73
- _fill_data: any,
74
- _unit: boolean,
75
- _fmt: Fmt,
76
- _memo: boolean,
77
- [Prop: string]: any;
75
+ _error: Err;
76
+ _fmt: Fmt;
77
+ _unit: boolean;
78
+ _debug?: boolean;
79
+ _on_debug?: (info: any) => void;
80
+ _angle_unit?: 'deg' | 'rad';
81
+ _compact_units?: string[];
82
+ _compact_step?: number | number[];
83
+ _thousands?: Record<string, ThousandsPreset>;
84
+ /** 多路取值时视为空值的值数组(仅运行时选项) */
85
+ _empty_values?: any[];
86
+ /** 多路取值时自定义空值判断函数(仅运行时选项) */
87
+ _empty_check?: (value: any, path?: string) => boolean;
88
+ [key: string]: any; // 允许任意数据字段
78
89
  }>;
79
90
 
80
91
  export type Calc = <const Expr extends string | number, const Fmt extends string, const Err = never>
81
- (expr: Expr, options?: CalcConfig<Fmt, Err>) =>
92
+ (expr: Expr, options?: CalcRuntimeOptions<Fmt, Err>) =>
82
93
  (
83
94
  If_StrIncludes<Fmt, ["!n"]> & If_StrIncludes<Expr, ["!n"]> extends true ?
84
95
  number | Err
@@ -87,7 +98,7 @@ export type Calc = <const Expr extends string | number, const Fmt extends string
87
98
  );
88
99
 
89
100
  export type CalcSpace = <const Expr extends string | number, const Fmt extends string, const Err = never>
90
- (expr: Expr, options?: CalcConfig<Fmt, Err>) =>
101
+ (expr: Expr, options?: CalcRuntimeOptions<Fmt, Err>) =>
91
102
  (
92
103
  If_StrIncludes<Fmt, ["!n"]> & If_StrIncludes<Expr, ["!n"]> extends true ?
93
104
  number | Err
@@ -96,7 +107,7 @@ export type CalcSpace = <const Expr extends string | number, const Fmt extends s
96
107
  );
97
108
 
98
109
  export type CalcSum = <const Expr extends string | number, const Fmt extends string, const Err = never>
99
- (expr: Expr, options: Array<CalcConfig<Fmt, Err>>) =>
110
+ (expr: Expr, options: Array<CalcRuntimeOptions<Fmt, Err>>) =>
100
111
  (
101
112
  If_StrIncludes<Fmt, ["!n"]> & If_StrIncludes<Expr, ["!n"]> extends true ?
102
113
  number | Err
@@ -105,26 +116,30 @@ export type CalcSum = <const Expr extends string | number, const Fmt extends str
105
116
  );
106
117
 
107
118
  /**
108
- * fmt 格式化选项
119
+ * fmt 格式化选项(运行时选项,可以包含数据)
109
120
  */
110
121
  export interface FmtOptions {
111
122
  _error?: any;
112
123
  _fmt?: string;
113
- /** 交易量单位数组(仅选项,临时覆盖) */
114
- _vol_units?: string[];
115
- /** 交易量阶梯值(仅选项,临时覆盖) */
116
- _vol_step?: number | number[];
117
- /** 交易量预设配置(仅选项) */
118
- _vol?: Record<string, VolumePreset>;
124
+ /** 紧凑格式单位数组(仅选项,临时覆盖) */
125
+ _compact_units?: string[];
126
+ /** 紧凑格式阶梯值(仅选项,临时覆盖) */
127
+ _compact_step?: number | number[];
128
+ /** 紧凑格式预设配置(仅选项) */
129
+ _compact?: Record<string, CompactPreset>;
119
130
  _unit_convert_out?: Record<string, any>;
120
131
  _unit_convert_in?: Record<string, any>;
121
132
  _unit_default_out?: string | string[];
122
133
  _unit_default_in?: string | string[];
123
134
  _unit_default_position?: 'before' | 'after' | 'middle';
124
- _unit_default_positions?: Record<string, 'before' | 'after' | 'middle'>;
125
- _thousands?: Record<string, any>;
126
- _unit_thousands?: Record<string, string>;
127
- _unit_vol?: Record<string, string>;
135
+ _unit_position_map?: Record<string, 'before' | 'after' | 'middle'>;
136
+ _thousands?: Record<string, ThousandsPreset>;
137
+ _unit_thousands_map?: Record<string, string>;
138
+ _unit_compact_map?: Record<string, string>;
139
+ /** 多路取值时视为空值的值数组(仅运行时选项) */
140
+ _empty_values?: any[];
141
+ /** 多路取值时自定义空值判断函数(仅运行时选项) */
142
+ _empty_check?: (value: any, path?: string) => boolean;
128
143
  [key: string]: any;
129
144
  }
130
145
 
@@ -144,10 +159,10 @@ export interface CalcWrap {
144
159
  <const Expr extends string | number>
145
160
  (expr: Expr): If_IncludesVar<Expr> extends true ? FuncReturn<Expr> : If_StrIncludes<Expr, ["!n", "!N"]> extends true ? number | "-" : string | "-";
146
161
 
147
- <const Expr extends string | number, const Fmt extends string, const Err, const Options extends CalcConfig<Fmt, Err>>
162
+ <const Expr extends string | number, const Fmt extends string, const Err, const Options extends CalcRuntimeOptions<Fmt, Err>>
148
163
  (expr: Expr, options: Options): DirectReturn<Expr, Options>;
149
164
 
150
- <const Fmt extends string, const Err, const Options extends CalcConfig<Fmt, Err>>
165
+ <const Fmt extends string, const Err, const Options extends CalcRuntimeOptions<Fmt, Err>>
151
166
  (options: Options): FuncReturn<Options>;
152
167
  }
153
168
 
@@ -462,9 +477,9 @@ export interface ThousandsPreset {
462
477
  }
463
478
 
464
479
  /**
465
- * 交易量预设配置类型
480
+ * 紧凑格式预设配置类型
466
481
  */
467
- export type VolumePreset =
482
+ export type CompactPreset =
468
483
  | string[] // 简写形式:只有单位数组,step 默认 1000
469
484
  | { // 完整形式:包含 units 和 step
470
485
  units: string[];
@@ -482,27 +497,35 @@ export type VolumePreset =
482
497
  } | string); // 可以返回对象或字符串
483
498
 
484
499
  /**
485
- * 全局配置项
500
+ * 全局配置项(只能通过 set_config 设置)
486
501
  */
487
- export interface CalcConfig {
502
+ export interface GlobalConfig {
488
503
  /** 计算模式: "decimal" | "bigint" | "wasm" */
489
504
  _compute_mode?: ComputeMode;
490
505
  /** 角度单位: "deg" (度) | "rad" (弧度),默认 "deg" */
491
506
  _angle_unit?: AngleUnit;
492
507
  /** 除法精度(小数位数),默认 20 */
493
508
  _div_precision?: number;
494
- /** 错误时的返回值 */
509
+ /** 错误时的返回值,默认 '-' */
495
510
  _error?: any;
496
511
  /** 是否启用调试模式控制台输出,默认 true */
497
512
  _debug_console?: boolean;
498
- /** 自定义函数映射 */
499
- _custom_functions?: Record<string, (...args: any[]) => any>;
513
+ /** 默认舍入模式 */
514
+ _default_round?: string;
515
+ /** 默认格式化字符串(全局配置) */
516
+ _fmt?: string;
517
+ /** 内置函数映射 */
518
+ _builtin_functions?: Record<string, (...args: any[]) => any>;
519
+
520
+ // ==================== 紧凑格式配置 ====================
521
+ /** 紧凑格式预设配置(全局配置) */
522
+ _compact?: Record<string, CompactPreset>;
523
+ /** 默认紧凑格式预设名称 */
524
+ _compact_default?: string;
500
525
 
501
- // ==================== 交易量配置 ====================
502
- /** 交易量预设配置(支持对象、数组简写、自定义函数) */
503
- _vol?: Record<string, VolumePreset>;
504
- /** 默认交易量预设名称 */
505
- _vol_default?: string;
526
+ // ==================== 格式化分组配置 ====================
527
+ /** 格式化分组(全局配置) */
528
+ _fmt_groups?: Record<string, string>;
506
529
 
507
530
  // ==================== 单位转换配置 ====================
508
531
  /** 单位转换映射(输出单位为key) */
@@ -521,15 +544,24 @@ export interface CalcConfig {
521
544
  _unit_position_map?: Record<string, 'before' | 'after' | 'middle'>;
522
545
  /** 单位到千分位预设的映射 */
523
546
  _unit_thousands_map?: Record<string, string>;
524
- /** 单位到交易量预设的映射 */
525
- _unit_vol_map?: Record<string, string>;
547
+ /** 单位到紧凑格式预设的映射 */
548
+ _unit_compact_map?: Record<string, string>;
526
549
 
527
550
  // ==================== 千分位配置 ====================
528
551
  /** 千分位预设配置 */
529
552
  _thousands?: Record<string, ThousandsPreset>;
530
-
531
- /** 其他自定义配置 */
532
- [key: string]: any;
553
+ /** 默认千分位预设名称 */
554
+ _thousands_default?: string;
555
+
556
+ // ==================== 快捷语法配置 ====================
557
+ /** 快捷语法前缀(:xxx 等同于 _shortcut_prefix:xxx),默认 '!u' */
558
+ _shortcut_prefix?: string;
559
+
560
+ // ==================== 多路取值配置 ====================
561
+ /** 多路取值时视为空值的值数组(全局配置,运行时选项可覆盖) */
562
+ _empty_values?: any[];
563
+ /** 多路取值时自定义空值判断函数(全局配置,运行时选项可覆盖) */
564
+ _empty_check?: (value: any, path?: string) => boolean;
533
565
  }
534
566
 
535
567
  /**
@@ -541,7 +573,7 @@ export interface CalcConfig {
541
573
  * set_config({ _div_precision: 30 }) // 设置除法精度为 30 位
542
574
  * set_config({ _error: 0 }) // 错误时返回 0
543
575
  */
544
- export function set_config(config: CalcConfig): void;
576
+ export function set_config(config: GlobalConfig): void;
545
577
 
546
578
  /**
547
579
  * 获取全局配置
@@ -551,8 +583,8 @@ export function set_config(config: CalcConfig): void;
551
583
  * get_config('_compute_mode') // => 'decimal'
552
584
  * get_config() // => { _compute_mode: 'decimal', ... }
553
585
  */
554
- export function get_config(): CalcConfig;
555
- export function get_config<K extends keyof CalcConfig>(key: K): CalcConfig[K];
586
+ export function get_config(): GlobalConfig;
587
+ export function get_config<K extends keyof GlobalConfig>(key: K): GlobalConfig[K];
556
588
 
557
589
  /**
558
590
  * 重置全局配置到默认值
@@ -563,8 +595,8 @@ export function get_config<K extends keyof CalcConfig>(key: K): CalcConfig[K];
563
595
  * reset_config(['_unit_convert_out', '_unit_default_out']) // 重置多个配置
564
596
  */
565
597
  export function reset_config(): void;
566
- export function reset_config(key: keyof CalcConfig): void;
567
- export function reset_config(keys: (keyof CalcConfig)[]): void;
598
+ export function reset_config(key: keyof GlobalConfig): void;
599
+ export function reset_config(keys: (keyof GlobalConfig)[]): void;
568
600
 
569
601
  /**
570
602
  * 运算符方法类型(内部使用,通过 r* 函数访问)