@asteby/metacore-lib 0.7.0 → 0.8.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/README.md +22 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/money.d.ts +181 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +523 -0
- package/dist/money.js.map +1 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -48,6 +48,28 @@ try {
|
|
|
48
48
|
}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
## Money (exact amounts)
|
|
52
|
+
|
|
53
|
+
`@asteby/metacore-lib/money` is the TypeScript twin of the kernel's `money`
|
|
54
|
+
package: integer minor units in `bigint`, explicit rounding modes, no floats.
|
|
55
|
+
Its behaviour is pinned by `src/__fixtures__/money.golden.json`, a byte-for-byte
|
|
56
|
+
copy of the kernel's `money/testdata/golden.json`.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { MoneyValue, formatMoney, inverseRate } from '@asteby/metacore-lib/money'
|
|
60
|
+
|
|
61
|
+
const total = MoneyValue.parse('1899.00', 'MXN') // PrecisionError on '1.005'
|
|
62
|
+
total.mulDecimal('0.16').toString() // "303.84"
|
|
63
|
+
MoneyValue.parse('100.00', 'MXN').allocate([1, 1, 1]).map(String) // ["33.34", "33.33", "33.33"]
|
|
64
|
+
MoneyValue.parse('12.33', 'CHF').roundCash().toString() // "12.35"
|
|
65
|
+
|
|
66
|
+
const usdMxn = { base: 'USD', quote: 'MXN', value: '17.2345' } // MXN per 1 USD
|
|
67
|
+
MoneyValue.parse('100.00', 'USD').convert(usdMxn, 'MXN').toJSON() // { amount: "1723.45", currency_code: "MXN" }
|
|
68
|
+
inverseRate(usdMxn).value // "0.058023151237"
|
|
69
|
+
|
|
70
|
+
formatMoney({ amount: '1000', currency_code: 'JPY' }, { locale: 'en-US' }) // "¥1,000"
|
|
71
|
+
```
|
|
72
|
+
|
|
51
73
|
## Error labels
|
|
52
74
|
|
|
53
75
|
`handleServerError` accepts an injected `toast` so consumers decide the UI binding, and an optional `labels` map for localization.
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { formatNumber, formatPercentage, formatDuration, truncate } from './form
|
|
|
4
4
|
export type { FormatNumberOptions, FormatDurationOptions } from './format';
|
|
5
5
|
export { formatCurrency, getCurrencySymbol, parseCurrency, SPANISH_SYMBOLS, } from './currency';
|
|
6
6
|
export type { CurrencyInfo } from './currency';
|
|
7
|
+
export { MoneyValue, formatMoney, currencySpec, isoCurrencySpec, isoCurrencyCodes, inverseRate, ROUNDING_MODES, INVERSE_SCALE, MoneyError, CurrencyMismatchError, PrecisionError, OverflowError, InvalidMoneyError, } from './money';
|
|
8
|
+
export type { Money, CurrencySpec, RoundingMode, Rate, MoneyErrorCode, FormatMoneyOptions, } from './money';
|
|
7
9
|
export { handleServerError } from './errors';
|
|
8
10
|
export type { ErrorLabels, ToastLike, LoggerLike } from './errors';
|
|
9
11
|
export { HtmlResponseError, HTML_RESPONSE_ERROR_CODE, detectHtmlResponse, isHtmlResponseError, looksLikeHtml, isHtmlContentType, htmlTitle, htmlSnippet, newCorrelationId, } from './http-errors';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,QAAQ,CAAA;AACf,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAE1C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnF,YAAY,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAE1E,OAAO,EACL,cAAc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,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,kBAAkB,GACnB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAElE,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,gBAAgB,GACjB,MAAM,eAAe,CAAA;AACtB,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { formatDate, formatDistance, formatRelative, getAllTimezones, detectTimezone, } from './date';
|
|
2
2
|
export { formatNumber, formatPercentage, formatDuration, truncate } from './format';
|
|
3
3
|
export { formatCurrency, getCurrencySymbol, parseCurrency, SPANISH_SYMBOLS, } from './currency';
|
|
4
|
+
export { MoneyValue, formatMoney, currencySpec, isoCurrencySpec, isoCurrencyCodes, inverseRate, ROUNDING_MODES, INVERSE_SCALE, MoneyError, CurrencyMismatchError, PrecisionError, OverflowError, InvalidMoneyError, } from './money';
|
|
4
5
|
export { handleServerError } from './errors';
|
|
5
6
|
export { HtmlResponseError, HTML_RESPONSE_ERROR_CODE, detectHtmlResponse, isHtmlResponseError, looksLikeHtml, isHtmlContentType, htmlTitle, htmlSnippet, newCorrelationId, } from './http-errors';
|
|
6
7
|
export { showSubmittedData } from './show-submitted-data';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,QAAQ,CAAA;AAGf,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGnF,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,YAAY,CAAA;AAGnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAG5C,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,gBAAgB,GACjB,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,QAAQ,CAAA;AAGf,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGnF,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,YAAY,CAAA;AAGnB,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,aAAa,EACb,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,iBAAiB,GAClB,MAAM,SAAS,CAAA;AAUhB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAG5C,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,gBAAgB,GACjB,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA"}
|
package/dist/money.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exact money for the platform: the TypeScript twin of the kernel `money`
|
|
3
|
+
* package (Go). Amounts live in integer minor units (`bigint`) plus the
|
|
4
|
+
* currency spec; nothing goes through `number`/`parseFloat`.
|
|
5
|
+
*
|
|
6
|
+
* - Wire shape: `Money = { amount: "1899.00", currency_code: "MXN" }`, the
|
|
7
|
+
* same contract as `@asteby/storefront` and the kernel's JSON.
|
|
8
|
+
* - Arithmetic only within one currency (`CurrencyMismatchError`), int64
|
|
9
|
+
* bounds enforced (`OverflowError`), parsing never drops digits
|
|
10
|
+
* (`PrecisionError`) unless you ask for rounding (`parseRound`).
|
|
11
|
+
* - `allocate` uses the largest remainder method: parts always add up to the
|
|
12
|
+
* total, exactly.
|
|
13
|
+
* - Rates are QUOTE units per 1 BASE unit (USD→MXN 17.2345).
|
|
14
|
+
*
|
|
15
|
+
* Behaviour is pinned by `src/__fixtures__/money.golden.json`, a byte-for-byte
|
|
16
|
+
* copy of the kernel's `money/testdata/golden.json` (compared by sha256).
|
|
17
|
+
* Pure: no React, no DOM.
|
|
18
|
+
*/
|
|
19
|
+
/** Wire/JSON money: decimal string amount + ISO 4217 code. */
|
|
20
|
+
export type Money = {
|
|
21
|
+
amount: string;
|
|
22
|
+
currency_code: string;
|
|
23
|
+
};
|
|
24
|
+
/** Currency description used for arithmetic and formatting. */
|
|
25
|
+
export interface CurrencySpec {
|
|
26
|
+
/** ISO 4217 code ("MXN"). */
|
|
27
|
+
code: string;
|
|
28
|
+
/** Decimals of the currency (MXN 2, JPY 0, KWD 3). */
|
|
29
|
+
minorUnits: number;
|
|
30
|
+
/**
|
|
31
|
+
* Cash rounding increment in MINOR units (CHF 5 = 0.05). 0/1/undefined =
|
|
32
|
+
* no cash rounding. Same as the kernel's `Spec.CashIncrementMinor`.
|
|
33
|
+
*/
|
|
34
|
+
cashIncrement?: number;
|
|
35
|
+
/** Where `formatMoney` puts the symbol; omitted = the locale decides. */
|
|
36
|
+
symbolPosition?: 'before' | 'after';
|
|
37
|
+
}
|
|
38
|
+
export type RoundingMode = 'halfAwayFromZero' | 'halfEven' | 'towardZero' | 'awayFromZero' | 'floor' | 'ceil';
|
|
39
|
+
/** All rounding modes, in the kernel's order. `halfAwayFromZero` is the default. */
|
|
40
|
+
export declare const ROUNDING_MODES: readonly RoundingMode[];
|
|
41
|
+
/** Exchange rate: `value` units of `quote` per 1 unit of `base`. */
|
|
42
|
+
export interface Rate {
|
|
43
|
+
id?: string;
|
|
44
|
+
base: string;
|
|
45
|
+
quote: string;
|
|
46
|
+
/** Plain decimal string ("17.2345"). */
|
|
47
|
+
value: string;
|
|
48
|
+
kind?: string;
|
|
49
|
+
/** True when obtained by inverting a stored rate. */
|
|
50
|
+
inverted?: boolean;
|
|
51
|
+
/** True when computed (inverse/cross) instead of read as stored. */
|
|
52
|
+
derived?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export type MoneyErrorCode = 'currency_mismatch' | 'overflow' | 'precision' | 'invalid';
|
|
55
|
+
export declare class MoneyError extends Error {
|
|
56
|
+
readonly code: MoneyErrorCode;
|
|
57
|
+
constructor(code: MoneyErrorCode, message: string);
|
|
58
|
+
}
|
|
59
|
+
/** Two amounts (or an amount and a rate) do not share the currency. */
|
|
60
|
+
export declare class CurrencyMismatchError extends MoneyError {
|
|
61
|
+
constructor(message: string);
|
|
62
|
+
}
|
|
63
|
+
/** The input has more decimals than the currency allows. */
|
|
64
|
+
export declare class PrecisionError extends MoneyError {
|
|
65
|
+
constructor(message: string);
|
|
66
|
+
}
|
|
67
|
+
/** The result does not fit in int64 minor units (same bound as the kernel). */
|
|
68
|
+
export declare class OverflowError extends MoneyError {
|
|
69
|
+
constructor(message: string);
|
|
70
|
+
}
|
|
71
|
+
/** Malformed decimal, unknown currency, bad spec, weights, rate or mode. */
|
|
72
|
+
export declare class InvalidMoneyError extends MoneyError {
|
|
73
|
+
constructor(message: string);
|
|
74
|
+
}
|
|
75
|
+
/** Default scale of derived inverse rates (fx_rates numeric(28,12)). */
|
|
76
|
+
export declare const INVERSE_SCALE = 12;
|
|
77
|
+
/**
|
|
78
|
+
* Validates a plain decimal string and returns its canonical form
|
|
79
|
+
* ("-0.00" → "0.00", "+3" → "3"). Rejects exponents, separators, NaN, double
|
|
80
|
+
* signs and bare dots with `InvalidMoneyError`.
|
|
81
|
+
*/
|
|
82
|
+
export declare function canonicalDecimal(s: string): string;
|
|
83
|
+
/** Exact product of two decimal strings (scale = sum of scales). */
|
|
84
|
+
export declare function decimalMul(a: string, b: string): string;
|
|
85
|
+
/** a / b rounded to `scale` digits with `mode`. */
|
|
86
|
+
export declare function decimalQuo(a: string, b: string, scale: number, mode: RoundingMode): string;
|
|
87
|
+
/** Every ISO code known to the local table, sorted. */
|
|
88
|
+
export declare function isoCurrencyCodes(): string[];
|
|
89
|
+
/**
|
|
90
|
+
* Strict ISO 4217 lookup (case-insensitive): the same table as the kernel's
|
|
91
|
+
* `money.ISO`. Returns `undefined` for codes it does not know.
|
|
92
|
+
*/
|
|
93
|
+
export declare function isoCurrencySpec(code: string): CurrencySpec | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Spec for any currency code: the ISO table first; unknown but well-formed
|
|
96
|
+
* codes fall back to what `Intl` reports (`resolvedOptions().maximumFractionDigits`).
|
|
97
|
+
* Throws `InvalidMoneyError` for malformed codes.
|
|
98
|
+
*/
|
|
99
|
+
export declare function currencySpec(code: string): CurrencySpec;
|
|
100
|
+
/**
|
|
101
|
+
* Immutable exact amount: integer minor units (`bigint`, int64 range) + spec.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const total = MoneyValue.parse('1899.00', 'MXN')
|
|
105
|
+
* const iva = total.mulDecimal('0.16') // 303.84 MXN
|
|
106
|
+
* total.allocate([1, 1, 1]).map(String) // ['633.00', '633.00', '633.00']
|
|
107
|
+
*/
|
|
108
|
+
export declare class MoneyValue {
|
|
109
|
+
readonly minor: bigint;
|
|
110
|
+
readonly spec: CurrencySpec;
|
|
111
|
+
private constructor();
|
|
112
|
+
/** Amount from minor units (`fromMinor(189900n, 'MXN')` = 1899.00). */
|
|
113
|
+
static fromMinor(minor: bigint | number, spec: CurrencySpec | string): MoneyValue;
|
|
114
|
+
static zero(spec: CurrencySpec | string): MoneyValue;
|
|
115
|
+
/**
|
|
116
|
+
* Parses a plain decimal string. `PrecisionError` if it cannot be
|
|
117
|
+
* represented with `minorUnits` decimals (trailing zeros are fine: "10.0"
|
|
118
|
+
* JPY = 10), `OverflowError` outside int64, `InvalidMoneyError` for
|
|
119
|
+
* malformed input or an unknown currency code.
|
|
120
|
+
*/
|
|
121
|
+
static parse(amount: string, spec: CurrencySpec | string): MoneyValue;
|
|
122
|
+
/** Like `parse` but rounds extra decimals with `mode`. */
|
|
123
|
+
static parseRound(amount: string, spec: CurrencySpec | string, mode?: RoundingMode): MoneyValue;
|
|
124
|
+
/**
|
|
125
|
+
* From the wire shape. Without `spec` the currency must be in the ISO table
|
|
126
|
+
* (as in the kernel's UnmarshalJSON); pass a spec for other currencies or to
|
|
127
|
+
* carry an organization's cash rounding.
|
|
128
|
+
*/
|
|
129
|
+
static fromJSON(m: Money, spec?: CurrencySpec): MoneyValue;
|
|
130
|
+
/** ISO code. */
|
|
131
|
+
get currency(): string;
|
|
132
|
+
private same;
|
|
133
|
+
private with;
|
|
134
|
+
add(o: MoneyValue): MoneyValue;
|
|
135
|
+
sub(o: MoneyValue): MoneyValue;
|
|
136
|
+
neg(): MoneyValue;
|
|
137
|
+
/** -1, 0 or 1. */
|
|
138
|
+
cmp(o: MoneyValue): number;
|
|
139
|
+
equals(o: MoneyValue): boolean;
|
|
140
|
+
sign(): -1 | 0 | 1;
|
|
141
|
+
isZero(): boolean;
|
|
142
|
+
/** this × factor (decimal string), rounded to minor units. */
|
|
143
|
+
mulDecimal(factor: string, mode?: RoundingMode): MoneyValue;
|
|
144
|
+
/**
|
|
145
|
+
* Largest remainder split: parts add up to this amount exactly; leftover
|
|
146
|
+
* minor units go to the largest remainders, ties to the earliest index.
|
|
147
|
+
* Weights: non-negative integers, not all zero.
|
|
148
|
+
*/
|
|
149
|
+
allocate(weights: ReadonlyArray<number | bigint>): MoneyValue[];
|
|
150
|
+
/** Rounds to the spec's cash increment (CHF: 12.32 → 12.30, 12.33 → 12.35). */
|
|
151
|
+
roundCash(mode?: RoundingMode): MoneyValue;
|
|
152
|
+
/**
|
|
153
|
+
* Converts to `to` with `rate` (rate.base must be this currency and
|
|
154
|
+
* rate.quote the target, else `CurrencyMismatchError`).
|
|
155
|
+
*/
|
|
156
|
+
convert(rate: Rate, to: CurrencySpec | string, mode?: RoundingMode): MoneyValue;
|
|
157
|
+
/** Canonical amount with exactly `minorUnits` decimals: "1899.00", "1000" (JPY). */
|
|
158
|
+
toString(): string;
|
|
159
|
+
toJSON(): Money;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Inverse of a rate (quote→base): 1/value at `scale` digits with halfEven,
|
|
163
|
+
* marked `derived` and with `inverted` flipped.
|
|
164
|
+
*/
|
|
165
|
+
export declare function inverseRate(rate: Rate, scale?: number): Rate;
|
|
166
|
+
export interface FormatMoneyOptions {
|
|
167
|
+
/** BCP 47 locale (default 'es', like `formatCurrency`). */
|
|
168
|
+
locale?: string;
|
|
169
|
+
/** Overrides the spec resolved with `currencySpec(currency_code)`. */
|
|
170
|
+
spec?: CurrencySpec;
|
|
171
|
+
/** Intl `currencyDisplay` (default 'symbol'). */
|
|
172
|
+
display?: 'symbol' | 'narrowSymbol' | 'code' | 'name';
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Formats money with `Intl.NumberFormat`, using exactly `spec.minorUnits`
|
|
176
|
+
* fraction digits and passing the decimal STRING to Intl (no parseFloat, so
|
|
177
|
+
* 1e12 VES or 0.1 + 0.2 never lose digits). Returns '' for a malformed amount
|
|
178
|
+
* and `"<amount> <code>"` if Intl rejects the currency.
|
|
179
|
+
*/
|
|
180
|
+
export declare function formatMoney(m: Money | MoneyValue, options?: FormatMoneyOptions): string;
|
|
181
|
+
//# sourceMappingURL=money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../src/money.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,8DAA8D;AAC9D,MAAM,MAAM,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAA;AAE7D,+DAA+D;AAC/D,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,yEAAyE;IACzE,cAAc,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;CACpC;AAED,MAAM,MAAM,YAAY,GACpB,kBAAkB,GAClB,UAAU,GACV,YAAY,GACZ,cAAc,GACd,OAAO,GACP,MAAM,CAAA;AAEV,oFAAoF;AACpF,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAOjD,CAAA;AAED,oEAAoE;AACpE,MAAM,WAAW,IAAI;IACnB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,oEAAoE;IACpE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAID,MAAM,MAAM,cAAc,GAAG,mBAAmB,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAA;AAEvF,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;gBACjB,I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AAG,UAAU;IAgBnG,oFAAoF;IACpF,QAAQ,IAAI,MAAM;IAIlB,MAAM,IAAI,KAAK;CAGhB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,GAAE,MAAsB,GAAG,IAAI,CAS3E;AAID,MAAM,WAAW,kBAAkB;IACjC,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,sEAAsE;IACtE,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB,iDAAiD;IACjD,OAAO,CAAC,EAAE,QAAQ,GAAG,cAAc,GAAG,MAAM,GAAG,MAAM,CAAA;CACtD;AAOD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,UAAU,EAAE,OAAO,GAAE,kBAAuB,GAAG,MAAM,CA4B3F"}
|
package/dist/money.js
ADDED
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exact money for the platform: the TypeScript twin of the kernel `money`
|
|
3
|
+
* package (Go). Amounts live in integer minor units (`bigint`) plus the
|
|
4
|
+
* currency spec; nothing goes through `number`/`parseFloat`.
|
|
5
|
+
*
|
|
6
|
+
* - Wire shape: `Money = { amount: "1899.00", currency_code: "MXN" }`, the
|
|
7
|
+
* same contract as `@asteby/storefront` and the kernel's JSON.
|
|
8
|
+
* - Arithmetic only within one currency (`CurrencyMismatchError`), int64
|
|
9
|
+
* bounds enforced (`OverflowError`), parsing never drops digits
|
|
10
|
+
* (`PrecisionError`) unless you ask for rounding (`parseRound`).
|
|
11
|
+
* - `allocate` uses the largest remainder method: parts always add up to the
|
|
12
|
+
* total, exactly.
|
|
13
|
+
* - Rates are QUOTE units per 1 BASE unit (USD→MXN 17.2345).
|
|
14
|
+
*
|
|
15
|
+
* Behaviour is pinned by `src/__fixtures__/money.golden.json`, a byte-for-byte
|
|
16
|
+
* copy of the kernel's `money/testdata/golden.json` (compared by sha256).
|
|
17
|
+
* Pure: no React, no DOM.
|
|
18
|
+
*/
|
|
19
|
+
/** All rounding modes, in the kernel's order. `halfAwayFromZero` is the default. */
|
|
20
|
+
export const ROUNDING_MODES = [
|
|
21
|
+
'halfAwayFromZero',
|
|
22
|
+
'halfEven',
|
|
23
|
+
'towardZero',
|
|
24
|
+
'awayFromZero',
|
|
25
|
+
'floor',
|
|
26
|
+
'ceil',
|
|
27
|
+
];
|
|
28
|
+
export class MoneyError extends Error {
|
|
29
|
+
code;
|
|
30
|
+
constructor(code, message) {
|
|
31
|
+
super(`money: ${message}`);
|
|
32
|
+
this.name = 'MoneyError';
|
|
33
|
+
this.code = code;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Two amounts (or an amount and a rate) do not share the currency. */
|
|
37
|
+
export class CurrencyMismatchError extends MoneyError {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super('currency_mismatch', message);
|
|
40
|
+
this.name = 'CurrencyMismatchError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The input has more decimals than the currency allows. */
|
|
44
|
+
export class PrecisionError extends MoneyError {
|
|
45
|
+
constructor(message) {
|
|
46
|
+
super('precision', message);
|
|
47
|
+
this.name = 'PrecisionError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** The result does not fit in int64 minor units (same bound as the kernel). */
|
|
51
|
+
export class OverflowError extends MoneyError {
|
|
52
|
+
constructor(message) {
|
|
53
|
+
super('overflow', message);
|
|
54
|
+
this.name = 'OverflowError';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Malformed decimal, unknown currency, bad spec, weights, rate or mode. */
|
|
58
|
+
export class InvalidMoneyError extends MoneyError {
|
|
59
|
+
constructor(message) {
|
|
60
|
+
super('invalid', message);
|
|
61
|
+
this.name = 'InvalidMoneyError';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// --------------------------------------------------------------- decimals
|
|
65
|
+
const INT64_MIN = -(1n << 63n);
|
|
66
|
+
const INT64_MAX = (1n << 63n) - 1n;
|
|
67
|
+
const UINT64_LIMIT = 1n << 64n;
|
|
68
|
+
const MAX_DECIMAL_LEN = 256;
|
|
69
|
+
const MAX_SCALE = 64;
|
|
70
|
+
const MAX_MINOR_UNITS = 18;
|
|
71
|
+
const DECIMAL_RE = /^[+-]?[0-9]+(?:\.[0-9]+)?$/;
|
|
72
|
+
/** Default scale of derived inverse rates (fx_rates numeric(28,12)). */
|
|
73
|
+
export const INVERSE_SCALE = 12;
|
|
74
|
+
function pow10(n) {
|
|
75
|
+
return 10n ** BigInt(n);
|
|
76
|
+
}
|
|
77
|
+
function parseDec(s) {
|
|
78
|
+
if (typeof s !== 'string' || s.length === 0 || s.length > MAX_DECIMAL_LEN || !DECIMAL_RE.test(s)) {
|
|
79
|
+
throw new InvalidMoneyError(`decimal ${JSON.stringify(truncate(String(s)))}: not a plain decimal`);
|
|
80
|
+
}
|
|
81
|
+
const dot = s.indexOf('.');
|
|
82
|
+
const frac = dot < 0 ? '' : s.slice(dot + 1);
|
|
83
|
+
const digits = (dot < 0 ? s : s.slice(0, dot)).replace(/^[+-]/, '') + frac;
|
|
84
|
+
const coef = BigInt(digits);
|
|
85
|
+
return { coef: s.startsWith('-') ? -coef : coef, scale: frac.length };
|
|
86
|
+
}
|
|
87
|
+
function truncate(s) {
|
|
88
|
+
return s.length > 32 ? `${s.slice(0, 32)}…` : s;
|
|
89
|
+
}
|
|
90
|
+
function formatScaled(coef, scale) {
|
|
91
|
+
const neg = coef < 0n;
|
|
92
|
+
let digits = (neg ? -coef : coef).toString();
|
|
93
|
+
if (scale > 0) {
|
|
94
|
+
if (digits.length <= scale)
|
|
95
|
+
digits = '0'.repeat(scale - digits.length + 1) + digits;
|
|
96
|
+
digits = `${digits.slice(0, digits.length - scale)}.${digits.slice(digits.length - scale)}`;
|
|
97
|
+
}
|
|
98
|
+
return neg ? `-${digits}` : digits;
|
|
99
|
+
}
|
|
100
|
+
function checkMode(mode) {
|
|
101
|
+
if (!ROUNDING_MODES.includes(mode)) {
|
|
102
|
+
throw new InvalidMoneyError(`unknown rounding mode ${JSON.stringify(mode)}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function checkScale(scale) {
|
|
106
|
+
if (!Number.isInteger(scale) || scale < 0 || scale > MAX_SCALE) {
|
|
107
|
+
throw new InvalidMoneyError(`scale ${scale} out of range`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** num/den rounded to an integer with mode (den ≠ 0). */
|
|
111
|
+
function divRound(num, den, mode) {
|
|
112
|
+
const q = num / den; // truncates toward zero
|
|
113
|
+
const r = num % den;
|
|
114
|
+
if (r === 0n)
|
|
115
|
+
return q;
|
|
116
|
+
const sign = (num < 0n) !== (den < 0n) ? -1n : 1n;
|
|
117
|
+
let up;
|
|
118
|
+
switch (mode) {
|
|
119
|
+
case 'towardZero':
|
|
120
|
+
up = false;
|
|
121
|
+
break;
|
|
122
|
+
case 'awayFromZero':
|
|
123
|
+
up = true;
|
|
124
|
+
break;
|
|
125
|
+
case 'floor':
|
|
126
|
+
up = sign < 0n;
|
|
127
|
+
break;
|
|
128
|
+
case 'ceil':
|
|
129
|
+
up = sign > 0n;
|
|
130
|
+
break;
|
|
131
|
+
default: {
|
|
132
|
+
const r2 = (r < 0n ? -r : r) * 2n;
|
|
133
|
+
const d = den < 0n ? -den : den;
|
|
134
|
+
up = r2 > d || (r2 === d && (mode === 'halfAwayFromZero' || q % 2n !== 0n));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return up ? q + sign : q;
|
|
138
|
+
}
|
|
139
|
+
function roundDec(d, scale, mode) {
|
|
140
|
+
if (scale >= d.scale)
|
|
141
|
+
return { coef: d.coef * pow10(scale - d.scale), scale };
|
|
142
|
+
return { coef: divRound(d.coef, pow10(d.scale - scale), mode), scale };
|
|
143
|
+
}
|
|
144
|
+
function cmpDec(a, b) {
|
|
145
|
+
let x = a.coef;
|
|
146
|
+
let y = b.coef;
|
|
147
|
+
if (a.scale < b.scale)
|
|
148
|
+
x *= pow10(b.scale - a.scale);
|
|
149
|
+
else if (a.scale > b.scale)
|
|
150
|
+
y *= pow10(a.scale - b.scale);
|
|
151
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Validates a plain decimal string and returns its canonical form
|
|
155
|
+
* ("-0.00" → "0.00", "+3" → "3"). Rejects exponents, separators, NaN, double
|
|
156
|
+
* signs and bare dots with `InvalidMoneyError`.
|
|
157
|
+
*/
|
|
158
|
+
export function canonicalDecimal(s) {
|
|
159
|
+
const d = parseDec(s);
|
|
160
|
+
return formatScaled(d.coef, d.scale);
|
|
161
|
+
}
|
|
162
|
+
/** Exact product of two decimal strings (scale = sum of scales). */
|
|
163
|
+
export function decimalMul(a, b) {
|
|
164
|
+
const x = parseDec(a);
|
|
165
|
+
const y = parseDec(b);
|
|
166
|
+
return formatScaled(x.coef * y.coef, x.scale + y.scale);
|
|
167
|
+
}
|
|
168
|
+
/** a / b rounded to `scale` digits with `mode`. */
|
|
169
|
+
export function decimalQuo(a, b, scale, mode) {
|
|
170
|
+
const x = parseDec(a);
|
|
171
|
+
const y = parseDec(b);
|
|
172
|
+
if (y.coef === 0n)
|
|
173
|
+
throw new InvalidMoneyError('division by zero');
|
|
174
|
+
checkScale(scale);
|
|
175
|
+
checkMode(mode);
|
|
176
|
+
const num = x.coef * pow10(y.scale + scale);
|
|
177
|
+
const den = y.coef * pow10(x.scale);
|
|
178
|
+
return formatScaled(divRound(num, den, mode), scale);
|
|
179
|
+
}
|
|
180
|
+
// ------------------------------------------------------------- ISO 4217
|
|
181
|
+
// ISO 4217 list one (active codes) → minor units. Keep identical to the
|
|
182
|
+
// kernel (money/iso.go) and to the "iso" section of the golden file.
|
|
183
|
+
const ISO_MINOR_UNITS = Object.freeze(Object.fromEntries(('AED2 AFN2 ALL2 AMD2 ANG2 AOA2 ARS2 AUD2 AWG2 AZN2 BAM2 BBD2 BDT2 BGN2 BHD3 BIF0 ' +
|
|
184
|
+
'BMD2 BND2 BOB2 BOV2 BRL2 BSD2 BTN2 BWP2 BYN2 BZD2 CAD2 CDF2 CHE2 CHF2 CHW2 CLF4 ' +
|
|
185
|
+
'CLP0 CNY2 COP2 COU2 CRC2 CUC2 CUP2 CVE2 CZK2 DJF0 DKK2 DOP2 DZD2 EGP2 ERN2 ETB2 ' +
|
|
186
|
+
'EUR2 FJD2 FKP2 GBP2 GEL2 GHS2 GIP2 GMD2 GNF0 GTQ2 GYD2 HKD2 HNL2 HTG2 HUF2 IDR2 ' +
|
|
187
|
+
'ILS2 INR2 IQD3 IRR2 ISK0 JMD2 JOD3 JPY0 KES2 KGS2 KHR2 KMF0 KPW2 KRW0 KWD3 KYD2 ' +
|
|
188
|
+
'KZT2 LAK2 LBP2 LKR2 LRD2 LSL2 LYD3 MAD2 MDL2 MGA2 MKD2 MMK2 MNT2 MOP2 MRU2 MUR2 ' +
|
|
189
|
+
'MVR2 MWK2 MXN2 MXV2 MYR2 MZN2 NAD2 NGN2 NIO2 NOK2 NPR2 NZD2 OMR3 PAB2 PEN2 PGK2 ' +
|
|
190
|
+
'PHP2 PKR2 PLN2 PYG0 QAR2 RON2 RSD2 RUB2 RWF0 SAR2 SBD2 SCR2 SDG2 SEK2 SGD2 SHP2 ' +
|
|
191
|
+
'SLE2 SLL2 SOS2 SRD2 SSP2 STN2 SVC2 SYP2 SZL2 THB2 TJS2 TMT2 TND3 TOP2 TRY2 TTD2 ' +
|
|
192
|
+
'TWD2 TZS2 UAH2 UGX0 USD2 USN2 UYI0 UYU2 UYW4 UZS2 VED2 VES2 VND0 VUV0 WST2 XAF0 ' +
|
|
193
|
+
'XCD2 XCG2 XOF0 XPF0 YER2 ZAR2 ZMW2 ZWG2 ZWL2')
|
|
194
|
+
.split(' ')
|
|
195
|
+
.map((e) => [e.slice(0, 3), Number(e.slice(3))])));
|
|
196
|
+
// Default cash rounding increments in minor units (CLDR); orgs may override.
|
|
197
|
+
const CASH_INCREMENTS = Object.freeze({
|
|
198
|
+
CHF: 5,
|
|
199
|
+
CAD: 5,
|
|
200
|
+
DKK: 50,
|
|
201
|
+
SEK: 100,
|
|
202
|
+
NOK: 100,
|
|
203
|
+
CZK: 100,
|
|
204
|
+
HUF: 100,
|
|
205
|
+
});
|
|
206
|
+
/** Every ISO code known to the local table, sorted. */
|
|
207
|
+
export function isoCurrencyCodes() {
|
|
208
|
+
return Object.keys(ISO_MINOR_UNITS).sort();
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Strict ISO 4217 lookup (case-insensitive): the same table as the kernel's
|
|
212
|
+
* `money.ISO`. Returns `undefined` for codes it does not know.
|
|
213
|
+
*/
|
|
214
|
+
export function isoCurrencySpec(code) {
|
|
215
|
+
const c = String(code).trim().toUpperCase();
|
|
216
|
+
const minorUnits = ISO_MINOR_UNITS[c];
|
|
217
|
+
if (minorUnits === undefined)
|
|
218
|
+
return undefined;
|
|
219
|
+
const spec = { code: c, minorUnits };
|
|
220
|
+
const cash = CASH_INCREMENTS[c];
|
|
221
|
+
if (cash)
|
|
222
|
+
spec.cashIncrement = cash;
|
|
223
|
+
return spec;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Spec for any currency code: the ISO table first; unknown but well-formed
|
|
227
|
+
* codes fall back to what `Intl` reports (`resolvedOptions().maximumFractionDigits`).
|
|
228
|
+
* Throws `InvalidMoneyError` for malformed codes.
|
|
229
|
+
*/
|
|
230
|
+
export function currencySpec(code) {
|
|
231
|
+
const iso = isoCurrencySpec(code);
|
|
232
|
+
if (iso)
|
|
233
|
+
return iso;
|
|
234
|
+
const c = String(code).trim().toUpperCase();
|
|
235
|
+
if (!/^[A-Z]{3}$/.test(c))
|
|
236
|
+
throw new InvalidMoneyError(`currency code ${JSON.stringify(code)}`);
|
|
237
|
+
let minorUnits = 2;
|
|
238
|
+
try {
|
|
239
|
+
const digits = new Intl.NumberFormat('en', { style: 'currency', currency: c }).resolvedOptions()
|
|
240
|
+
.maximumFractionDigits;
|
|
241
|
+
if (typeof digits === 'number')
|
|
242
|
+
minorUnits = digits;
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
// keep 2
|
|
246
|
+
}
|
|
247
|
+
return { code: c, minorUnits };
|
|
248
|
+
}
|
|
249
|
+
function validateSpec(spec) {
|
|
250
|
+
if (!spec || typeof spec.code !== 'string' || spec.code === '') {
|
|
251
|
+
throw new InvalidMoneyError('empty currency code');
|
|
252
|
+
}
|
|
253
|
+
if (!Number.isInteger(spec.minorUnits) || spec.minorUnits < 0 || spec.minorUnits > MAX_MINOR_UNITS) {
|
|
254
|
+
throw new InvalidMoneyError(`${spec.code} minor units ${spec.minorUnits} out of range`);
|
|
255
|
+
}
|
|
256
|
+
if (spec.cashIncrement !== undefined && (!Number.isSafeInteger(spec.cashIncrement) || spec.cashIncrement < 0)) {
|
|
257
|
+
throw new InvalidMoneyError(`${spec.code} cash increment ${spec.cashIncrement}`);
|
|
258
|
+
}
|
|
259
|
+
return spec;
|
|
260
|
+
}
|
|
261
|
+
/** A string spec is resolved strictly (ISO table); pass an object for other currencies. */
|
|
262
|
+
function resolveSpec(spec) {
|
|
263
|
+
if (typeof spec === 'string') {
|
|
264
|
+
const iso = isoCurrencySpec(spec);
|
|
265
|
+
if (!iso)
|
|
266
|
+
throw new InvalidMoneyError(`unknown currency ${JSON.stringify(spec)}`);
|
|
267
|
+
return iso;
|
|
268
|
+
}
|
|
269
|
+
return validateSpec(spec);
|
|
270
|
+
}
|
|
271
|
+
function fit(minor, code) {
|
|
272
|
+
if (minor < INT64_MIN || minor > INT64_MAX) {
|
|
273
|
+
throw new OverflowError(`${truncate(minor.toString())} minor units of ${code}`);
|
|
274
|
+
}
|
|
275
|
+
return minor;
|
|
276
|
+
}
|
|
277
|
+
// ----------------------------------------------------------------- money
|
|
278
|
+
/**
|
|
279
|
+
* Immutable exact amount: integer minor units (`bigint`, int64 range) + spec.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* const total = MoneyValue.parse('1899.00', 'MXN')
|
|
283
|
+
* const iva = total.mulDecimal('0.16') // 303.84 MXN
|
|
284
|
+
* total.allocate([1, 1, 1]).map(String) // ['633.00', '633.00', '633.00']
|
|
285
|
+
*/
|
|
286
|
+
export class MoneyValue {
|
|
287
|
+
minor;
|
|
288
|
+
spec;
|
|
289
|
+
constructor(minor, spec) {
|
|
290
|
+
this.minor = minor;
|
|
291
|
+
this.spec = spec;
|
|
292
|
+
Object.freeze(this);
|
|
293
|
+
}
|
|
294
|
+
/** Amount from minor units (`fromMinor(189900n, 'MXN')` = 1899.00). */
|
|
295
|
+
static fromMinor(minor, spec) {
|
|
296
|
+
const s = resolveSpec(spec);
|
|
297
|
+
if (typeof minor === 'number' && !Number.isSafeInteger(minor)) {
|
|
298
|
+
throw new InvalidMoneyError(`minor units ${minor} is not a safe integer`);
|
|
299
|
+
}
|
|
300
|
+
return new MoneyValue(fit(BigInt(minor), s.code), s);
|
|
301
|
+
}
|
|
302
|
+
static zero(spec) {
|
|
303
|
+
return new MoneyValue(0n, resolveSpec(spec));
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Parses a plain decimal string. `PrecisionError` if it cannot be
|
|
307
|
+
* represented with `minorUnits` decimals (trailing zeros are fine: "10.0"
|
|
308
|
+
* JPY = 10), `OverflowError` outside int64, `InvalidMoneyError` for
|
|
309
|
+
* malformed input or an unknown currency code.
|
|
310
|
+
*/
|
|
311
|
+
static parse(amount, spec) {
|
|
312
|
+
const s = resolveSpec(spec);
|
|
313
|
+
const d = parseDec(amount);
|
|
314
|
+
const r = roundDec(d, s.minorUnits, 'towardZero');
|
|
315
|
+
if (cmpDec(r, d) !== 0) {
|
|
316
|
+
throw new PrecisionError(`${truncate(amount)} has more than ${s.minorUnits} decimals for ${s.code}`);
|
|
317
|
+
}
|
|
318
|
+
return new MoneyValue(fit(r.coef, s.code), s);
|
|
319
|
+
}
|
|
320
|
+
/** Like `parse` but rounds extra decimals with `mode`. */
|
|
321
|
+
static parseRound(amount, spec, mode = 'halfAwayFromZero') {
|
|
322
|
+
const s = resolveSpec(spec);
|
|
323
|
+
checkMode(mode);
|
|
324
|
+
const r = roundDec(parseDec(amount), s.minorUnits, mode);
|
|
325
|
+
return new MoneyValue(fit(r.coef, s.code), s);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* From the wire shape. Without `spec` the currency must be in the ISO table
|
|
329
|
+
* (as in the kernel's UnmarshalJSON); pass a spec for other currencies or to
|
|
330
|
+
* carry an organization's cash rounding.
|
|
331
|
+
*/
|
|
332
|
+
static fromJSON(m, spec) {
|
|
333
|
+
if (!m || typeof m.amount !== 'string' || typeof m.currency_code !== 'string') {
|
|
334
|
+
throw new InvalidMoneyError('money must be {amount: string, currency_code: string}');
|
|
335
|
+
}
|
|
336
|
+
if (spec && spec.code !== m.currency_code) {
|
|
337
|
+
throw new CurrencyMismatchError(`${m.currency_code} vs spec ${spec.code}`);
|
|
338
|
+
}
|
|
339
|
+
return MoneyValue.parse(m.amount, spec ?? m.currency_code);
|
|
340
|
+
}
|
|
341
|
+
/** ISO code. */
|
|
342
|
+
get currency() {
|
|
343
|
+
return this.spec.code;
|
|
344
|
+
}
|
|
345
|
+
same(o) {
|
|
346
|
+
if (o.spec.code !== this.spec.code || o.spec.minorUnits !== this.spec.minorUnits) {
|
|
347
|
+
throw new CurrencyMismatchError(`${this.spec.code}(${this.spec.minorUnits}) vs ${o.spec.code}(${o.spec.minorUnits})`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
with(minor) {
|
|
351
|
+
return new MoneyValue(fit(minor, this.spec.code), this.spec);
|
|
352
|
+
}
|
|
353
|
+
add(o) {
|
|
354
|
+
this.same(o);
|
|
355
|
+
return this.with(this.minor + o.minor);
|
|
356
|
+
}
|
|
357
|
+
sub(o) {
|
|
358
|
+
this.same(o);
|
|
359
|
+
return this.with(this.minor - o.minor);
|
|
360
|
+
}
|
|
361
|
+
neg() {
|
|
362
|
+
return this.with(-this.minor);
|
|
363
|
+
}
|
|
364
|
+
/** -1, 0 or 1. */
|
|
365
|
+
cmp(o) {
|
|
366
|
+
this.same(o);
|
|
367
|
+
return this.minor < o.minor ? -1 : this.minor > o.minor ? 1 : 0;
|
|
368
|
+
}
|
|
369
|
+
equals(o) {
|
|
370
|
+
return o.spec.code === this.spec.code && o.spec.minorUnits === this.spec.minorUnits && o.minor === this.minor;
|
|
371
|
+
}
|
|
372
|
+
sign() {
|
|
373
|
+
return this.minor < 0n ? -1 : this.minor > 0n ? 1 : 0;
|
|
374
|
+
}
|
|
375
|
+
isZero() {
|
|
376
|
+
return this.minor === 0n;
|
|
377
|
+
}
|
|
378
|
+
/** this × factor (decimal string), rounded to minor units. */
|
|
379
|
+
mulDecimal(factor, mode = 'halfAwayFromZero') {
|
|
380
|
+
checkMode(mode);
|
|
381
|
+
const d = parseDec(factor);
|
|
382
|
+
return this.with(divRound(this.minor * d.coef, pow10(d.scale), mode));
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Largest remainder split: parts add up to this amount exactly; leftover
|
|
386
|
+
* minor units go to the largest remainders, ties to the earliest index.
|
|
387
|
+
* Weights: non-negative integers, not all zero.
|
|
388
|
+
*/
|
|
389
|
+
allocate(weights) {
|
|
390
|
+
if (weights.length === 0)
|
|
391
|
+
throw new InvalidMoneyError('allocate needs at least one weight');
|
|
392
|
+
const ws = weights.map((w) => {
|
|
393
|
+
if (typeof w === 'number' && !Number.isSafeInteger(w)) {
|
|
394
|
+
throw new InvalidMoneyError(`weight ${w} is not an integer`);
|
|
395
|
+
}
|
|
396
|
+
const b = BigInt(w);
|
|
397
|
+
if (b < 0n)
|
|
398
|
+
throw new InvalidMoneyError(`negative weight ${b}`);
|
|
399
|
+
if (b > INT64_MAX)
|
|
400
|
+
throw new InvalidMoneyError(`weight ${b} out of range`);
|
|
401
|
+
return b;
|
|
402
|
+
});
|
|
403
|
+
const total = ws.reduce((a, b) => a + b, 0n);
|
|
404
|
+
if (total >= UINT64_LIMIT)
|
|
405
|
+
throw new OverflowError('sum of weights');
|
|
406
|
+
if (total === 0n)
|
|
407
|
+
throw new InvalidMoneyError('all weights are zero');
|
|
408
|
+
const abs = this.minor < 0n ? -this.minor : this.minor;
|
|
409
|
+
const quotas = ws.map((w) => (abs * w) / total);
|
|
410
|
+
const rems = ws.map((w) => (abs * w) % total);
|
|
411
|
+
let left = abs - quotas.reduce((a, b) => a + b, 0n);
|
|
412
|
+
const order = ws.map((_, i) => i).sort((a, b) => {
|
|
413
|
+
const ra = rems[a];
|
|
414
|
+
const rb = rems[b];
|
|
415
|
+
return ra === rb ? a - b : ra > rb ? -1 : 1;
|
|
416
|
+
});
|
|
417
|
+
for (let k = 0; left > 0n; k++, left--) {
|
|
418
|
+
const i = order[k];
|
|
419
|
+
quotas[i] = quotas[i] + 1n;
|
|
420
|
+
}
|
|
421
|
+
return quotas.map((q) => this.with(this.minor < 0n ? -q : q));
|
|
422
|
+
}
|
|
423
|
+
/** Rounds to the spec's cash increment (CHF: 12.32 → 12.30, 12.33 → 12.35). */
|
|
424
|
+
roundCash(mode = 'halfAwayFromZero') {
|
|
425
|
+
checkMode(mode);
|
|
426
|
+
const inc = BigInt(this.spec.cashIncrement ?? 0);
|
|
427
|
+
if (inc <= 1n)
|
|
428
|
+
return this;
|
|
429
|
+
return this.with(divRound(this.minor, inc, mode) * inc);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Converts to `to` with `rate` (rate.base must be this currency and
|
|
433
|
+
* rate.quote the target, else `CurrencyMismatchError`).
|
|
434
|
+
*/
|
|
435
|
+
convert(rate, to, mode = 'halfAwayFromZero') {
|
|
436
|
+
const target = resolveSpec(to);
|
|
437
|
+
checkMode(mode);
|
|
438
|
+
const v = parseDec(rate.value);
|
|
439
|
+
if (v.coef <= 0n)
|
|
440
|
+
throw new InvalidMoneyError(`rate ${rate.base}/${rate.quote} must be > 0`);
|
|
441
|
+
if (rate.base !== this.spec.code) {
|
|
442
|
+
throw new CurrencyMismatchError(`amount in ${this.spec.code}, rate base ${rate.base}`);
|
|
443
|
+
}
|
|
444
|
+
if (rate.quote !== target.code) {
|
|
445
|
+
throw new CurrencyMismatchError(`target ${target.code}, rate quote ${rate.quote}`);
|
|
446
|
+
}
|
|
447
|
+
const num = this.minor * v.coef * pow10(target.minorUnits);
|
|
448
|
+
const den = pow10(v.scale + this.spec.minorUnits);
|
|
449
|
+
return new MoneyValue(fit(divRound(num, den, mode), target.code), target);
|
|
450
|
+
}
|
|
451
|
+
/** Canonical amount with exactly `minorUnits` decimals: "1899.00", "1000" (JPY). */
|
|
452
|
+
toString() {
|
|
453
|
+
return formatScaled(this.minor, this.spec.minorUnits);
|
|
454
|
+
}
|
|
455
|
+
toJSON() {
|
|
456
|
+
return { amount: this.toString(), currency_code: this.spec.code };
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Inverse of a rate (quote→base): 1/value at `scale` digits with halfEven,
|
|
461
|
+
* marked `derived` and with `inverted` flipped.
|
|
462
|
+
*/
|
|
463
|
+
export function inverseRate(rate, scale = INVERSE_SCALE) {
|
|
464
|
+
const v = parseDec(rate.value);
|
|
465
|
+
if (v.coef <= 0n)
|
|
466
|
+
throw new InvalidMoneyError(`rate ${rate.base}/${rate.quote} must be > 0`);
|
|
467
|
+
const inv = decimalQuo('1', rate.value, scale, 'halfEven');
|
|
468
|
+
if (parseDec(inv).coef === 0n) {
|
|
469
|
+
throw new PrecisionError(`inverse of ${rate.value} rounds to 0 at scale ${scale}`);
|
|
470
|
+
}
|
|
471
|
+
const out = { ...rate, base: rate.quote, quote: rate.base, value: inv, inverted: !rate.inverted, derived: true };
|
|
472
|
+
return out;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Formats money with `Intl.NumberFormat`, using exactly `spec.minorUnits`
|
|
476
|
+
* fraction digits and passing the decimal STRING to Intl (no parseFloat, so
|
|
477
|
+
* 1e12 VES or 0.1 + 0.2 never lose digits). Returns '' for a malformed amount
|
|
478
|
+
* and `"<amount> <code>"` if Intl rejects the currency.
|
|
479
|
+
*/
|
|
480
|
+
export function formatMoney(m, options = {}) {
|
|
481
|
+
const json = m instanceof MoneyValue ? m.toJSON() : m;
|
|
482
|
+
let amount;
|
|
483
|
+
try {
|
|
484
|
+
amount = canonicalDecimal(json.amount);
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
return '';
|
|
488
|
+
}
|
|
489
|
+
const code = json.currency_code;
|
|
490
|
+
let spec;
|
|
491
|
+
try {
|
|
492
|
+
spec = options.spec ?? currencySpec(code);
|
|
493
|
+
}
|
|
494
|
+
catch {
|
|
495
|
+
return `${amount} ${code}`;
|
|
496
|
+
}
|
|
497
|
+
try {
|
|
498
|
+
const nf = new Intl.NumberFormat(options.locale ?? 'es', {
|
|
499
|
+
style: 'currency',
|
|
500
|
+
currency: code,
|
|
501
|
+
currencyDisplay: options.display ?? 'symbol',
|
|
502
|
+
minimumFractionDigits: spec.minorUnits,
|
|
503
|
+
maximumFractionDigits: spec.minorUnits,
|
|
504
|
+
});
|
|
505
|
+
if (!spec.symbolPosition)
|
|
506
|
+
return nf.format(amount);
|
|
507
|
+
return placeSymbol(nf.formatToParts(amount), spec.symbolPosition);
|
|
508
|
+
}
|
|
509
|
+
catch {
|
|
510
|
+
return `${amount} ${code}`;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function placeSymbol(parts, position) {
|
|
514
|
+
const symbol = parts.find((p) => p.type === 'currency')?.value ?? '';
|
|
515
|
+
const sign = parts.filter((p) => p.type === 'minusSign' || p.type === 'plusSign').map((p) => p.value).join('');
|
|
516
|
+
const number = parts
|
|
517
|
+
.filter((p) => p.type !== 'currency' && p.type !== 'minusSign' && p.type !== 'plusSign')
|
|
518
|
+
.map((p) => p.value)
|
|
519
|
+
.join('')
|
|
520
|
+
.trim();
|
|
521
|
+
return position === 'before' ? `${sign}${symbol}${number}` : `${sign}${number} ${symbol}`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,WAAW,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC9G,MAAM,MAAM,GAAG,KAAK;SACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;SACvF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;SACnB,IAAI,CAAC,EAAE,CAAC;SACR,IAAI,EAAE,CAAA;IACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM,IAAI,MAAM,EAAE,CAAA;AAC3F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asteby/metacore-lib",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Metacore utilities — date/currency/number formatting, error handling, cookies",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "Metacore utilities — exact money, date/currency/number formatting, error handling, cookies",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"types": "./dist/currency.d.ts",
|
|
33
33
|
"import": "./dist/currency.js"
|
|
34
34
|
},
|
|
35
|
+
"./money": {
|
|
36
|
+
"types": "./dist/money.d.ts",
|
|
37
|
+
"import": "./dist/money.js"
|
|
38
|
+
},
|
|
35
39
|
"./errors": {
|
|
36
40
|
"types": "./dist/errors.d.ts",
|
|
37
41
|
"import": "./dist/errors.js"
|