@vielzeug/coins 2.2.0 → 3.0.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 +12 -67
- package/dist/_decimal.cjs +1 -1
- package/dist/_decimal.cjs.map +1 -1
- package/dist/_decimal.d.ts +1 -0
- package/dist/_decimal.d.ts.map +1 -1
- package/dist/_decimal.js +30 -19
- package/dist/_decimal.js.map +1 -1
- package/dist/aggregate.cjs +1 -1
- package/dist/aggregate.cjs.map +1 -1
- package/dist/aggregate.d.ts.map +1 -1
- package/dist/aggregate.js +32 -26
- package/dist/aggregate.js.map +1 -1
- package/dist/coins.cjs +1 -1
- package/dist/coins.cjs.map +1 -1
- package/dist/coins.iife.js +1 -1
- package/dist/coins.iife.js.map +1 -1
- package/dist/coins.js +1 -1
- package/dist/coins.js.map +1 -1
- package/dist/currency.cjs +1 -1
- package/dist/currency.cjs.map +1 -1
- package/dist/currency.d.ts.map +1 -1
- package/dist/currency.js +7 -6
- package/dist/currency.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +3 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +16 -5
- package/dist/errors.js.map +1 -1
- package/dist/exchange.cjs +1 -1
- package/dist/exchange.cjs.map +1 -1
- package/dist/exchange.js +1 -1
- package/dist/exchange.js.map +1 -1
- package/dist/format.cjs +1 -1
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +54 -52
- package/dist/format.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/money.cjs +1 -1
- package/dist/money.cjs.map +1 -1
- package/dist/money.d.ts +9 -2
- package/dist/money.d.ts.map +1 -1
- package/dist/money.js +72 -54
- package/dist/money.js.map +1 -1
- package/dist/serialization.cjs +1 -1
- package/dist/serialization.cjs.map +1 -1
- package/dist/serialization.d.ts +1 -4
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +6 -38
- package/dist/serialization.js.map +1 -1
- package/package.json +8 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEhD,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAI9C"}
|
package/dist/serialization.js
CHANGED
|
@@ -1,45 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { currency as t } from "./currency.js";
|
|
3
|
-
import { assertMoney as n, money as r } from "./money.js";
|
|
1
|
+
import { assertMoney as e } from "./money.js";
|
|
4
2
|
//#region src/serialization.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
];
|
|
10
|
-
function o(e) {
|
|
11
|
-
return n(e), {
|
|
12
|
-
amount: e.amount.toString(),
|
|
13
|
-
currency: e.currency.code,
|
|
3
|
+
function t(t) {
|
|
4
|
+
return e(t), {
|
|
5
|
+
amount: t.amount.toString(),
|
|
6
|
+
currency: t.currency.code,
|
|
14
7
|
unit: "minor"
|
|
15
8
|
};
|
|
16
9
|
}
|
|
17
|
-
function s(n, i = {}) {
|
|
18
|
-
try {
|
|
19
|
-
let e = c(n), a = i.currency ?? t;
|
|
20
|
-
return r(BigInt(e.amount), a(e.currency), { unit: "minor" });
|
|
21
|
-
} catch (t) {
|
|
22
|
-
throw new e("INVALID_MONEY", "Invalid Money JSON", { cause: t });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function c(e) {
|
|
26
|
-
if (typeof e != "object" || !e || Object.getPrototypeOf(e) !== Object.prototype) throw TypeError("Money JSON must be a plain object");
|
|
27
|
-
let t = Object.getOwnPropertyDescriptors(e), n = Reflect.ownKeys(e);
|
|
28
|
-
if (n.length !== a.length || !a.every((e) => n.includes(e))) throw TypeError("Money JSON must contain only amount, currency, and unit");
|
|
29
|
-
for (let e of a) {
|
|
30
|
-
let n = t[e];
|
|
31
|
-
if (!n || !("value" in n) || n.get || n.set) throw TypeError(`Money JSON property "${e}" must be a data value`);
|
|
32
|
-
}
|
|
33
|
-
let r = t.amount?.value, o = t.currency?.value, s = t.unit?.value;
|
|
34
|
-
if (typeof r != "string" || !i.test(r)) throw TypeError("Money JSON amount must be a canonical integer string");
|
|
35
|
-
if (typeof o != "string" || s !== "minor") throw TypeError("Money JSON currency/unit are invalid");
|
|
36
|
-
return {
|
|
37
|
-
amount: r,
|
|
38
|
-
currency: o,
|
|
39
|
-
unit: s
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
10
|
//#endregion
|
|
43
|
-
export {
|
|
11
|
+
export { t as toJSON };
|
|
44
12
|
|
|
45
13
|
//# sourceMappingURL=serialization.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialization.js","names":[],"sources":["../src/serialization.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"serialization.js","names":[],"sources":["../src/serialization.ts"],"sourcesContent":["import { assertMoney } from './money';\nimport type { Money, MoneyJSON } from './types';\n\nexport function toJSON(value: Money): MoneyJSON {\n assertMoney(value);\n\n return { amount: value.amount.toString(), currency: value.currency.code, unit: 'minor' };\n}\n"],"mappings":";;AAGA,SAAgB,EAAO,GAAyB;CAG9C,OAFA,EAAY,CAAK,GAEV;EAAE,QAAQ,EAAM,OAAO,SAAS;EAAG,UAAU,EAAM,SAAS;EAAM,MAAM;CAAQ;AACzF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/coins",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Bigint-based monetary arithmetic with currency formatting, exchange rates, and rounding policies",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,18 +30,19 @@
|
|
|
30
30
|
"registry": "https://registry.npmjs.org/"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "vite build && pnpm run build:bundle && pnpm run build:types",
|
|
33
|
+
"build": "vite build && pnpm --silent run build:bundle && pnpm --silent run build:types && pnpm --silent run verify:exports",
|
|
34
34
|
"build:bundle": "vite build --config vite.bundle.config.ts",
|
|
35
35
|
"build:types": "tsc -p tsconfig.declarations.json",
|
|
36
36
|
"fix": "biome check --write src",
|
|
37
37
|
"lint": "biome ci src",
|
|
38
|
-
"prepublishOnly": "pnpm run build",
|
|
39
|
-
"test": "vitest"
|
|
38
|
+
"prepublishOnly": "pnpm --silent run build",
|
|
39
|
+
"test": "vitest",
|
|
40
|
+
"verify:exports": "node verify-exports.mjs"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@types/node": "^26.
|
|
43
|
+
"@types/node": "^26.4.1",
|
|
43
44
|
"typescript": "^6.0.3",
|
|
44
|
-
"vite": "^8.2.
|
|
45
|
-
"vitest": "^
|
|
45
|
+
"vite": "^8.2.2",
|
|
46
|
+
"vitest": "^5.0.0"
|
|
46
47
|
}
|
|
47
48
|
}
|