@wickermoney/plugin-sdk 0.2.1 → 0.3.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.
Files changed (103) hide show
  1. package/README.md +53 -2
  2. package/dist/index.d.ts +4 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/manifest/CORE_TABLES.d.ts.map +1 -1
  7. package/dist/manifest/CORE_TABLES.js +3 -2
  8. package/dist/manifest/CORE_TABLES.js.map +1 -1
  9. package/dist/money/MONEY_SCALE.d.ts +3 -0
  10. package/dist/money/MONEY_SCALE.d.ts.map +1 -0
  11. package/dist/money/MONEY_SCALE.js +3 -0
  12. package/dist/money/MONEY_SCALE.js.map +1 -0
  13. package/dist/money/MONEY_UNIT.d.ts +8 -0
  14. package/dist/money/MONEY_UNIT.d.ts.map +1 -0
  15. package/dist/money/MONEY_UNIT.js +8 -0
  16. package/dist/money/MONEY_UNIT.js.map +1 -0
  17. package/dist/money/Money.d.ts +12 -0
  18. package/dist/money/Money.d.ts.map +1 -0
  19. package/dist/money/Money.js +2 -0
  20. package/dist/money/Money.js.map +1 -0
  21. package/dist/money/ZERO_MONEY.d.ts +8 -0
  22. package/dist/money/ZERO_MONEY.d.ts.map +1 -0
  23. package/dist/money/ZERO_MONEY.js +8 -0
  24. package/dist/money/ZERO_MONEY.js.map +1 -0
  25. package/dist/money/absMoney.d.ts +9 -0
  26. package/dist/money/absMoney.d.ts.map +1 -0
  27. package/dist/money/absMoney.js +14 -0
  28. package/dist/money/absMoney.js.map +1 -0
  29. package/dist/money/addMoney.d.ts +12 -0
  30. package/dist/money/addMoney.d.ts.map +1 -0
  31. package/dist/money/addMoney.js +16 -0
  32. package/dist/money/addMoney.js.map +1 -0
  33. package/dist/money/compareMoney.d.ts +13 -0
  34. package/dist/money/compareMoney.d.ts.map +1 -0
  35. package/dist/money/compareMoney.js +18 -0
  36. package/dist/money/compareMoney.js.map +1 -0
  37. package/dist/money/divideUnits.d.ts +21 -0
  38. package/dist/money/divideUnits.d.ts.map +1 -0
  39. package/dist/money/divideUnits.js +29 -0
  40. package/dist/money/divideUnits.js.map +1 -0
  41. package/dist/money/editableMoney.d.ts +16 -0
  42. package/dist/money/editableMoney.d.ts.map +1 -0
  43. package/dist/money/editableMoney.js +27 -0
  44. package/dist/money/editableMoney.js.map +1 -0
  45. package/dist/money/equalMoney.d.ts +13 -0
  46. package/dist/money/equalMoney.d.ts.map +1 -0
  47. package/dist/money/equalMoney.js +16 -0
  48. package/dist/money/equalMoney.js.map +1 -0
  49. package/dist/money/index.d.ts +44 -0
  50. package/dist/money/index.d.ts.map +1 -0
  51. package/dist/money/index.js +18 -0
  52. package/dist/money/index.js.map +1 -0
  53. package/dist/money/isNegativeMoney.d.ts +9 -0
  54. package/dist/money/isNegativeMoney.d.ts.map +1 -0
  55. package/dist/money/isNegativeMoney.js +12 -0
  56. package/dist/money/isNegativeMoney.js.map +1 -0
  57. package/dist/money/isZeroMoney.d.ts +9 -0
  58. package/dist/money/isZeroMoney.d.ts.map +1 -0
  59. package/dist/money/isZeroMoney.js +12 -0
  60. package/dist/money/isZeroMoney.js.map +1 -0
  61. package/dist/money/moneyToUnits.d.ts +23 -0
  62. package/dist/money/moneyToUnits.d.ts.map +1 -0
  63. package/dist/money/moneyToUnits.js +37 -0
  64. package/dist/money/moneyToUnits.js.map +1 -0
  65. package/dist/money/negateMoney.d.ts +9 -0
  66. package/dist/money/negateMoney.d.ts.map +1 -0
  67. package/dist/money/negateMoney.js +13 -0
  68. package/dist/money/negateMoney.js.map +1 -0
  69. package/dist/money/normalizeMoney.d.ts +12 -0
  70. package/dist/money/normalizeMoney.d.ts.map +1 -0
  71. package/dist/money/normalizeMoney.js +16 -0
  72. package/dist/money/normalizeMoney.js.map +1 -0
  73. package/dist/money/subtractMoney.d.ts +10 -0
  74. package/dist/money/subtractMoney.d.ts.map +1 -0
  75. package/dist/money/subtractMoney.js +14 -0
  76. package/dist/money/subtractMoney.js.map +1 -0
  77. package/dist/money/sumMoney.d.ts +9 -0
  78. package/dist/money/sumMoney.d.ts.map +1 -0
  79. package/dist/money/sumMoney.js +13 -0
  80. package/dist/money/sumMoney.js.map +1 -0
  81. package/dist/money/unitsToMoney.d.ts +14 -0
  82. package/dist/money/unitsToMoney.d.ts.map +1 -0
  83. package/dist/money/unitsToMoney.js +23 -0
  84. package/dist/money/unitsToMoney.js.map +1 -0
  85. package/dist/recurrence/index.d.ts +2 -1
  86. package/dist/recurrence/index.d.ts.map +1 -1
  87. package/dist/recurrence/index.js +1 -0
  88. package/dist/recurrence/index.js.map +1 -1
  89. package/dist/recurrence/projection.d.ts +10 -2
  90. package/dist/recurrence/projection.d.ts.map +1 -1
  91. package/dist/recurrence/projection.js +38 -30
  92. package/dist/recurrence/projection.js.map +1 -1
  93. package/dist/recurrence/scheduled.d.ts +29 -0
  94. package/dist/recurrence/scheduled.d.ts.map +1 -0
  95. package/dist/recurrence/scheduled.js +108 -0
  96. package/dist/recurrence/scheduled.js.map +1 -0
  97. package/dist/recurrence/types.d.ts +42 -0
  98. package/dist/recurrence/types.d.ts.map +1 -1
  99. package/package.json +5 -1
  100. package/dist/recurrence/money.d.ts +0 -39
  101. package/dist/recurrence/money.d.ts.map +0 -1
  102. package/dist/recurrence/money.js +0 -58
  103. package/dist/recurrence/money.js.map +0 -1
