import { NodePath } from '@babel/traverse'; import { FilterPattern } from '@rollup/pluginutils'; import { MagicStringAST } from 'magic-string-ast'; declare const DECIMAL_RM_LIGHT: Readonly<{ ROUND_UP: 0; ROUND_DOWN: 1; ROUND_CEIL: 2; ROUND_FLOOR: 3; ROUND_HALF_UP: 4; ROUND_HALF_DOWN: 5; ROUND_HALF_EVEN: 6; ROUND_HALF_CEIL: 7; ROUND_HALF_FLOOR: 8; }>; declare const DECIMAL_RM: Readonly<{ EUCLID: 9; ROUND_UP: 0; ROUND_DOWN: 1; ROUND_CEIL: 2; ROUND_FLOOR: 3; ROUND_HALF_UP: 4; ROUND_HALF_DOWN: 5; ROUND_HALF_EVEN: 6; ROUND_HALF_CEIL: 7; ROUND_HALF_FLOOR: 8; }>; declare const BIG_RM: Readonly<{ ROUND_DOWN: 0; ROUND_HALF_UP: 1; ROUND_HALF_DOWN: 2; ROUND_UP: 3; }>; interface AutoDecimal { } interface Options { shouldSkip: boolean; msa: MagicStringAST; imported: boolean; decimalPkgName: string; initial: boolean; callMethod: CallMethod; callArgs: string; autoDecimalOptions: InnerAutoDecimalOptions; integer: boolean; fromNewFunction?: boolean; needImport?: boolean; ownerPath?: NodePath; } interface ToDecimalConfig extends ToDecimalOptions { name?: string; } interface AutoDecimalOptions { /** * @desc 支持字符串数字 */ supportString?: boolean; /** * @desc 是否启用末尾补 0 的形式 * * 当启用后,只有计算表达式的最末端 “+0“ 才会转换 */ tailPatchZero?: boolean; /** * @desc 高精度计算库 * * @type {decimal.js | decimal.js-light | big.js} */ package?: Package; /** * @desc 启用 toDecimal 来显式转换计算表达式 * * 启用后,只有计算表达式使用 .toDecimal() 时,才会转换。 */ toDecimal?: boolean | ToDecimalConfig; /** * @desc 是否生成 dts 文件 * * 当前项目中存在 typescript 时,默认生成 */ dts?: boolean | string; /** * @desc 是否启用装饰器 */ decorator?: boolean; /** * @desc 转换时,Decimal 实例的名称,避免命名冲突。 * * @default __Decimal */ decimalName?: string; /** * @desc 支持 new Function 表达式 * * 默认情况下,new Function 中的参数不会转换 */ supportNewFunction?: boolean | NewFunctionOptions; /** * @desc 包含的文件 * @default *.(cjs|mjs|js|ts|mts|jsx|tsx|vue) */ includes?: FilterPattern; /** * @desc 排除的文件 * @default node_modules */ excludes?: FilterPattern; } type InnerAutoDecimalOptions = Required & { ext: string; }; interface ToDecimalOptions { /** * @desc 调用 Decimal 的方法,或者定义是否返回 decimal 实例 * @alias cm * @type {toNumber | toString | toFixed | decimal} */ callMethod?: CallMethod; /** * @desc callMethod 别名 */ cm?: CallMethod; /** * @desc 调用 Decimal 的 toFixed 方法时,需要保留的小数位数 * @alias p * @type {number} */ precision?: number; /** * @desc precision 别名 */ p?: number; /** * @desc 调用 Decimal 的 toFixed 方法时,使用的舍入模式 * @alias rm * @type {RoundingModes | number} * @tutorial https://mikemcl.github.io/decimal.js/#modes */ roundingModes?: RoundingModes | number; /** * @desc roundingModes 别名 */ rm?: RoundingModes | number; } type InnerToDecimalOptions = Required; type ToDecimal = (options?: T) => ToDecimalReturn; interface Extra { __extra: Record; options: Options; __shouldTransform: boolean; } type CallMethod = 'toNumber' | 'toString' | 'toFixed' | 'decimal'; type Package = 'decimal.js' | 'decimal.js-light' | 'big.js'; type ToDecimalReturn = GetToDecimalReturn | GetToDecimalReturn; type RoundingModes = AutoDecimal['package'] extends 'big.js' ? BigRoundingMode : AutoDecimal['package'] extends 'decimal.js' ? DecimalRoundingMode : DecimalLightRoundingMode; type DecimalRoundingMode = keyof typeof DECIMAL_RM; type DecimalLightRoundingMode = keyof typeof DECIMAL_RM_LIGHT; type BigRoundingMode = keyof typeof BIG_RM; type Operator = '+' | '-' | '*' | '/'; interface CommentState { line: number; block: boolean; next: boolean; } interface NewFunctionOptions { toDecimal?: boolean | ToDecimalConfig; injectWindow?: string; } type GetToDecimalReturn = V extends keyof T ? T[V] extends 'toFixed' | 'toString' ? string : T[V] extends 'decimal' ? AutoDecimal['decimal'] : number : never; export type { AutoDecimal, AutoDecimalOptions, BigRoundingMode, CallMethod, CommentState, DecimalLightRoundingMode, DecimalRoundingMode, Extra, InnerAutoDecimalOptions, InnerToDecimalOptions, NewFunctionOptions, Operator, Options, Package, RoundingModes, ToDecimal, ToDecimalConfig, ToDecimalOptions, ToDecimalReturn };