@ducatjs/money 0.2.0 → 0.2.2

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 (75) hide show
  1. package/NOTICE +100 -0
  2. package/README.md +12 -13
  3. package/dist/fixed.d.ts.map +1 -1
  4. package/dist/fixed.js +10 -1
  5. package/dist/fixed.js.map +1 -1
  6. package/dist/money.d.ts.map +1 -1
  7. package/dist/money.js +2 -0
  8. package/dist/money.js.map +1 -1
  9. package/dist/plugins/adyen.d.ts +1 -1
  10. package/dist/plugins/adyen.d.ts.map +1 -1
  11. package/dist/plugins/adyen.js.map +1 -1
  12. package/dist/plugins/allocate.d.ts +1 -1
  13. package/dist/plugins/allocate.d.ts.map +1 -1
  14. package/dist/plugins/allocate.js.map +1 -1
  15. package/dist/plugins/braintree.d.ts +1 -1
  16. package/dist/plugins/braintree.d.ts.map +1 -1
  17. package/dist/plugins/braintree.js.map +1 -1
  18. package/dist/plugins/cash.d.ts +1 -1
  19. package/dist/plugins/cash.d.ts.map +1 -1
  20. package/dist/plugins/cash.js.map +1 -1
  21. package/dist/plugins/checkout.d.ts +1 -1
  22. package/dist/plugins/checkout.d.ts.map +1 -1
  23. package/dist/plugins/checkout.js.map +1 -1
  24. package/dist/plugins/convert.d.ts +2 -1
  25. package/dist/plugins/convert.d.ts.map +1 -1
  26. package/dist/plugins/convert.js.map +1 -1
  27. package/dist/plugins/exact.d.ts +1 -1
  28. package/dist/plugins/exact.d.ts.map +1 -1
  29. package/dist/plugins/exact.js.map +1 -1
  30. package/dist/plugins/fixed.d.ts +1 -1
  31. package/dist/plugins/fixed.d.ts.map +1 -1
  32. package/dist/plugins/fixed.js.map +1 -1
  33. package/dist/plugins/format.d.ts +1 -1
  34. package/dist/plugins/format.d.ts.map +1 -1
  35. package/dist/plugins/format.js.map +1 -1
  36. package/dist/plugins/klarna.d.ts +1 -1
  37. package/dist/plugins/klarna.d.ts.map +1 -1
  38. package/dist/plugins/klarna.js.map +1 -1
  39. package/dist/plugins/paypal.d.ts +1 -1
  40. package/dist/plugins/paypal.d.ts.map +1 -1
  41. package/dist/plugins/paypal.js +0 -4
  42. package/dist/plugins/paypal.js.map +1 -1
  43. package/dist/plugins/prisma.d.ts +1 -1
  44. package/dist/plugins/prisma.d.ts.map +1 -1
  45. package/dist/plugins/prisma.js +0 -4
  46. package/dist/plugins/prisma.js.map +1 -1
  47. package/dist/plugins/stripe.d.ts +1 -1
  48. package/dist/plugins/stripe.d.ts.map +1 -1
  49. package/dist/plugins/stripe.js +0 -4
  50. package/dist/plugins/stripe.js.map +1 -1
  51. package/dist/plugins/tax.d.ts +2 -1
  52. package/dist/plugins/tax.d.ts.map +1 -1
  53. package/dist/plugins/tax.js.map +1 -1
  54. package/dist/rounding.d.ts +15 -0
  55. package/dist/rounding.d.ts.map +1 -1
  56. package/dist/rounding.js +32 -0
  57. package/dist/rounding.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/fixed.ts +12 -0
  60. package/src/money.ts +2 -0
  61. package/src/plugins/adyen.ts +3 -2
  62. package/src/plugins/allocate.ts +3 -2
  63. package/src/plugins/braintree.ts +3 -2
  64. package/src/plugins/cash.ts +3 -2
  65. package/src/plugins/checkout.ts +3 -2
  66. package/src/plugins/convert.ts +3 -2
  67. package/src/plugins/exact.ts +3 -2
  68. package/src/plugins/fixed.ts +3 -2
  69. package/src/plugins/format.ts +3 -2
  70. package/src/plugins/klarna.ts +3 -2
  71. package/src/plugins/paypal.ts +3 -2
  72. package/src/plugins/prisma.ts +3 -2
  73. package/src/plugins/stripe.ts +3 -2
  74. package/src/plugins/tax.ts +3 -2
  75. package/src/rounding.ts +34 -0
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { type Fixed } from '../fixed.js';
6
6
  export * from '../fixed.js';
