@trajectonomics/tax 0.0.0-stage → 0.1.0-alpha.0
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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/clamp-BKG7kjVf.cjs +509 -0
- package/dist/clamp-BKG7kjVf.cjs.map +1 -0
- package/dist/clamp-Bse4u0H-.mjs +426 -0
- package/dist/clamp-Bse4u0H-.mjs.map +1 -0
- package/dist/index.cjs +27 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +102 -0
- package/dist/index.d.mts +102 -0
- package/dist/index.mjs +15 -0
- package/dist/index.mjs.map +1 -0
- package/dist/th/index.cjs +1480 -0
- package/dist/th/index.cjs.map +1 -0
- package/dist/th/index.d.cts +636 -0
- package/dist/th/index.d.mts +636 -0
- package/dist/th/index.mjs +1473 -0
- package/dist/th/index.mjs.map +1 -0
- package/dist/types-798sLpt6.d.cts +170 -0
- package/dist/types-798sLpt6.d.mts +170 -0
- package/dist/us/index.cjs +2921 -0
- package/dist/us/index.cjs.map +1 -0
- package/dist/us/index.d.cts +649 -0
- package/dist/us/index.d.mts +649 -0
- package/dist/us/index.mjs +2897 -0
- package/dist/us/index.mjs.map +1 -0
- package/package.json +78 -5
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { a as money, c as ValidateAmountOptions, d as StatutoryCapOptions, f as TaxSupportedCurrency, h as TaxBracket, i as Money, l as validateMonetaryAmount, m as BracketSlice, n as TaxResult, o as thb, p as BracketEvaluationResult, r as TaxSystem, s as usd, t as JurisdictionCode, u as ClampedAmount } from "./types-798sLpt6.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Evaluates progressive tax brackets slice-by-slice across multiple tiers.
|
|
4
|
+
*
|
|
5
|
+
* Math: Slices taxable income across progressive tiers and sums integer tax per slice.
|
|
6
|
+
* Units: All inputs and outputs must be integer minor units (satang/cents).
|
|
7
|
+
*
|
|
8
|
+
* @param taxableAmount Taxable income in integer minor units.
|
|
9
|
+
* @param brackets Ordered progressive statutory tax brackets.
|
|
10
|
+
* @param grossIncome Optional gross income in minor units for statutory effective rate calculation.
|
|
11
|
+
* @param field Diagnostic field name.
|
|
12
|
+
* @returns Evaluated bracket result including total tax, slices, effective rate, and marginal rate.
|
|
13
|
+
* @throws {TaxValidationError} if inputs are invalid.
|
|
14
|
+
*/
|
|
15
|
+
export declare function evaluateBrackets(taxableAmount: number, brackets: readonly TaxBracket[], grossIncome?: number, field?: string): BracketEvaluationResult;
|
|
16
|
+
/**
|
|
17
|
+
* Clamps a requested deduction, allowance, or expense against a statutory cap.
|
|
18
|
+
*
|
|
19
|
+
* @param requested Original requested amount.
|
|
20
|
+
* @param capOrOptions Numeric cap or StatutoryCapOptions specification.
|
|
21
|
+
* @param field Diagnostic field name.
|
|
22
|
+
* @returns Breakdown-ready ClampedAmount structure.
|
|
23
|
+
* @throws {TaxValidationError} if inputs are negative, NaN, or non-finite.
|
|
24
|
+
* @example clampCap(150_000, 100_000, "allowance") // { requested: 150000, allowed: 100000, cap: 100000, wasClamped: true }
|
|
25
|
+
*/
|
|
26
|
+
export declare function clampCap(requested: number, capOrOptions: number | StatutoryCapOptions, field?: string): ClampedAmount;
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when input values violate mathematical boundaries or statutory constraints.
|
|
29
|
+
* Exposes field, raw value, and validation reason for transparency and structured error reporting.
|
|
30
|
+
*/
|
|
31
|
+
export declare class TaxValidationError extends Error {
|
|
32
|
+
readonly field: string;
|
|
33
|
+
readonly value: unknown;
|
|
34
|
+
readonly reason: string;
|
|
35
|
+
constructor(field: string, value: unknown, reason: string);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts a major-unit monetary amount to integer minor units (satang/cent).
|
|
39
|
+
*
|
|
40
|
+
* Math: Decimal string expansion and half-away-from-zero rounding to eliminate IEEE 754 float drift.
|
|
41
|
+
* Units: Input is major currency unit (e.g. THB, USD); output is integer minor units (e.g. Satang, Cents).
|
|
42
|
+
*
|
|
43
|
+
* @param amount Amount in major units.
|
|
44
|
+
* @param currency Supported statutory currency (THB or USD).
|
|
45
|
+
* @param field Diagnostic field name.
|
|
46
|
+
* @param options Validation options (e.g. allowNegative for refund balances).
|
|
47
|
+
* @returns Integer minor units.
|
|
48
|
+
* @throws {TaxValidationError} if amount is NaN, infinite, or results in a non-safe integer.
|
|
49
|
+
* @example toMinorUnits(1.14, "USD") // 114 (114 cents)
|
|
50
|
+
*/
|
|
51
|
+
export declare function toMinorUnits(amount: number, currency: TaxSupportedCurrency, field?: string, options?: ValidateAmountOptions): number;
|
|
52
|
+
/**
|
|
53
|
+
* Converts an integer minor unit amount back to major currency units.
|
|
54
|
+
*
|
|
55
|
+
* @param minorUnits Integer minor units.
|
|
56
|
+
* @param currency Supported statutory currency (THB or USD).
|
|
57
|
+
* @param field Diagnostic field name.
|
|
58
|
+
* @param options Validation options (e.g. allowNegative for refund balances).
|
|
59
|
+
* @returns Amount in major units.
|
|
60
|
+
* @throws {TaxValidationError} if minorUnits is not a safe integer.
|
|
61
|
+
* @example fromMinorUnits(1055, "THB") // 10.55
|
|
62
|
+
*/
|
|
63
|
+
export declare function fromMinorUnits(minorUnits: number, currency: TaxSupportedCurrency, field?: string, options?: ValidateAmountOptions): number;
|
|
64
|
+
/**
|
|
65
|
+
* Supported rounding modes for statutory tax computations.
|
|
66
|
+
*/
|
|
67
|
+
type RoundingMode = "half-up" | "floor" | "ceil";
|
|
68
|
+
/**
|
|
69
|
+
* Rounds a number to the nearest integer, breaking ties away from zero (standard half-up).
|
|
70
|
+
*
|
|
71
|
+
* Math: Rounds fractional halves away from zero (e.g. 1.5 -> 2, -1.5 -> -2).
|
|
72
|
+
*
|
|
73
|
+
* @param value Floating-point value.
|
|
74
|
+
* @returns Rounded integer.
|
|
75
|
+
*/
|
|
76
|
+
export declare function roundHalfUp(value: number): number;
|
|
77
|
+
/**
|
|
78
|
+
* Applies a statutory percentage rate to an integer minor unit amount using exact rational arithmetic.
|
|
79
|
+
*
|
|
80
|
+
* Math: Exact rational scaling via BigInt `(minorUnits * num + modeAdjust) / den`
|
|
81
|
+
* to eliminate IEEE 754 binary floating-point drift on exact statutory tax rates.
|
|
82
|
+
* Units: Input and output are integer minor units (satang/cents).
|
|
83
|
+
*
|
|
84
|
+
* @param minorUnits Integer minor units amount.
|
|
85
|
+
* @param rate Statutory rate ratio (e.g. 0.05 for 5%, 0.35 for 35%).
|
|
86
|
+
* @param rounding Rounding mode (`half-up`, `floor`, or `ceil`).
|
|
87
|
+
* @param options Validation options (e.g. allowNegative).
|
|
88
|
+
* @returns Computed tax in integer minor units.
|
|
89
|
+
* @throws {TaxValidationError} if minorUnits is not a safe integer or rate is outside [0, 1].
|
|
90
|
+
* @example applyPercentage(90, 0.35) // 32 (exact statutory satang calculation)
|
|
91
|
+
*/
|
|
92
|
+
export declare function applyPercentage(minorUnits: number, rate: number, rounding?: RoundingMode, options?: ValidateAmountOptions): number;
|
|
93
|
+
/**
|
|
94
|
+
* Standard runner that executes tax calculation on a given TaxSystem instance.
|
|
95
|
+
*
|
|
96
|
+
* @param system TaxSystem implementation.
|
|
97
|
+
* @param input Statutory input parameters.
|
|
98
|
+
* @returns Standardized TaxResult envelope.
|
|
99
|
+
*/
|
|
100
|
+
export declare function calculateTax<TInput, C extends TaxSupportedCurrency, TBreakdown>(system: TaxSystem<TInput, C, TBreakdown>, input: TInput): TaxResult<C, TBreakdown>;
|
|
101
|
+
export { type BracketEvaluationResult, type BracketSlice, type ClampedAmount, type JurisdictionCode, type Money, type RoundingMode, type StatutoryCapOptions, type TaxBracket, type TaxResult, type TaxSupportedCurrency, type TaxSystem, type ValidateAmountOptions, money, thb, usd, validateMonetaryAmount };
|
|
102
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { a as usd, c as roundHalfUp, f as validateMonetaryAmount, i as thb, l as fromMinorUnits, m as TaxValidationError, n as evaluateBrackets, r as money, s as applyPercentage, t as clampCap, u as toMinorUnits } from "./clamp-Bse4u0H-.mjs";
|
|
2
|
+
// src/core/system/runner.ts
|
|
3
|
+
/**
|
|
4
|
+
* Standard runner that executes tax calculation on a given TaxSystem instance.
|
|
5
|
+
*
|
|
6
|
+
* @param system TaxSystem implementation.
|
|
7
|
+
* @param input Statutory input parameters.
|
|
8
|
+
* @returns Standardized TaxResult envelope.
|
|
9
|
+
*/
|
|
10
|
+
function calculateTax(system, input) {
|
|
11
|
+
return system.calculate(input);
|
|
12
|
+
}
|
|
13
|
+
export { TaxValidationError, applyPercentage, calculateTax, clampCap, evaluateBrackets, fromMinorUnits, money, roundHalfUp, thb, toMinorUnits, usd, validateMonetaryAmount };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/core/system/runner.ts"],"sourcesContent":["import type { TaxSupportedCurrency } from \"../money\"\nimport type { TaxResult, TaxSystem } from \"./types\"\n\n/**\n * Standard runner that executes tax calculation on a given TaxSystem instance.\n *\n * @param system TaxSystem implementation.\n * @param input Statutory input parameters.\n * @returns Standardized TaxResult envelope.\n */\nexport function calculateTax<TInput, C extends TaxSupportedCurrency, TBreakdown>(\n\tsystem: TaxSystem<TInput, C, TBreakdown>,\n\tinput: TInput,\n): TaxResult<C, TBreakdown> {\n\treturn system.calculate(input)\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,aACf,QACA,OAC2B;CAC3B,OAAO,OAAO,UAAU,KAAK;AAC9B"}
|