package/README.md CHANGED
@@ -28,10 +28,11 @@ plugin as a Module Federation singleton.
28
28
  | Import | Use it for | Contents |
29
29
  |---|---|---|
30
30
  | `@wickermoney/plugin-sdk/runtime` | Plugin UI code (browser) | Types for the React components a plugin exports (`PluginWidgetProps`, `PluginPageProps`, `PluginContext`, ...), and `adoptPluginStyles` |
31
- | `@wickermoney/plugin-sdk/recurrence` | Anything (browser or Node) | Recurring-item date maths and projections: `occurrences`, `nextOccurrence`, `nextPayday`, `monthlyEquivalent`, `dailyBalances`, `flowTotals` |
31
+ | `@wickermoney/plugin-sdk/recurrence` | Anything (browser or Node) | Recurring-item date maths and projections: `occurrences`, `nextOccurrence`, `scheduledOccurrences`, `nextScheduledOccurrence`, `nextPayday`, `monthlyEquivalent`, `dailyBalances`, `flowTotals`, with per-occurrence overrides (skip, move, change the legs) |
32
+ | `@wickermoney/plugin-sdk/money` | Anything (browser or Node) | Exact money arithmetic on decimal strings: `addMoney`, `sumMoney`, `compareMoney`, `equalMoney`, `moneyToUnits`, `divideUnits`, ... |
32
33
  | `@wickermoney/plugin-sdk` | Hosts, tooling, tests (Node) | Everything above, plus the Zod manifest schemas, `parseManifest`, dashboard-range helpers and constants |
33
34
 
34
- Import from `/runtime` (and `/recurrence` if you need it) in plugin UI code.
35
+ Import from `/runtime` (and `/money` or `/recurrence` if you need them) in plugin UI code.
35
36
  The package root re-exports the Zod manifest schemas, which add about 85 kB to
36
37
  a plugin bundle that never uses them.
37
38
 
@@ -62,6 +63,56 @@ from the anchor each time (Jan 31 → Feb 28 → Mar 31). `semimonthly` takes tw
62
63
  days (`semimonthlyDays`, default `[1, 15]`). An unknown frequency throws rather
63
64
  than dropping an item from a forecast.
64
65
 