7
- declare module '../money.js' {
7
+ declare module '../index.js' {
8
8
  interface Money<C extends string> {
9
9
  /**
10
10
  * The exact Fixed of this amount, at its scale: `money('12.34', 'EUR').toFixedPoint()` is
@@ -1 +1 @@
1
- {"version":3,"file":"fixed.d.ts","sourceRoot":"","sources":["../../src/plugins/fixed.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAGvD,cAAc,aAAa,CAAC;AAE5B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B;;;;WAIG;QACH,YAAY,IAAI,KAAK,CAAC;KACvB;CACF"}
1
+ {"version":3,"file":"fixed.d.ts","sourceRoot":"","sources":["../../src/plugins/fixed.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAIvD,cAAc,aAAa,CAAC;AAE5B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B;;;;WAIG;QACH,YAAY,IAAI,KAAK,CAAC;KACvB;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"fixed.js","sourceRoot":"","sources":["../../src/plugins/fixed.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAEtD,cAAc,aAAa,CAAC;AAa5B,WAAW,CACT;IACE,YAAY;QACV,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF,EACD,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAClC,CAAC"}
1
+ {"version":3,"file":"fixed.js","sourceRoot":"","sources":["../../src/plugins/fixed.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,cAAc,aAAa,CAAC;AAa5B,WAAW,CACT;IACE,YAAY;QACV,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF,EACD,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAClC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export * from '../format.js';
2
- declare module '../money.js' {
2
+ declare module '../index.js' {
3
3
  interface Money<C extends string> {
4
4
  /** Locale formatting via Intl: `price.format('de-DE')` gives "19,99 €" */
5
5
  format(locale?: string, options?: Intl.NumberFormatOptions): string;
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/plugins/format.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,0EAA0E;QAC1E,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;QACpE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;KAC7F;CACF"}
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/plugins/format.ts"],"names":[],"mappings":"AAQA,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,0EAA0E;QAC1E,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;QACpE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;KAC7F;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/plugins/format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAEtD,cAAc,cAAc,CAAC;AAU7B,WAAW,CACT;IACE,MAAM,CAAc,MAAe,EAAE,OAAkC;QACrE,OAAO,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IACD,aAAa,CAAc,MAAe,EAAE,OAAkC;QAC5E,OAAO,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/plugins/format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,cAAc,cAAc,CAAC;AAU7B,WAAW,CACT;IACE,MAAM,CAAc,MAAe,EAAE,OAAkC;QACrE,OAAO,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IACD,aAAa,CAAc,MAAe,EAAE,OAAkC;QAC5E,OAAO,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /** `@ducatjs/money/klarna`: Klarna's amount view. Importing this module adds `toKlarna`. */
2
2
  import { type KlarnaAmountOptions } from '../klarna.js';
3
3
  export * from '../klarna.js';
4
- declare module '../money.js' {
4
+ declare module '../index.js' {
5
5
  interface Money<C extends string> {
6
6
  /** The integer for any Klarna amount field: `money('25', 'EUR').toKlarna()` is 2500. */
7
7
  toKlarna(options?: KlarnaAmountOptions): number;
@@ -1 +1 @@
1
- {"version":3,"file":"klarna.d.ts","sourceRoot":"","sources":["../../src/plugins/klarna.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,EAAY,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGlE,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,wFAAwF;QACxF,QAAQ,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC;KACjD;CACF"}
1
+ {"version":3,"file":"klarna.d.ts","sourceRoot":"","sources":["../../src/plugins/klarna.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,EAAY,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAIlE,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,wFAAwF;QACxF,QAAQ,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC;KACjD;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"klarna.js","sourceRoot":"","sources":["../../src/plugins/klarna.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,EAAE,QAAQ,EAA4B,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAEtD,cAAc,cAAc,CAAC;AAS7B,WAAW,CACT;IACE,QAAQ,CAAc,OAA6B;QACjD,OAAO,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
1
+ {"version":3,"file":"klarna.js","sourceRoot":"","sources":["../../src/plugins/klarna.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,EAAE,QAAQ,EAA4B,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,cAAc,cAAc,CAAC;AAS7B,WAAW,CACT;IACE,QAAQ,CAAc,OAA6B;QACjD,OAAO,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { type PayPalAmountOptions } from '../paypal.js';
2
2
  export * from '../paypal.js';
3
- declare module '../money.js' {
3
+ declare module '../index.js' {
4
4
  interface Money<C extends string> {
5
5
  /** The exact `value` string for PayPal: `money('1000', 'HUF').toPayPalValue()` is '1000'. */
6
6
  toPayPalValue(options?: PayPalAmountOptions): string;
@@ -1 +1 @@
1
- {"version":3,"file":"paypal.d.ts","sourceRoot":"","sources":["../../src/plugins/paypal.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEjF,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,6FAA6F;QAC7F,aAAa,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC;QACrD,2DAA2D;QAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG;YAAE,aAAa,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;KACnF;CACF"}
1
+ {"version":3,"file":"paypal.d.ts","sourceRoot":"","sources":["../../src/plugins/paypal.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEjF,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,6FAA6F;QAC7F,aAAa,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC;QACrD,2DAA2D;QAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG;YAAE,aAAa,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;KACnF;CACF"}
@@ -1,7 +1,3 @@
1
- /**
2
- * `@ducatjs/money/paypal`: PayPal's amount view. Importing this module adds `toPayPal` and
3
- * `toPayPalValue`.
4
- */
5
1
  import { extendMoney } from '../money.js';
6
2
  import { toPayPal, toPayPalValue } from '../paypal.js';
7
3
  export * from '../paypal.js';
@@ -1 +1 @@
1
- {"version":3,"file":"paypal.js","sourceRoot":"","sources":["../../src/plugins/paypal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAA4B,MAAM,cAAc,CAAC;AAEjF,cAAc,cAAc,CAAC;AAW7B,WAAW,CACT;IACE,aAAa,CAAc,OAA6B;QACtD,OAAO,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IACD,QAAQ,CAAc,OAA6B;QACjD,OAAO,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
1
+ {"version":3,"file":"paypal.js","sourceRoot":"","sources":["../../src/plugins/paypal.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAA4B,MAAM,cAAc,CAAC;AAEjF,cAAc,cAAc,CAAC;AAW7B,WAAW,CACT;IACE,aAAa,CAAc,OAA6B;QACtD,OAAO,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IACD,QAAQ,CAAc,OAA6B;QACjD,OAAO,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export * from '../prisma.js';
2
- declare module '../money.js' {
2
+ declare module '../index.js' {
3
3
  interface Money<C extends string> {
4
4
  /** A Decimal for a NUMERIC column: `m.toDecimalValue(Prisma.Decimal)`. */
5
5
  toDecimalValue<D>(Decimal: new (value: string) => D): D;
@@ -1 +1 @@
1
- {"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/plugins/prisma.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,0EAA0E;QAC1E,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;KACzD;CACF"}
1
+ {"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/plugins/prisma.ts"],"names":[],"mappings":"AAQA,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,0EAA0E;QAC1E,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;KACzD;CACF"}
@@ -1,7 +1,3 @@
1
- /**
2
- * `@ducatjs/money/prisma`: Prisma and SQL column helpers. Importing this module adds
3
- * `toDecimalValue`.
4
- */
5
1
  import { extendMoney } from '../money.js';
6
2
  import { toDecimalValue } from '../prisma.js';
7
3
  export * from '../prisma.js';
@@ -1 +1 @@
1
- {"version":3,"file":"prisma.js","sourceRoot":"","sources":["../../src/plugins/prisma.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,cAAc,cAAc,CAAC;AAS7B,WAAW,CACT;IACE,cAAc,CAAc,OAAuC;QACjE,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
1
+ {"version":3,"file":"prisma.js","sourceRoot":"","sources":["../../src/plugins/prisma.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,cAAc,cAAc,CAAC;AAS7B,WAAW,CACT;IACE,cAAc,CAAc,OAAuC;QACjE,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { type StripeAmountOptions } from '../stripe.js';
2
2
  export * from '../stripe.js';
3
- declare module '../money.js' {
3
+ declare module '../index.js' {
4
4
  interface Money<C extends string> {
5
5
  /** The integer `amount` to send to Stripe: `money('5', 'ISK').toStripeAmount()` is 500. */
6
6
  toStripeAmount(options?: StripeAmountOptions): number;
@@ -1 +1 @@
1
- {"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../../src/plugins/stripe.ts"],"names":[],"mappings":"AAKA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAElF,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,2FAA2F;QAC3F,cAAc,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC;QACtD,+FAA+F;QAC/F,QAAQ,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC;KAC/E;CACF"}
1
+ {"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../../src/plugins/stripe.ts"],"names":[],"mappings":"AAMA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAElF,cAAc,cAAc,CAAC;AAE7B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,2FAA2F;QAC3F,cAAc,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC;QACtD,+FAA+F;QAC/F,QAAQ,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC;KAC/E;CACF"}
@@ -1,7 +1,3 @@
1
- /**
2
- * `@ducatjs/money/stripe`: Stripe's minor-unit view. Importing this module adds `toStripe` and
3
- * `toStripeAmount`.
4
- */
5
1
  import { extendMoney } from '../money.js';
6
2
  import { toStripe, toStripeAmount } from '../stripe.js';
7
3
  export * from '../stripe.js';
@@ -1 +1 @@
1
- {"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../src/plugins/stripe.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAA4B,MAAM,cAAc,CAAC;AAElF,cAAc,cAAc,CAAC;AAW7B,WAAW,CACT;IACE,cAAc,CAAc,OAA6B;QACvD,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IACD,QAAQ,CAAc,OAA6B;QACjD,OAAO,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
1
+ {"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../src/plugins/stripe.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAA4B,MAAM,cAAc,CAAC;AAElF,cAAc,cAAc,CAAC;AAW7B,WAAW,CACT;IACE,cAAc,CAAc,OAA6B;QACvD,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IACD,QAAQ,CAAc,OAA6B;QACjD,OAAO,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;CACF,EACD,EAAE,KAAK,EAAE,uBAAuB,EAAE,CACnC,CAAC"}
@@ -3,9 +3,10 @@
3
3
  * methods below.
4
4
  */
5
5
  import type { Factor } from '../decimal.js';
6
+ import { type RoundingInput } from '../money.js';
6
7
  import { type TaxBreakdown } from '../tax.js';
7
8
  export * from '../tax.js';
8
- declare module '../money.js' {
9
+ declare module '../index.js' {
9
10
  interface Money<C extends string> {
10
11
  /** `percent`% of this, e.g. `price.percentage(15, 'halfEven')` */
11
12
  percentage(percent: Factor, rounding?: RoundingInput): Money<C>;
@@ -1 +1 @@
1
- {"version":3,"file":"tax.d.ts","sourceRoot":"","sources":["../../src/plugins/tax.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAA4C,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAExF,cAAc,WAAW,CAAC;AAE1B,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM;QAC9B,kEAAkE;QAClE,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAChE,4BAA4B;QAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,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E,QAAwB;QAC3D,OAAO,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IACD,UAAU,CAAc,OAAe,EAAE,QAAwB;QAC/D,OAAO,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;CACF,EACD,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAChC,CAAC"}
@@ -1,3 +1,4 @@
1
+ import type { Ratio } from './decimal.js';
1
2
  import { RoundingError } from './rounding-error.js';
2
3
  /**
3
4
  * Rounding modes. The string values are the ones `Intl.NumberFormat` uses for its `roundingMode`
@@ -35,6 +36,20 @@ export declare const Rounding: {
35
36
  */
36
37
  export declare const DEFAULT_ROUNDING: RoundingMode;
37
38
  export { RoundingError };
39
+ /**
40
+ * @internal `value / divisor` rounded with `mode`, for a safe-integer `value` and a reduced ratio
41
+ * (`ratio()` makes its denominator positive): the number fast path of Fixed's divide, at the value's
42
+ * own scale. Money's `divide` in money.ts inlines a copy of these steps, since a call there costs it
43
+ * about 4% on its benchmarks; test/divide.test.ts checks that the copies agree in every mode, and
44
+ * both against the proved kernel. It is `value × denominator / numerator`,
45
+ * rounded once by `divideAndRound`, which is the same fraction the inverse ratio would give, without
46
+ * building that ratio (bigint arithmetic and a gcd). Returns NaN when the number path doesn't apply,
47
+ * so the caller takes the bigint path:
48
+ * - a part that is NaN marks one that isn't a safe integer (`Ratio.n` and `Ratio.d`);
49
+ * - `value` and `denominator` are safe integers, so a float product beyond 2^53 - 1 can't round
50
+ * back into the safe range, and the bound check rejects every inexact product.
51
+ */
52
+ export declare function divideSafeByRatio(value: number, divisor: Ratio, mode: RoundingMode): number;
38
53
  /**
39
54
  * dividend / divisor rounded with `mode`, for safe-integer dividends and divisor > 0. Exact: the
40
55
  * float quotient is only a first guess, corrected until the remainder has the dividend's sign and
@@ -1 +1 @@
1
- {"version":3,"file":"rounding.d.ts","sourceRoot":"","sources":["../src/rounding.ts"],"names":[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AAO,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,CAkB3F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,CAwC5F;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,YAAY,GACjB,MAAM,CAKR"}
package/dist/rounding.js CHANGED
@@ -27,6 +27,38 @@ export const Rounding = {
27
27
  export const DEFAULT_ROUNDING = 'halfExpand';
28
28
  export { RoundingError };
29
29
  const MAX_SAFE_MINOR = Number.MAX_SAFE_INTEGER;
30
+ /**
31
+ * @internal `value / divisor` rounded with `mode`, for a safe-integer `value` and a reduced ratio
32
+ * (`ratio()` makes its denominator positive): the number fast path of Fixed's divide, at the value's
33
+ * own scale. Money's `divide` in money.ts inlines a copy of these steps, since a call there costs it
34
+ * about 4% on its benchmarks; test/divide.test.ts checks that the copies agree in every mode, and
35
+ * both against the proved kernel. It is `value × denominator / numerator`,
36
+ * rounded once by `divideAndRound`, which is the same fraction the inverse ratio would give, without
37
+ * building that ratio (bigint arithmetic and a gcd). Returns NaN when the number path doesn't apply,
38
+ * so the caller takes the bigint path:
39
+ * - a part that is NaN marks one that isn't a safe integer (`Ratio.n` and `Ratio.d`);
40
+ * - `value` and `denominator` are safe integers, so a float product beyond 2^53 - 1 can't round
41
+ * back into the safe range, and the bound check rejects every inexact product.
42
+ */
43
+ export function divideSafeByRatio(value, divisor, mode) {
44
+ const numerator = divisor.n;
45
+ const denominator = divisor.d;
46
+ // `x !== x` is true only for NaN
47
+ if (numerator !== numerator || denominator !== denominator) {
48
+ return NaN;
49
+ }
50
+ let dividend = value * denominator;
51
+ if (!(dividend <= MAX_SAFE_MINOR && dividend >= -MAX_SAFE_MINOR)) {
52
+ return NaN;
53
+ }
54
+ // divideAndRound needs a positive divisor: (−p)/(−n) is the same quotient
55
+ let positiveDivisor = numerator;
56
+ if (numerator < 0) {
57
+ dividend = 0 - dividend;
58
+ positiveDivisor = 0 - numerator;
59
+ }
60
+ return divideAndRound(dividend, positiveDivisor, mode);
61
+ }
30
62
  /**
31
63
  * dividend / divisor rounded with `mode`, for safe-integer dividends and divisor > 0. Exact: the
32
64
  * float quotient is only a first guess, corrected until the remainder has the dividend's sign and
@@ -1 +1 @@
1
- {"version":3,"file":"rounding.js","sourceRoot":"","sources":["../src/rounding.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,IAAI,0BAA0B,EAClD,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAyBpD;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,YAAY;IACpB,QAAQ,EAAE,WAAW;IACrB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,EAAE,EAAE,QAAQ;IACZ,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;CACqB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAiB,YAAY,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,OAAe,EAAE,IAAkB;IAClF,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,OAAO,QAAQ,GAAG,CAAC,CAAC,CAAC,2CAA2C;IAClE,CAAC;IACD,6FAA6F;IAC7F,QAAQ;IACR,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,C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Q,IAAI,CAAC,CAAC;YACd,SAAS,IAAI,OAAO,CAAC;QACvB,CAAC;IACH,CAAC;SAAM,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QACzB,QAAQ,IAAI,CAAC,CAAC;QACd,SAAS,IAAI,OAAO,CAAC;IACvB,CAAC;SAAM,IAAI,SAAS,IAAI,CAAC,OAAO,EAAE,CAAC;QACjC,QAAQ,IAAI,CAAC,CAAC;QACd,SAAS,IAAI,OAAO,CAAC;IACvB,CAAC;IAED,kGAAkG;IAClG,QAAQ;IACR,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,QAAQ,GAAG,CAAC,CAAC,CAAC,oBAAoB;IAC3C,CAAC;IACD,8FAA8F;IAC9F,iBAAiB;IACjB,OAAO,sBAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AAClF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,QAAgB,EAChB,OAAe,EACf,IAAkB;IAElB,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,0BAA0B,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAC7D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ducatjs/money",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Exact, fast, typed Money for TypeScript: integer minor units, bigint fallback, Stripe/Adyen views, allocation, cash rounding, Prisma helpers.",
5
5
  "homepage": "https://github.com/public/ducat#readme",
6
6
  "bugs": {
package/src/fixed.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  DEFAULT_ROUNDING,
26
26
  divideAndRound,
27
27
  divideAndRoundBigint,
28
+ divideSafeByRatio,
28
29
  RoundingError,
29
30
  type RoundingMode,
30
31
  } from './rounding.js';
@@ -177,6 +178,17 @@ export class Fixed {
177
178
  if (divisorRatio.num === 0n) {
178
179
  throw new RangeError('Division by zero');
179
180
  }
181
+
182
+ // The fast path Money's divide takes: a safe-integer value and a divisor whose ratio parts are
183
+ // safe integers, at this value's scale, without building the inverse ratio.
184
+ const value = this.value;
185
+ if (typeof value === 'number' && scale === this.scale) {
186
+ const quotient = divideSafeByRatio(value, divisorRatio, rounding);
187
+ if (quotient === quotient) {
188
+ return make(quotient, scale);
189
+ }
190
+ }
191
+
180
192
  return multiplyByRatio(this, ratio(divisorRatio.den, divisorRatio.num), rounding, scale);
181
193
  }
182
194
 
package/src/money.ts CHANGED
@@ -721,6 +721,8 @@ export function divide<C extends string>(
721
721
  // dividend + divisor exceeds the safe range).
722
722
  // A rounding policy (a function, not a mode string) must not take this path: it rounds to its own
723
723
  // scale and increment.
724
+ // divideSafeByRatio in rounding.ts is the same steps as a function, for Fixed; a call here costs
725
+ // about 4% on the divide benchmarks. test/divide.test.ts checks that the two copies agree.
724
726
  const minor = money.minor;
725
727
  const numerator = divisorRatio.n;
726
728
  const denominator = divisorRatio.d;
@@ -1,11 +1,12 @@
1
1
  /** `@ducatjs/money/adyen`: Adyen's minor-unit view. Importing this module adds `toAdyen`. */
2
2
  import { toAdyen } from '../adyen.js';
3
- import { extendMoney, type Money } from '../money.js';
3
+ import type { Money } from '../index.js';
4
+ import { extendMoney } from '../money.js';
4
5
  import type { RoundingMode } from '../rounding.js';
5
6
 
6
7
  export * from '../adyen.js';
7
8
 
8
- declare module '../money.js' {
9
+ declare module '../index.js' {
9
10
  interface Money<C extends string> {
10
11
  /**
11
12
  * Adyen `amount` object: `money('15000', 'IDR').toAdyen()` is `{ value: 15000, currency: 'IDR'
@@ -14,11 +14,12 @@ import {
14
14
  type Tranche,
15
15
  type Weight,
16
16
  } from '../allocate.js';
17
- import { extendMoney, type Money } from '../money.js';
17
+ import type { Money } from '../index.js';
18
+ import { extendMoney } from '../money.js';
18
19
 
19
20
  export * from '../allocate.js';
20
21
 
21
- declare module '../money.js' {
22
+ declare module '../index.js' {
22
23
  interface Money<C extends string> {
23
24
  /** Splits by weights; the parts always sum to this. */
24
25
  allocate(weights: readonly Weight[], options?: AllocateOptions): Money<C>[];
@@ -2,11 +2,12 @@
2
2
  * `@ducatjs/money/braintree`: Braintree's amount view. Importing this module adds `toBraintree`.
3
3
  */
4
4
  import { toBraintree, type BraintreeAmountOptions } from '../braintree.js';
5
- import { extendMoney, type Money } from '../money.js';
5
+ import type { Money } from '../index.js';
6
+ import { extendMoney } from '../money.js';
6
7
 
7
8
  export * from '../braintree.js';
8
9
 
9
- declare module '../money.js' {
10
+ declare module '../index.js' {
10
11
  interface Money<C extends string> {
11
12
  /** The exact `amount` string for Braintree: `money('10', 'USD').toBraintree()` is '10.00'. */
12
13
  toBraintree(options?: BraintreeAmountOptions): string;
@@ -3,12 +3,13 @@
3
3
  * rounding to an increment. Importing this module adds the methods below.
4
4
  */
5
5
  import { cashRound, roundToIncrement, type CashRoundOptions } from '../cash.js';
6
- import { extendMoney, type Money } from '../money.js';
6
+ import type { Money } from '../index.js';
7
+ import { extendMoney } from '../money.js';
7
8
  import type { RoundingMode } from '../rounding.js';
8
9
 
9
10
  export * from '../cash.js';
10
11
 
11
- declare module '../money.js' {
12
+ declare module '../index.js' {
12
13
  interface Money<C extends string> {
13
14
  /**
14
15
  * Rounds a cash total to the local cash step (CHF 0.05, SEK 1, ...); unchanged when no rule
@@ -3,11 +3,12 @@
3
3
  * and `toCheckoutAmount`.
4
4
  */
5
5
  import { toCheckout, toCheckoutAmount, type CheckoutAmountOptions } from '../checkout.js';
6
- import { extendMoney, type Money } from '../money.js';
6
+ import type { Money } from '../index.js';
7
+ import { extendMoney } from '../money.js';
7
8
 
8
9
  export * from '../checkout.js';
9
10
 
10
- declare module '../money.js' {
11
+ declare module '../index.js' {
11
12
  interface Money<C extends string> {
12
13
  /**
13
14
  * The integer `amount` to send to Checkout.com: `money('5000', 'CLP').toCheckoutAmount()` is
@@ -4,14 +4,15 @@
4
4
  */
5
5
  import { convert } from '../convert.js';
6
6
  import type { Factor } from '../decimal.js';
7
- import { extendMoney, type CurrencyInput, type Money, type RoundingInput } from '../money.js';
7
+ import type { Money } from '../index.js';
8
+ import { extendMoney, type CurrencyInput, type RoundingInput } from '../money.js';
8
9
  import type { ProviderConvertOptions } from '../convert.js';
9
10
  import type { RateProvider } from '../provider.js';
10
11
  import type { ConvertOptions, Rate } from '../rate.js';
11
12
 
12
13
  export * from '../convert.js';
13
14
 
14
- declare module '../money.js' {
15
+ declare module '../index.js' {
15
16
  interface Money<C extends string> {
16
17
  /** Converts at a Rate, rounding once: `eur.convert(eurUsd, 'halfEven')`. */
17
18
  convert<To extends string>(
@@ -3,11 +3,12 @@
3
3
  * `Money#exact`.
4
4
  */
5
5
  import { exact, type ExactMoney } from '../exact.js';
6
- import { extendMoney, type Money } from '../money.js';
6
+ import type { Money } from '../index.js';
7
+ import { extendMoney } from '../money.js';
7
8
 
8
9
  export * from '../exact.js';
9
10
 
10
- declare module '../money.js' {
11
+ declare module '../index.js' {
11
12
  interface Money<C extends string> {
12
13
  /**
13
14
  * The exact value, for chained arithmetic that rounds once: `price.exact().divide(3).round()`.
@@ -3,11 +3,12 @@
3
3
  * Money. Importing this module adds `Money#toFixedPoint()`.
4
4
  */
5
5
  import { moneyToFixed, type Fixed } from '../fixed.js';
6
- import { extendMoney, type Money } from '../money.js';
6
+ import type { Money } from '../index.js';
7
+ import { extendMoney } from '../money.js';
7
8
 
8
9
  export * from '../fixed.js';
9
10
 
10
- declare module '../money.js' {
11
+ declare module '../index.js' {
11
12
  interface Money<C extends string> {
12
13
  /**
13
14
  * The exact Fixed of this amount, at its scale: `money('12.34', 'EUR').toFixedPoint()` is
@@ -3,11 +3,12 @@
3
3
  * below.
4
4
  */
5
5
  import { format, formatToParts } from '../format.js';
6
- import { extendMoney, type Money } from '../money.js';
6
+ import type { Money } from '../index.js';
7
+ import { extendMoney } from '../money.js';
7
8
 
8
9
  export * from '../format.js';
9
10
 
10
- declare module '../money.js' {
11
+ declare module '../index.js' {
11
12
  interface Money<C extends string> {
12
13
  /** Locale formatting via Intl: `price.format('de-DE')` gives "19,99 €" */
13
14
  format(locale?: string, options?: Intl.NumberFormatOptions): string;
@@ -1,10 +1,11 @@
1
1
  /** `@ducatjs/money/klarna`: Klarna's amount view. Importing this module adds `toKlarna`. */
2
2
  import { toKlarna, type KlarnaAmountOptions } from '../klarna.js';
3
- import { extendMoney, type Money } from '../money.js';
3
+ import type { Money } from '../index.js';
4
+ import { extendMoney } from '../money.js';
4
5
 
5
6
  export * from '../klarna.js';
6
7
 
7
- declare module '../money.js' {
8
+ declare module '../index.js' {
8
9
  interface Money<C extends string> {
9
10
  /** The integer for any Klarna amount field: `money('25', 'EUR').toKlarna()` is 2500. */
10
11
  toKlarna(options?: KlarnaAmountOptions): number;
@@ -2,12 +2,13 @@
2
2
  * `@ducatjs/money/paypal`: PayPal's amount view. Importing this module adds `toPayPal` and
3
3
  * `toPayPalValue`.
4
4
  */
5
- import { extendMoney, type Money } from '../money.js';
5
+ import type { Money } from '../index.js';
6
+ import { extendMoney } from '../money.js';
6
7
  import { toPayPal, toPayPalValue, type PayPalAmountOptions } from '../paypal.js';
7
8
 
8
9
  export * from '../paypal.js';
9
10
 
10
- declare module '../money.js' {
11
+ declare module '../index.js' {
11
12
  interface Money<C extends string> {
12
13
  /** The exact `value` string for PayPal: `money('1000', 'HUF').toPayPalValue()` is '1000'. */
13
14
  toPayPalValue(options?: PayPalAmountOptions): string;
@@ -2,12 +2,13 @@
2
2
  * `@ducatjs/money/prisma`: Prisma and SQL column helpers. Importing this module adds
3
3
  * `toDecimalValue`.
4
4
  */
5
- import { extendMoney, type Money } from '../money.js';
5
+ import type { Money } from '../index.js';
6
+ import { extendMoney } from '../money.js';
6
7
  import { toDecimalValue } from '../prisma.js';
7
8
 
8
9
  export * from '../prisma.js';
9
10
 
10
- declare module '../money.js' {
11
+ declare module '../index.js' {
11
12
  interface Money<C extends string> {
12
13
  /** A Decimal for a NUMERIC column: `m.toDecimalValue(Prisma.Decimal)`. */
13
14
  toDecimalValue<D>(Decimal: new (value: string) => D): D;
@@ -2,12 +2,13 @@
2
2
  * `@ducatjs/money/stripe`: Stripe's minor-unit view. Importing this module adds `toStripe` and
3
3
  * `toStripeAmount`.
4
4
  */
5
- import { extendMoney, type Money } from '../money.js';
5
+ import type { Money } from '../index.js';
6
+ import { extendMoney } from '../money.js';
6
7
  import { toStripe, toStripeAmount, type StripeAmountOptions } from '../stripe.js';
7
8
 
8
9
  export * from '../stripe.js';
9
10
 
10
- declare module '../money.js' {
11
+ declare module '../index.js' {
11
12
  interface Money<C extends string> {
12
13
  /** The integer `amount` to send to Stripe: `money('5', 'ISK').toStripeAmount()` is 500. */
13
14
  toStripeAmount(options?: StripeAmountOptions): number;
@@ -3,12 +3,13 @@
3
3
  * methods below.
4
4
  */
5
5
  import type { Factor } from '../decimal.js';
6
- import { extendMoney, type Money, type RoundingInput } from '../money.js';
6
+ import type { Money } from '../index.js';
7
+ import { extendMoney, type RoundingInput } from '../money.js';
7
8
  import { addTax, discount, extractTax, percentage, type TaxBreakdown } from '../tax.js';
8
9
 
9
10
  export * from '../tax.js';
10
11
 
11
- declare module '../money.js' {
12
+ declare module '../index.js' {
12
13
  interface Money<C extends string> {
13
14
  /** `percent`% of this, e.g. `price.percentage(15, 'halfEven')` */
14
15
  percentage(percent: Factor, rounding?: RoundingInput): Money<C>;
package/src/rounding.ts CHANGED
@@ -2,6 +2,7 @@ import {
2
2
  divideAndRoundBigint as provedDivideAndRoundBigint,
3
3
  roundTruncatedQuotient,
4
4
  } from './generated/kernel.js';
5
+ import type { Ratio } from './decimal.js';
5
6
  import { RoundingError } from './rounding-error.js';
6
7
 
7
8
  /**
@@ -58,6 +59,39 @@ export { RoundingError };
58
59
 
59
60
  const MAX_SAFE_MINOR = Number.MAX_SAFE_INTEGER;
60
61
 
62
+ /**
63
+ * @internal `value / divisor` rounded with `mode`, for a safe-integer `value` and a reduced ratio
64
+ * (`ratio()` makes its denominator positive): the number fast path of Fixed's divide, at the value's
65
+ * own scale. Money's `divide` in money.ts inlines a copy of these steps, since a call there costs it
66
+ * about 4% on its benchmarks; test/divide.test.ts checks that the copies agree in every mode, and
67
+ * both against the proved kernel. It is `value × denominator / numerator`,
68
+ * rounded once by `divideAndRound`, which is the same fraction the inverse ratio would give, without
69
+ * building that ratio (bigint arithmetic and a gcd). Returns NaN when the number path doesn't apply,
70
+ * so the caller takes the bigint path:
71
+ * - a part that is NaN marks one that isn't a safe integer (`Ratio.n` and `Ratio.d`);
72
+ * - `value` and `denominator` are safe integers, so a float product beyond 2^53 - 1 can't round
73
+ * back into the safe range, and the bound check rejects every inexact product.
74
+ */
75
+ export function divideSafeByRatio(value: number, divisor: Ratio, mode: RoundingMode): number {
76
+ const numerator = divisor.n;
77
+ const denominator = divisor.d;
78
+ // `x !== x` is true only for NaN
79
+ if (numerator !== numerator || denominator !== denominator) {
80
+ return NaN;
81
+ }
82
+ let dividend = value * denominator;
83
+ if (!(dividend <= MAX_SAFE_MINOR && dividend >= -MAX_SAFE_MINOR)) {
84
+ return NaN;
85
+ }
86
+ // divideAndRound needs a positive divisor: (−p)/(−n) is the same quotient
87
+ let positiveDivisor = numerator;
88
+ if (numerator < 0) {
89
+ dividend = 0 - dividend;
90
+ positiveDivisor = 0 - numerator;
91
+ }
92
+ return divideAndRound(dividend, positiveDivisor, mode);
93
+ }
94
+
61
95
  /**
62
96
  * dividend / divisor rounded with `mode`, for safe-integer dividends and divisor > 0. Exact: the
63
97
  * float quotient is only a first guess, corrected until the remainder has the dividend's sign and