66
+ An item can carry `overrides`, keyed by nominal date, to change single
67
+ occurrences: `skipped`, a new `date` (earlier or later, even outside the range
68
+ asked about) or replacement `legs`. Every projection honours them, and
69
+ `scheduledOccurrences(item, from, to)` lists what lands in a range after them.
70
+ An empty `legs` list means "happens, moves nothing", which is how money that
71
+ has already posted is kept out of a projection.
72
+
73
+ ```ts
74
+ const bills = { ...rent, overrides: { '2026-03-31': { skipped: true }, '2026-04-30': { date: '2026-05-01' } } }
75
+ scheduledOccurrences(bills, '2026-03-01', '2026-06-01')
76
+ // [{ nominalDate: '2026-04-30', date: '2026-05-01', legs }, { nominalDate: '2026-05-31', ... }]
77
+ ```
78
+
79
+ ## Money
80
+
81
+ Money is `numeric(19,4)` in the database and a decimal string in TypeScript,
82
+ never a `number`. `/money` does the arithmetic exactly, in `bigint` units of
83
+ 0.0001, and hands back canonical four-decimal strings.
84
+
85
+ ```ts
86
+ import { addMoney, compareMoney, equalMoney, sumMoney } from '@wickermoney/plugin-sdk/money'
87
+
88
+ sumMoney(['0.1', '0.2']) // '0.3000', not 0.30000000000000004
89
+ equalMoney('-81.2000', '-81.20') // true; `===` would say false
90
+ rows.sort((a, b) => compareMoney(a.total, b.total))
91
+ ```
92
+
93
+ For loops that add up many values, work in units and format once:
94
+
95
+ ```ts
96
+ import { moneyToUnits, unitsToMoney, divideUnits } from '@wickermoney/plugin-sdk/money'
97
+
98
+ let total = 0n
99
+ for (const row of rows) total += moneyToUnits(row.amount)
100
+ unitsToMoney(total) // '1234.5600'
101
+ unitsToMoney(divideUnits(total * 26n, 12n)) // scale, then round once
102
+ ```
103
+
104
+ The rules:
105
+
106
+ - **Strict input.** A plain decimal string with at most four decimal places.
107
+ Anything else, including a fifth decimal place, throws `RangeError`. Nothing
108
+ is silently truncated or rounded, and the API refuses the same input.
109
+ - **Canonical output.** Four decimal places, and never `'-0.0000'`.
110
+ - **One rounding rule.** Only `divideUnits` rounds, half away from zero. That
111
+ is the API's rule as well, so a plugin and the server agree to the unit.
112
+ - **Not for display.** `unitsToMoney` returns the storage form. Show amounts
113
+ with the host's `ctx.formatMoney`, and prefill inputs with `editableMoney`
114
+ (`'450.0000'` → `'450.00'`).
115
+
65
116
  ## A plugin, in brief
66
117
 
67
118
  A plugin is a **manifest** plus a **Module Federation remote** whose exposed
package/dist/index.d.ts CHANGED
@@ -13,6 +13,8 @@ export { adoptPluginStyles } from './runtime.js';
13
13
  export type { PluginApi, PluginContext, PluginModule, PluginPage, PluginPageProps, PluginSession, PluginWidget, PluginWidgetProps, } from './runtime.js';
14
14
  export { RANGE_KEYS, DEFAULT_RANGE_KEY, isRangeKey, rangeLabel, resolveRange, monthsInRange, } from './range.js';
15
15
  export type { DashboardRange, RangeKey } from './range.js';
16
- export { DEFAULT_SEMIMONTHLY_DAYS, RECURRENCE_FREQUENCIES, dailyBalances, flowTotals, monthlyEquivalent, nextOccurrence, nextPayday, occurrences, } from './recurrence/index.js';
17
- export type { DailyBalance, FlowTotals, RecurrenceFrequency, RecurrenceSchedule, RecurringItem, RecurringLeg, } from './recurrence/index.js';
16
+ export { DEFAULT_SEMIMONTHLY_DAYS, RECURRENCE_FREQUENCIES, dailyBalances, flowTotals, monthlyEquivalent, nextOccurrence, nextPayday, nextScheduledOccurrence, occurrences, scheduledOccurrences, } from './recurrence/index.js';
17
+ export type { DailyBalance, FlowTotals, OccurrenceOverride, RecurrenceFrequency, RecurrenceSchedule, RecurringItem, RecurringLeg, ScheduledOccurrence, } from './recurrence/index.js';
18
+ export { MONEY_SCALE, MONEY_UNIT, ZERO_MONEY, absMoney, addMoney, compareMoney, divideUnits, editableMoney, equalMoney, isNegativeMoney, isZeroMoney, moneyToUnits, negateMoney, normalizeMoney, subtractMoney, sumMoney, unitsToMoney, } from './money/index.js';
19
+ export type { Money } from './money/index.js';
18
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,UAAU,GACX,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,YAAY,EACV,SAAS,EACT,aAAa,EACb,YAAY,EACZ,UAAU,EACV,eAAe,EACf,aAAa,EACb,YAAY,EACZ,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,UAAU,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,GACnF,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1D,OAAO,EACL,wBAAwB,EAAE,sBAAsB,EAChD,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,GACtF,MAAM,uBAAuB,CAAA;AAC9B,YAAY,EACV,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,GAC/F,MAAM,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,UAAU,GACX,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,YAAY,EACV,SAAS,EACT,aAAa,EACb,YAAY,EACZ,UAAU,EACV,eAAe,EACf,aAAa,EACb,YAAY,EACZ,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,UAAU,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,GACnF,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1D,OAAO,EACL,wBAAwB,EAAE,sBAAsB,EAChD,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,uBAAuB,EACjG,WAAW,EAAE,oBAAoB,GAClC,MAAM,uBAAuB,CAAA;AAC9B,YAAY,EACV,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,aAAa,EACpG,YAAY,EAAE,mBAAmB,GAClC,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,WAAW,EAAE,UAAU,EAAE,UAAU,EACnC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EACzF,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,GAC9F,MAAM,kBAAkB,CAAA;AACzB,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA"}
package/dist/index.js CHANGED
@@ -10,5 +10,6 @@
10
10
  export { CORE_TABLES, checkRemoteEntry, remoteEntrySchema, PERMISSIONS, REMOTE_ENTRY_TYPE, SDK_MAJOR_VERSION, WIDGET_SIZES, WIDGET_SLOTS, federationName, isCompatible, pagePath, parseManifest, pageContributionSchema, pluginManifestSchema, tableGrantSchema, widgetContributionSchema, } from './manifest/index.js';
11
11
  export { adoptPluginStyles } from './runtime.js';
12
12
  export { RANGE_KEYS, DEFAULT_RANGE_KEY, isRangeKey, rangeLabel, resolveRange, monthsInRange, } from './range.js';
13
- export { DEFAULT_SEMIMONTHLY_DAYS, RECURRENCE_FREQUENCIES, dailyBalances, flowTotals, monthlyEquivalent, nextOccurrence, nextPayday, occurrences, } from './recurrence/index.js';
13
+ export { DEFAULT_SEMIMONTHLY_DAYS, RECURRENCE_FREQUENCIES, dailyBalances, flowTotals, monthlyEquivalent, nextOccurrence, nextPayday, nextScheduledOccurrence, occurrences, scheduledOccurrences, } from './recurrence/index.js';
14
+ export { MONEY_SCALE, MONEY_UNIT, ZERO_MONEY, absMoney, addMoney, compareMoney, divideUnits, editableMoney, equalMoney, isNegativeMoney, isZeroMoney, moneyToUnits, negateMoney, normalizeMoney, subtractMoney, sumMoney, unitsToMoney, } from './money/index.js';
14
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,qBAAqB,CAAA;AAa5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAYhD,OAAO,EACL,UAAU,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,GACnF,MAAM,YAAY,CAAA;AAGnB,OAAO,EACL,wBAAwB,EAAE,sBAAsB,EAChD,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,GACtF,MAAM,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,qBAAqB,CAAA;AAa5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAYhD,OAAO,EACL,UAAU,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,GACnF,MAAM,YAAY,CAAA;AAGnB,OAAO,EACL,wBAAwB,EAAE,sBAAsB,EAChD,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,uBAAuB,EACjG,WAAW,EAAE,oBAAoB,GAClC,MAAM,uBAAuB,CAAA;AAM9B,OAAO,EACL,WAAW,EAAE,UAAU,EAAE,UAAU,EACnC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EACzF,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,GAC9F,MAAM,kBAAkB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"CORE_TABLES.d.ts","sourceRoot":"","sources":["../../src/manifest/CORE_TABLES.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,4IAUd,CAAA"}
1
+ {"version":3,"file":"CORE_TABLES.d.ts","sourceRoot":"","sources":["../../src/manifest/CORE_TABLES.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,4IAWd,CAAA"}
@@ -11,8 +11,9 @@ export const CORE_TABLES = [
11
11
  'categories',
12
12
  'category_rules',
13
13
  'category_rule_conditions',
14
- // Also grants `recurring_item_legs`: an item is its schedule plus its legs,
15
- // and neither is usable without the other.
14
+ // Also grants `recurring_item_legs`, `recurring_occurrences` and
15
+ // `recurring_occurrence_legs`: an item is its schedule plus its legs plus
16
+ // what was recorded about single occurrences, and none is usable alone.
16
17
  'recurring_items',
17
18
  ];
18
19
  //# sourceMappingURL=CORE_TABLES.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CORE_TABLES.js","sourceRoot":"","sources":["../../src/manifest/CORE_TABLES.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,UAAU;IACV,cAAc;IACd,oBAAoB;IACpB,YAAY;IACZ,gBAAgB;IAChB,0BAA0B;IAC1B,4EAA4E;IAC5E,2CAA2C;IAC3C,iBAAiB;CACT,CAAA"}
1
+ {"version":3,"file":"CORE_TABLES.js","sourceRoot":"","sources":["../../src/manifest/CORE_TABLES.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,UAAU;IACV,cAAc;IACd,oBAAoB;IACpB,YAAY;IACZ,gBAAgB;IAChB,0BAA0B;IAC1B,iEAAiE;IACjE,0EAA0E;IAC1E,wEAAwE;IACxE,iBAAiB;CACT,CAAA"}
@@ -0,0 +1,3 @@
1
+ /** Decimal places money is held at: the scale of `numeric(19,4)`. */
2
+ export declare const MONEY_SCALE = 4;
3
+ //# sourceMappingURL=MONEY_SCALE.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MONEY_SCALE.d.ts","sourceRoot":"","sources":["../../src/money/MONEY_SCALE.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,eAAO,MAAM,WAAW,IAAI,CAAA"}
@@ -0,0 +1,3 @@
1
+ /** Decimal places money is held at: the scale of `numeric(19,4)`. */
2
+ export const MONEY_SCALE = 4;
3
+ //# sourceMappingURL=MONEY_SCALE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MONEY_SCALE.js","sourceRoot":"","sources":["../../src/money/MONEY_SCALE.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Integer units per whole currency unit (`10 ** MONEY_SCALE`).
3
+ *
4
+ * {@link moneyToUnits} returns amounts in these units, so `1n` is 0.0001 and
5
+ * `MONEY_UNIT` is 1.0000.
6
+ */
7
+ export declare const MONEY_UNIT = 10000n;
8
+ //# sourceMappingURL=MONEY_UNIT.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MONEY_UNIT.d.ts","sourceRoot":"","sources":["../../src/money/MONEY_UNIT.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,UAAU,SAAU,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Integer units per whole currency unit (`10 ** MONEY_SCALE`).
3
+ *
4
+ * {@link moneyToUnits} returns amounts in these units, so `1n` is 0.0001 and
5
+ * `MONEY_UNIT` is 1.0000.
6
+ */
7
+ export const MONEY_UNIT = 10000n;
8
+ //# sourceMappingURL=MONEY_UNIT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MONEY_UNIT.js","sourceRoot":"","sources":["../../src/money/MONEY_UNIT.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAO,CAAA"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * An amount of money as a decimal string, such as `'-81.2000'` or `'450'`.
3
+ *
4
+ * Money is `numeric(19,4)` in PostgreSQL and a string everywhere in
5
+ * TypeScript, never a `number`: a double holds about fifteen significant
6
+ * digits and cannot represent `0.1` exactly, so `Number` arithmetic drifts by
7
+ * a cent nobody can find afterwards. The alias documents intent only; any
8
+ * plain decimal string is accepted, and the functions in this module return
9
+ * the canonical four-decimal form.
10
+ */
11
+ export type Money = string;
12
+ //# sourceMappingURL=Money.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Money.d.ts","sourceRoot":"","sources":["../../src/money/Money.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Money.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Money.js","sourceRoot":"","sources":["../../src/money/Money.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Zero in canonical form, as every function in this module returns it.
3
+ *
4
+ * Compare amounts with {@link isZeroMoney} or {@link equalMoney} rather than
5
+ * against this string: `'0'`, `'0.00'` and `'-0.0000'` are all zero too.
6
+ */
7
+ export declare const ZERO_MONEY = "0.0000";
8
+ //# sourceMappingURL=ZERO_MONEY.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZERO_MONEY.d.ts","sourceRoot":"","sources":["../../src/money/ZERO_MONEY.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,UAAU,WAAW,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Zero in canonical form, as every function in this module returns it.
3
+ *
4
+ * Compare amounts with {@link isZeroMoney} or {@link equalMoney} rather than
5
+ * against this string: `'0'`, `'0.00'` and `'-0.0000'` are all zero too.
6
+ */
7
+ export const ZERO_MONEY = '0.0000';
8
+ //# sourceMappingURL=ZERO_MONEY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZERO_MONEY.js","sourceRoot":"","sources":["../../src/money/ZERO_MONEY.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The magnitude of an amount.
3
+ *
4
+ * @param value - A decimal string.
5
+ * @returns `|value|` as a four-decimal string.
6
+ * @throws {RangeError} If `value` is not a decimal with at most four places.
7
+ */
8
+ export declare function absMoney(value: string): string;
9
+ //# sourceMappingURL=absMoney.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"absMoney.d.ts","sourceRoot":"","sources":["../../src/money/absMoney.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG9C"}
@@ -0,0 +1,14 @@
1
+ import { moneyToUnits } from './moneyToUnits.js';
2
+ import { unitsToMoney } from './unitsToMoney.js';
3
+ /**
4
+ * The magnitude of an amount.
5
+ *
6
+ * @param value - A decimal string.
7
+ * @returns `|value|` as a four-decimal string.
8
+ * @throws {RangeError} If `value` is not a decimal with at most four places.
9
+ */
10
+ export function absMoney(value) {
11
+ const units = moneyToUnits(value);
12
+ return unitsToMoney(units < 0n ? -units : units);
13
+ }
14
+ //# sourceMappingURL=absMoney.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"absMoney.js","sourceRoot":"","sources":["../../src/money/absMoney.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;IACjC,OAAO,YAAY,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AAClD,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Adds two amounts exactly.
3
+ *
4
+ * @param a - First amount, as a decimal string.
5
+ * @param b - Second amount, as a decimal string.
6
+ * @returns `a + b` as a four-decimal string.
7
+ * @throws {RangeError} If either argument is not a decimal with at most four places.
8
+ * @example
9
+ * addMoney('0.1', '0.2') // '0.3000'
10
+ */
11
+ export declare function addMoney(a: string, b: string): string;
12
+ //# sourceMappingURL=addMoney.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addMoney.d.ts","sourceRoot":"","sources":["../../src/money/addMoney.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD"}
@@ -0,0 +1,16 @@
1
+ import { moneyToUnits } from './moneyToUnits.js';
2
+ import { unitsToMoney } from './unitsToMoney.js';
3
+ /**
4
+ * Adds two amounts exactly.
5
+ *
6
+ * @param a - First amount, as a decimal string.
7
+ * @param b - Second amount, as a decimal string.
8
+ * @returns `a + b` as a four-decimal string.
9
+ * @throws {RangeError} If either argument is not a decimal with at most four places.
10
+ * @example
11
+ * addMoney('0.1', '0.2') // '0.3000'
12
+ */
13
+ export function addMoney(a, b) {
14
+ return unitsToMoney(moneyToUnits(a) + moneyToUnits(b));
15
+ }
16
+ //# sourceMappingURL=addMoney.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addMoney.js","sourceRoot":"","sources":["../../src/money/addMoney.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,OAAO,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AACxD,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Orders two amounts by value, for `Array.prototype.sort` and the like.
3
+ *
4
+ * Compares numerically, never as text: `'-81.2000'` equals `'-81.20'`, and
5
+ * `'9'` is less than `'10'`.
6
+ *
7
+ * @param a - First amount, as a decimal string.
8
+ * @param b - Second amount, as a decimal string.
9
+ * @returns `-1` if `a < b`, `1` if `a > b`, otherwise `0`.
10
+ * @throws {RangeError} If either argument is not a decimal with at most four places.
11
+ */
12
+ export declare function compareMoney(a: string, b: string): -1 | 0 | 1;
13
+ //# sourceMappingURL=compareMoney.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compareMoney.d.ts","sourceRoot":"","sources":["../../src/money/compareMoney.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAI7D"}
@@ -0,0 +1,18 @@
1
+ import { moneyToUnits } from './moneyToUnits.js';
2
+ /**
3
+ * Orders two amounts by value, for `Array.prototype.sort` and the like.
4
+ *
5
+ * Compares numerically, never as text: `'-81.2000'` equals `'-81.20'`, and
6
+ * `'9'` is less than `'10'`.
7
+ *
8
+ * @param a - First amount, as a decimal string.
9
+ * @param b - Second amount, as a decimal string.
10
+ * @returns `-1` if `a < b`, `1` if `a > b`, otherwise `0`.
11
+ * @throws {RangeError} If either argument is not a decimal with at most four places.
12
+ */
13
+ export function compareMoney(a, b) {
14
+ const x = moneyToUnits(a);
15
+ const y = moneyToUnits(b);
16
+ return x < y ? -1 : x > y ? 1 : 0;
17
+ }
18
+ //# sourceMappingURL=compareMoney.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compareMoney.js","sourceRoot":"","sources":["../../src/money/compareMoney.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,CAAS,EAAE,CAAS;IAC/C,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;IACzB,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;IACzB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACnC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Divides integer money units and rounds half away from zero.
3
+ *
4
+ * This is the one rounding rule in the SDK, and it is the API's too
5
+ * (`decimal.js` with `ROUND_HALF_UP`, which rounds ties away from zero). An
6
+ * amount and its negation round to mirror images, so `-0.00005` and `0.00005`
7
+ * both move away from zero and a refund nets exactly against its charge.
8
+ *
9
+ * To scale an amount by a fraction, multiply first and divide once:
10
+ * `divideUnits(units * 26n, 12n)` for a biweekly amount per month.
11
+ *
12
+ * @param numerator - Dividend, in units of 0.0001 (or a product of them).
13
+ * @param denominator - Divisor; any non-zero `bigint`.
14
+ * @returns The quotient rounded to a whole unit, half away from zero.
15
+ * @throws {RangeError} If `denominator` is zero.
16
+ * @example
17
+ * divideUnits(5n, 2n) // 3n
18
+ * divideUnits(-5n, 2n) // -3n
19
+ */
20
+ export declare function divideUnits(numerator: bigint, denominator: bigint): bigint;
21
+ //# sourceMappingURL=divideUnits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"divideUnits.d.ts","sourceRoot":"","sources":["../../src/money/divideUnits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAO1E"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Divides integer money units and rounds half away from zero.
3
+ *
4
+ * This is the one rounding rule in the SDK, and it is the API's too
5
+ * (`decimal.js` with `ROUND_HALF_UP`, which rounds ties away from zero). An
6
+ * amount and its negation round to mirror images, so `-0.00005` and `0.00005`
7
+ * both move away from zero and a refund nets exactly against its charge.
8
+ *
9
+ * To scale an amount by a fraction, multiply first and divide once:
10
+ * `divideUnits(units * 26n, 12n)` for a biweekly amount per month.
11
+ *
12
+ * @param numerator - Dividend, in units of 0.0001 (or a product of them).
13
+ * @param denominator - Divisor; any non-zero `bigint`.
14
+ * @returns The quotient rounded to a whole unit, half away from zero.
15
+ * @throws {RangeError} If `denominator` is zero.
16
+ * @example
17
+ * divideUnits(5n, 2n) // 3n
18
+ * divideUnits(-5n, 2n) // -3n
19
+ */
20
+ export function divideUnits(numerator, denominator) {
21
+ if (denominator === 0n)
22
+ throw new RangeError('Division by zero');
23
+ const negative = (numerator < 0n) !== (denominator < 0n);
24
+ const n = numerator < 0n ? -numerator : numerator;
25
+ const d = denominator < 0n ? -denominator : denominator;
26
+ const quotient = (n * 2n + d) / (d * 2n);
27
+ return negative ? -quotient : quotient;
28
+ }
29
+ //# sourceMappingURL=divideUnits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"divideUnits.js","sourceRoot":"","sources":["../../src/money/divideUnits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,WAAmB;IAChE,IAAI,WAAW,KAAK,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,kBAAkB,CAAC,CAAA;IAChE,MAAM,QAAQ,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,GAAG,EAAE,CAAC,CAAA;IACxD,MAAM,CAAC,GAAG,SAAS,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAA;IACjD,MAAM,CAAC,GAAG,WAAW,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAA;IACvD,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAA;IACxC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;AACxC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * An amount in the shape a person types, for prefilling an input.
3
+ *
4
+ * `numeric(19,4)` round-trips as `'450.0000'`, and putting that in an editable
5
+ * field tells the user the database's business rather than their own; nobody
6
+ * types four decimal places for a grocery budget. Two places are kept because
7
+ * that is what money looks like. Not localized and no currency symbol: use the
8
+ * host's `ctx.formatMoney` for display.
9
+ *
10
+ * @param value - A stored amount, as a decimal string.
11
+ * @returns Two decimals (`'450.00'`), or all four when the amount has real
12
+ * sub-cent precision (`'0.1250'`), so nothing the user entered is rounded away.
13
+ * @throws {RangeError} If `value` is not a decimal with at most four places.
14
+ */
15
+ export declare function editableMoney(value: string): string;
16
+ //# sourceMappingURL=editableMoney.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editableMoney.d.ts","sourceRoot":"","sources":["../../src/money/editableMoney.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOnD"}
@@ -0,0 +1,27 @@
1
+ import { MONEY_UNIT } from './MONEY_UNIT.js';
2
+ import { moneyToUnits } from './moneyToUnits.js';
3
+ import { unitsToMoney } from './unitsToMoney.js';
4
+ /**
5
+ * An amount in the shape a person types, for prefilling an input.
6
+ *
7
+ * `numeric(19,4)` round-trips as `'450.0000'`, and putting that in an editable
8
+ * field tells the user the database's business rather than their own; nobody
9
+ * types four decimal places for a grocery budget. Two places are kept because
10
+ * that is what money looks like. Not localized and no currency symbol: use the
11
+ * host's `ctx.formatMoney` for display.
12
+ *
13
+ * @param value - A stored amount, as a decimal string.
14
+ * @returns Two decimals (`'450.00'`), or all four when the amount has real
15
+ * sub-cent precision (`'0.1250'`), so nothing the user entered is rounded away.
16
+ * @throws {RangeError} If `value` is not a decimal with at most four places.
17
+ */
18
+ export function editableMoney(value) {
19
+ const units = moneyToUnits(value);
20
+ if (units % 100n !== 0n)
21
+ return unitsToMoney(units);
22
+ const negative = units < 0n;
23
+ const absolute = negative ? -units : units;
24
+ const cents = ((absolute % MONEY_UNIT) / 100n).toString().padStart(2, '0');
25
+ return `${negative ? '-' : ''}${absolute / MONEY_UNIT}.${cents}`;
26
+ }
27
+ //# sourceMappingURL=editableMoney.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editableMoney.js","sourceRoot":"","sources":["../../src/money/editableMoney.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;IACjC,IAAI,KAAK,GAAG,IAAI,KAAK,EAAE;QAAE,OAAO,YAAY,CAAC,KAAK,CAAC,CAAA;IACnD,MAAM,QAAQ,GAAG,KAAK,GAAG,EAAE,CAAA;IAC3B,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;IAC1C,MAAM,KAAK,GAAG,CAAC,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC1E,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,GAAG,UAAU,IAAI,KAAK,EAAE,CAAA;AAClE,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Tests whether two amounts are the same value.
3
+ *
4
+ * Use this instead of `===`: PostgreSQL returns `'-81.2000'` for an amount
5
+ * a CSV or a form wrote as `'-81.20'`, and the strings differ.
6
+ *
7
+ * @param a - First amount, as a decimal string.
8
+ * @param b - Second amount, as a decimal string.
9
+ * @returns `true` when both are the same amount at four decimal places.
10
+ * @throws {RangeError} If either argument is not a decimal with at most four places.
11
+ */
12
+ export declare function equalMoney(a: string, b: string): boolean;
13
+ //# sourceMappingURL=equalMoney.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"equalMoney.d.ts","sourceRoot":"","sources":["../../src/money/equalMoney.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAExD"}
@@ -0,0 +1,16 @@
1
+ import { moneyToUnits } from './moneyToUnits.js';
2
+ /**
3
+ * Tests whether two amounts are the same value.
4
+ *
5
+ * Use this instead of `===`: PostgreSQL returns `'-81.2000'` for an amount
6
+ * a CSV or a form wrote as `'-81.20'`, and the strings differ.
7
+ *
8
+ * @param a - First amount, as a decimal string.
9
+ * @param b - Second amount, as a decimal string.
10
+ * @returns `true` when both are the same amount at four decimal places.
11
+ * @throws {RangeError} If either argument is not a decimal with at most four places.
12
+ */
13
+ export function equalMoney(a, b) {
14
+ return moneyToUnits(a) === moneyToUnits(b);
15
+ }
16
+ //# sourceMappingURL=equalMoney.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"equalMoney.js","sourceRoot":"","sources":["../../src/money/equalMoney.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CAAC,CAAS,EAAE,CAAS;IAC7C,OAAO,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,CAAA;AAC5C,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @module
3
+ * Exact money arithmetic on decimal strings.
4
+ *
5
+ * Money is `numeric(19,4)` in PostgreSQL and a `string` in TypeScript at every
6
+ * boundary, never a `number`. In between, arithmetic happens in `bigint` units
7
+ * of 0.0001, so `0.1 + 0.2` is `0.3000` and a 19-digit balance keeps every
8
+ * digit.
9
+ *
10
+ * Two layers:
11
+ * - String in, string out: {@link addMoney}, {@link sumMoney},
12
+ * {@link compareMoney} and friends. Enough for most plugins.
13
+ * - `bigint` units, for loops that accumulate many values:
14
+ * {@link moneyToUnits}, {@link unitsToMoney} and {@link divideUnits}.
15
+ *
16
+ * Rules every function follows:
17
+ * - Input is a plain decimal string with at most four decimal places;
18
+ * anything else throws `RangeError`. Nothing is silently truncated.
19
+ * - Output is canonical: four decimal places, no `'-0.0000'`.
20
+ * - The only rounding is in {@link divideUnits}: half away from zero, the
21
+ * same rule the API uses.
22
+ *
23
+ * Pure and dependency-free, so it is safe in the browser and in Node. For
24
+ * showing an amount to a person, use the host's `ctx.formatMoney`.
25
+ */
26
+ export type { Money } from './Money.js';
27
+ export { MONEY_SCALE } from './MONEY_SCALE.js';
28
+ export { MONEY_UNIT } from './MONEY_UNIT.js';
29
+ export { ZERO_MONEY } from './ZERO_MONEY.js';
30
+ export { moneyToUnits } from './moneyToUnits.js';
31
+ export { unitsToMoney } from './unitsToMoney.js';
32
+ export { divideUnits } from './divideUnits.js';
33
+ export { normalizeMoney } from './normalizeMoney.js';
34
+ export { addMoney } from './addMoney.js';
35
+ export { subtractMoney } from './subtractMoney.js';
36
+ export { sumMoney } from './sumMoney.js';
37
+ export { negateMoney } from './negateMoney.js';
38
+ export { absMoney } from './absMoney.js';
39
+ export { compareMoney } from './compareMoney.js';
40
+ export { equalMoney } from './equalMoney.js';
41
+ export { isNegativeMoney } from './isNegativeMoney.js';
42
+ export { isZeroMoney } from './isZeroMoney.js';
43
+ export { editableMoney } from './editableMoney.js';
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/money/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,18 @@
1
+ export { MONEY_SCALE } from './MONEY_SCALE.js';
2
+ export { MONEY_UNIT } from './MONEY_UNIT.js';
3
+ export { ZERO_MONEY } from './ZERO_MONEY.js';
4
+ export { moneyToUnits } from './moneyToUnits.js';
5
+ export { unitsToMoney } from './unitsToMoney.js';
6
+ export { divideUnits } from './divideUnits.js';
7
+ export { normalizeMoney } from './normalizeMoney.js';
8
+ export { addMoney } from './addMoney.js';
9
+ export { subtractMoney } from './subtractMoney.js';
10
+ export { sumMoney } from './sumMoney.js';
11
+ export { negateMoney } from './negateMoney.js';
12
+ export { absMoney } from './absMoney.js';
13
+ export { compareMoney } from './compareMoney.js';
14
+ export { equalMoney } from './equalMoney.js';
15
+ export { isNegativeMoney } from './isNegativeMoney.js';
16
+ export { isZeroMoney } from './isZeroMoney.js';
17
+ export { editableMoney } from './editableMoney.js';
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/money/index.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Tests whether an amount is below zero.
3
+ *
4
+ * @param value - A decimal string.
5
+ * @returns `true` if `value` is strictly negative. `'-0.0000'` is zero, not negative.
6
+ * @throws {RangeError} If `value` is not a decimal with at most four places.
7
+ */
8
+ export declare function isNegativeMoney(value: string): boolean;
9
+ //# sourceMappingURL=isNegativeMoney.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNegativeMoney.d.ts","sourceRoot":"","sources":["../../src/money/isNegativeMoney.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD"}
@@ -0,0 +1,12 @@
1
+ import { moneyToUnits } from './moneyToUnits.js';
2
+ /**
3
+ * Tests whether an amount is below zero.
4
+ *
5
+ * @param value - A decimal string.
6
+ * @returns `true` if `value` is strictly negative. `'-0.0000'` is zero, not negative.
7
+ * @throws {RangeError} If `value` is not a decimal with at most four places.
8
+ */
9
+ export function isNegativeMoney(value) {
10
+ return moneyToUnits(value) < 0n;
11
+ }
12
+ //# sourceMappingURL=isNegativeMoney.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNegativeMoney.js","sourceRoot":"","sources":["../../src/money/isNegativeMoney.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,CAAA;AACjC,CAAC"}