iso-price 1.0.3

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 (85) hide show
  1. package/LICENSE +21 -0
  2. package/dist/contract/index.d.ts +25 -0
  3. package/dist/contract/index.js +60 -0
  4. package/dist/contract/index.js.map +1 -0
  5. package/dist/domain.objects/IsoCurrency.d.ts +63 -0
  6. package/dist/domain.objects/IsoCurrency.js +70 -0
  7. package/dist/domain.objects/IsoCurrency.js.map +1 -0
  8. package/dist/domain.objects/IsoPrice.d.ts +16 -0
  9. package/dist/domain.objects/IsoPrice.js +3 -0
  10. package/dist/domain.objects/IsoPrice.js.map +1 -0
  11. package/dist/domain.objects/IsoPriceExponent.d.ts +28 -0
  12. package/dist/domain.objects/IsoPriceExponent.js +33 -0
  13. package/dist/domain.objects/IsoPriceExponent.js.map +1 -0
  14. package/dist/domain.objects/IsoPriceHuman.d.ts +19 -0
  15. package/dist/domain.objects/IsoPriceHuman.js +3 -0
  16. package/dist/domain.objects/IsoPriceHuman.js.map +1 -0
  17. package/dist/domain.objects/IsoPriceRoundMode.d.ts +23 -0
  18. package/dist/domain.objects/IsoPriceRoundMode.js +28 -0
  19. package/dist/domain.objects/IsoPriceRoundMode.js.map +1 -0
  20. package/dist/domain.objects/IsoPriceShape.d.ts +30 -0
  21. package/dist/domain.objects/IsoPriceShape.js +3 -0
  22. package/dist/domain.objects/IsoPriceShape.js.map +1 -0
  23. package/dist/domain.objects/IsoPriceWords.d.ts +20 -0
  24. package/dist/domain.objects/IsoPriceWords.js +3 -0
  25. package/dist/domain.objects/IsoPriceWords.js.map +1 -0
  26. package/dist/domain.operations/arithmetic/allocatePrice.d.ts +48 -0
  27. package/dist/domain.operations/arithmetic/allocatePrice.js +167 -0
  28. package/dist/domain.operations/arithmetic/allocatePrice.js.map +1 -0
  29. package/dist/domain.operations/arithmetic/dividePrice.d.ts +40 -0
  30. package/dist/domain.operations/arithmetic/dividePrice.js +127 -0
  31. package/dist/domain.operations/arithmetic/dividePrice.js.map +1 -0
  32. package/dist/domain.operations/arithmetic/multiplyPrice.d.ts +38 -0
  33. package/dist/domain.operations/arithmetic/multiplyPrice.js +89 -0
  34. package/dist/domain.operations/arithmetic/multiplyPrice.js.map +1 -0
  35. package/dist/domain.operations/arithmetic/subPrices.d.ts +28 -0
  36. package/dist/domain.operations/arithmetic/subPrices.js +62 -0
  37. package/dist/domain.operations/arithmetic/subPrices.js.map +1 -0
  38. package/dist/domain.operations/arithmetic/sumPrices.d.ts +44 -0
  39. package/dist/domain.operations/arithmetic/sumPrices.js +88 -0
  40. package/dist/domain.operations/arithmetic/sumPrices.js.map +1 -0
  41. package/dist/domain.operations/cast/asIsoPrice.d.ts +35 -0
  42. package/dist/domain.operations/cast/asIsoPrice.js +117 -0
  43. package/dist/domain.operations/cast/asIsoPrice.js.map +1 -0
  44. package/dist/domain.operations/cast/asIsoPriceHuman.d.ts +25 -0
  45. package/dist/domain.operations/cast/asIsoPriceHuman.js +106 -0
  46. package/dist/domain.operations/cast/asIsoPriceHuman.js.map +1 -0
  47. package/dist/domain.operations/cast/asIsoPriceShape.d.ts +25 -0
  48. package/dist/domain.operations/cast/asIsoPriceShape.js +164 -0
  49. package/dist/domain.operations/cast/asIsoPriceShape.js.map +1 -0
  50. package/dist/domain.operations/cast/asIsoPriceWords.d.ts +25 -0
  51. package/dist/domain.operations/cast/asIsoPriceWords.js +103 -0
  52. package/dist/domain.operations/cast/asIsoPriceWords.js.map +1 -0
  53. package/dist/domain.operations/guard/isIsoPrice.d.ts +18 -0
  54. package/dist/domain.operations/guard/isIsoPrice.js +29 -0
  55. package/dist/domain.operations/guard/isIsoPrice.js.map +1 -0
  56. package/dist/domain.operations/guard/isIsoPriceHuman.d.ts +24 -0
  57. package/dist/domain.operations/guard/isIsoPriceHuman.js +76 -0
  58. package/dist/domain.operations/guard/isIsoPriceHuman.js.map +1 -0
  59. package/dist/domain.operations/guard/isIsoPriceShape.d.ts +29 -0
  60. package/dist/domain.operations/guard/isIsoPriceShape.js +50 -0
  61. package/dist/domain.operations/guard/isIsoPriceShape.js.map +1 -0
  62. package/dist/domain.operations/guard/isIsoPriceWords.d.ts +24 -0
  63. package/dist/domain.operations/guard/isIsoPriceWords.js +48 -0
  64. package/dist/domain.operations/guard/isIsoPriceWords.js.map +1 -0
  65. package/dist/domain.operations/precision/getIsoPriceExponentByCurrency.d.ts +15 -0
  66. package/dist/domain.operations/precision/getIsoPriceExponentByCurrency.js +49 -0
  67. package/dist/domain.operations/precision/getIsoPriceExponentByCurrency.js.map +1 -0
  68. package/dist/domain.operations/precision/roundPrice.d.ts +25 -0
  69. package/dist/domain.operations/precision/roundPrice.js +24 -0
  70. package/dist/domain.operations/precision/roundPrice.js.map +1 -0
  71. package/dist/domain.operations/precision/setPricePrecision.d.ts +29 -0
  72. package/dist/domain.operations/precision/setPricePrecision.js +119 -0
  73. package/dist/domain.operations/precision/setPricePrecision.js.map +1 -0
  74. package/dist/domain.operations/statistics/calcPriceAvg.d.ts +21 -0
  75. package/dist/domain.operations/statistics/calcPriceAvg.js +92 -0
  76. package/dist/domain.operations/statistics/calcPriceAvg.js.map +1 -0
  77. package/dist/domain.operations/statistics/calcPriceStdev.d.ts +23 -0
  78. package/dist/domain.operations/statistics/calcPriceStdev.js +137 -0
  79. package/dist/domain.operations/statistics/calcPriceStdev.js.map +1 -0
  80. package/dist/index.d.ts +1 -0
  81. package/dist/index.js +18 -0
  82. package/dist/index.js.map +1 -0
  83. package/license.md +21 -0
  84. package/package.json +102 -0
  85. package/readme.md +373 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Uladzimir Kasacheuski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ export { IsoCurrency } from '../domain.objects/IsoCurrency';
2
+ export type { IsoPrice } from '../domain.objects/IsoPrice';
3
+ export { IsoPriceExponent } from '../domain.objects/IsoPriceExponent';
4
+ export type { IsoPriceHuman } from '../domain.objects/IsoPriceHuman';
5
+ export { IsoPriceRoundMode } from '../domain.objects/IsoPriceRoundMode';
6
+ export type { IsoPriceShape } from '../domain.objects/IsoPriceShape';
7
+ export type { IsoPriceWords } from '../domain.objects/IsoPriceWords';
8
+ export { allocatePrice, priceAllocate, } from '../domain.operations/arithmetic/allocatePrice';
9
+ export { dividePrice, priceDivide, } from '../domain.operations/arithmetic/dividePrice';
10
+ export { multiplyPrice, priceMultiply, } from '../domain.operations/arithmetic/multiplyPrice';
11
+ export { priceSub, subPrices, } from '../domain.operations/arithmetic/subPrices';
12
+ export { addPrices, priceAdd, priceSum, sumPrices, } from '../domain.operations/arithmetic/sumPrices';
13
+ export { asIsoPrice } from '../domain.operations/cast/asIsoPrice';
14
+ export { asIsoPriceHuman } from '../domain.operations/cast/asIsoPriceHuman';
15
+ export { asIsoPriceShape } from '../domain.operations/cast/asIsoPriceShape';
16
+ export { asIsoPriceWords } from '../domain.operations/cast/asIsoPriceWords';
17
+ export { isIsoPrice } from '../domain.operations/guard/isIsoPrice';
18
+ export { isIsoPriceHuman } from '../domain.operations/guard/isIsoPriceHuman';
19
+ export { isIsoPriceShape } from '../domain.operations/guard/isIsoPriceShape';
20
+ export { isIsoPriceWords } from '../domain.operations/guard/isIsoPriceWords';
21
+ export { getIsoPriceExponentByCurrency } from '../domain.operations/precision/getIsoPriceExponentByCurrency';
22
+ export { roundPrice } from '../domain.operations/precision/roundPrice';
23
+ export { setPricePrecision } from '../domain.operations/precision/setPricePrecision';
24
+ export { calcPriceAvg } from '../domain.operations/statistics/calcPriceAvg';
25
+ export { calcPriceStdev } from '../domain.operations/statistics/calcPriceStdev';
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ // iso-price public contract
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.calcPriceStdev = exports.calcPriceAvg = exports.setPricePrecision = exports.roundPrice = exports.getIsoPriceExponentByCurrency = exports.isIsoPriceWords = exports.isIsoPriceShape = exports.isIsoPriceHuman = exports.isIsoPrice = exports.asIsoPriceWords = exports.asIsoPriceShape = exports.asIsoPriceHuman = exports.asIsoPrice = exports.sumPrices = exports.priceSum = exports.priceAdd = exports.addPrices = exports.subPrices = exports.priceSub = exports.priceMultiply = exports.multiplyPrice = exports.priceDivide = exports.dividePrice = exports.priceAllocate = exports.allocatePrice = exports.IsoPriceRoundMode = exports.IsoPriceExponent = exports.IsoCurrency = void 0;
5
+ var IsoCurrency_1 = require("../domain.objects/IsoCurrency");
6
+ Object.defineProperty(exports, "IsoCurrency", { enumerable: true, get: function () { return IsoCurrency_1.IsoCurrency; } });
7
+ // enums
8
+ var IsoPriceExponent_1 = require("../domain.objects/IsoPriceExponent");
9
+ Object.defineProperty(exports, "IsoPriceExponent", { enumerable: true, get: function () { return IsoPriceExponent_1.IsoPriceExponent; } });
10
+ var IsoPriceRoundMode_1 = require("../domain.objects/IsoPriceRoundMode");
11
+ Object.defineProperty(exports, "IsoPriceRoundMode", { enumerable: true, get: function () { return IsoPriceRoundMode_1.IsoPriceRoundMode; } });
12
+ var allocatePrice_1 = require("../domain.operations/arithmetic/allocatePrice");
13
+ Object.defineProperty(exports, "allocatePrice", { enumerable: true, get: function () { return allocatePrice_1.allocatePrice; } });
14
+ Object.defineProperty(exports, "priceAllocate", { enumerable: true, get: function () { return allocatePrice_1.priceAllocate; } });
15
+ var dividePrice_1 = require("../domain.operations/arithmetic/dividePrice");
16
+ Object.defineProperty(exports, "dividePrice", { enumerable: true, get: function () { return dividePrice_1.dividePrice; } });
17
+ Object.defineProperty(exports, "priceDivide", { enumerable: true, get: function () { return dividePrice_1.priceDivide; } });
18
+ var multiplyPrice_1 = require("../domain.operations/arithmetic/multiplyPrice");
19
+ Object.defineProperty(exports, "multiplyPrice", { enumerable: true, get: function () { return multiplyPrice_1.multiplyPrice; } });
20
+ Object.defineProperty(exports, "priceMultiply", { enumerable: true, get: function () { return multiplyPrice_1.priceMultiply; } });
21
+ var subPrices_1 = require("../domain.operations/arithmetic/subPrices");
22
+ Object.defineProperty(exports, "priceSub", { enumerable: true, get: function () { return subPrices_1.priceSub; } });
23
+ Object.defineProperty(exports, "subPrices", { enumerable: true, get: function () { return subPrices_1.subPrices; } });
24
+ // arithmetic operations
25
+ var sumPrices_1 = require("../domain.operations/arithmetic/sumPrices");
26
+ Object.defineProperty(exports, "addPrices", { enumerable: true, get: function () { return sumPrices_1.addPrices; } });
27
+ Object.defineProperty(exports, "priceAdd", { enumerable: true, get: function () { return sumPrices_1.priceAdd; } });
28
+ Object.defineProperty(exports, "priceSum", { enumerable: true, get: function () { return sumPrices_1.priceSum; } });
29
+ Object.defineProperty(exports, "sumPrices", { enumerable: true, get: function () { return sumPrices_1.sumPrices; } });
30
+ // cast functions
31
+ var asIsoPrice_1 = require("../domain.operations/cast/asIsoPrice");
32
+ Object.defineProperty(exports, "asIsoPrice", { enumerable: true, get: function () { return asIsoPrice_1.asIsoPrice; } });
33
+ var asIsoPriceHuman_1 = require("../domain.operations/cast/asIsoPriceHuman");
34
+ Object.defineProperty(exports, "asIsoPriceHuman", { enumerable: true, get: function () { return asIsoPriceHuman_1.asIsoPriceHuman; } });
35
+ var asIsoPriceShape_1 = require("../domain.operations/cast/asIsoPriceShape");
36
+ Object.defineProperty(exports, "asIsoPriceShape", { enumerable: true, get: function () { return asIsoPriceShape_1.asIsoPriceShape; } });
37
+ var asIsoPriceWords_1 = require("../domain.operations/cast/asIsoPriceWords");
38
+ Object.defineProperty(exports, "asIsoPriceWords", { enumerable: true, get: function () { return asIsoPriceWords_1.asIsoPriceWords; } });
39
+ var isIsoPrice_1 = require("../domain.operations/guard/isIsoPrice");
40
+ Object.defineProperty(exports, "isIsoPrice", { enumerable: true, get: function () { return isIsoPrice_1.isIsoPrice; } });
41
+ var isIsoPriceHuman_1 = require("../domain.operations/guard/isIsoPriceHuman");
42
+ Object.defineProperty(exports, "isIsoPriceHuman", { enumerable: true, get: function () { return isIsoPriceHuman_1.isIsoPriceHuman; } });
43
+ var isIsoPriceShape_1 = require("../domain.operations/guard/isIsoPriceShape");
44
+ Object.defineProperty(exports, "isIsoPriceShape", { enumerable: true, get: function () { return isIsoPriceShape_1.isIsoPriceShape; } });
45
+ // type guards
46
+ var isIsoPriceWords_1 = require("../domain.operations/guard/isIsoPriceWords");
47
+ Object.defineProperty(exports, "isIsoPriceWords", { enumerable: true, get: function () { return isIsoPriceWords_1.isIsoPriceWords; } });
48
+ // precision operations
49
+ var getIsoPriceExponentByCurrency_1 = require("../domain.operations/precision/getIsoPriceExponentByCurrency");
50
+ Object.defineProperty(exports, "getIsoPriceExponentByCurrency", { enumerable: true, get: function () { return getIsoPriceExponentByCurrency_1.getIsoPriceExponentByCurrency; } });
51
+ var roundPrice_1 = require("../domain.operations/precision/roundPrice");
52
+ Object.defineProperty(exports, "roundPrice", { enumerable: true, get: function () { return roundPrice_1.roundPrice; } });
53
+ var setPricePrecision_1 = require("../domain.operations/precision/setPricePrecision");
54
+ Object.defineProperty(exports, "setPricePrecision", { enumerable: true, get: function () { return setPricePrecision_1.setPricePrecision; } });
55
+ // statistics operations
56
+ var calcPriceAvg_1 = require("../domain.operations/statistics/calcPriceAvg");
57
+ Object.defineProperty(exports, "calcPriceAvg", { enumerable: true, get: function () { return calcPriceAvg_1.calcPriceAvg; } });
58
+ var calcPriceStdev_1 = require("../domain.operations/statistics/calcPriceStdev");
59
+ Object.defineProperty(exports, "calcPriceStdev", { enumerable: true, get: function () { return calcPriceStdev_1.calcPriceStdev; } });
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":";AAAA,4BAA4B;;;AAE5B,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AAEpB,QAAQ;AACR,uEAAsE;AAA7D,oHAAA,gBAAgB,OAAA;AAEzB,yEAAwE;AAA/D,sHAAA,iBAAiB,OAAA;AAI1B,+EAGuD;AAFrD,8GAAA,aAAa,OAAA;AACb,8GAAA,aAAa,OAAA;AAEf,2EAGqD;AAFnD,0GAAA,WAAW,OAAA;AACX,0GAAA,WAAW,OAAA;AAEb,+EAGuD;AAFrD,8GAAA,aAAa,OAAA;AACb,8GAAA,aAAa,OAAA;AAEf,uEAGmD;AAFjD,qGAAA,QAAQ,OAAA;AACR,sGAAA,SAAS,OAAA;AAEX,wBAAwB;AACxB,uEAKmD;AAJjD,sGAAA,SAAS,OAAA;AACT,qGAAA,QAAQ,OAAA;AACR,qGAAA,QAAQ,OAAA;AACR,sGAAA,SAAS,OAAA;AAEX,iBAAiB;AACjB,mEAAkE;AAAzD,wGAAA,UAAU,OAAA;AACnB,6EAA4E;AAAnE,kHAAA,eAAe,OAAA;AACxB,6EAA4E;AAAnE,kHAAA,eAAe,OAAA;AACxB,6EAA4E;AAAnE,kHAAA,eAAe,OAAA;AACxB,oEAAmE;AAA1D,wGAAA,UAAU,OAAA;AACnB,8EAA6E;AAApE,kHAAA,eAAe,OAAA;AACxB,8EAA6E;AAApE,kHAAA,eAAe,OAAA;AACxB,cAAc;AACd,8EAA6E;AAApE,kHAAA,eAAe,OAAA;AACxB,uBAAuB;AACvB,8GAA6G;AAApG,8IAAA,6BAA6B,OAAA;AACtC,wEAAuE;AAA9D,wGAAA,UAAU,OAAA;AACnB,sFAAqF;AAA5E,sHAAA,iBAAiB,OAAA;AAC1B,wBAAwB;AACxB,6EAA4E;AAAnE,4GAAA,YAAY,OAAA;AACrB,iFAAgF;AAAvE,gHAAA,cAAc,OAAA"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * .what = enum of iso 4217 currency codes for type-safe price operations
3
+ * .why = provides compile-time safety for the most common currencies
4
+ *
5
+ * includes:
6
+ * - top 21 currencies by forex trade volume (~$7 trillion daily)
7
+ * - 4 currencies with 3-decimal exponent (BHD, KWD, OMR, TND)
8
+ *
9
+ * note: custom currencies (BTC, ETH, etc) are supported via string generics
10
+ * this enum is for convenience, not restriction
11
+ */
12
+ export declare enum IsoCurrency {
13
+ /** US Dollar — ~90% of forex transactions */
14
+ USD = "USD",
15
+ /** Euro — 20 eurozone countries */
16
+ EUR = "EUR",
17
+ /** Japanese Yen — major reserve currency, 0-decimal */
18
+ JPY = "JPY",
19
+ /** British Pound — London as global finance hub */
20
+ GBP = "GBP",
21
+ /** Chinese Yuan — rapid growth in trade share */
22
+ CNY = "CNY",
23
+ /** Australian Dollar — commodity-linked */
24
+ AUD = "AUD",
25
+ /** Canadian Dollar — oil price correlation */
26
+ CAD = "CAD",
27
+ /** Swiss Franc — safe-haven currency */
28
+ CHF = "CHF",
29
+ /** Hong Kong Dollar — pegged to USD */
30
+ HKD = "HKD",
31
+ /** New Zealand Dollar — commodity-linked */
32
+ NZD = "NZD",
33
+ /** Swedish Krona — nordic economy */
34
+ SEK = "SEK",
35
+ /** South Korean Won — tech export economy, 0-decimal */
36
+ KRW = "KRW",
37
+ /** Singapore Dollar — asian finance hub */
38
+ SGD = "SGD",
39
+ /** Norwegian Krone — oil-linked */
40
+ NOK = "NOK",
41
+ /** Mexican Peso — growth market */
42
+ MXN = "MXN",
43
+ /** Indian Rupee — large population economy */
44
+ INR = "INR",
45
+ /** South African Rand — commodity-linked */
46
+ ZAR = "ZAR",
47
+ /** Brazilian Real — growth market */
48
+ BRL = "BRL",
49
+ /** Danish Krone — pegged to EUR */
50
+ DKK = "DKK",
51
+ /** Polish Zloty — EU non-eurozone */
52
+ PLN = "PLN",
53
+ /** Thai Baht — southeast asian economy */
54
+ THB = "THB",
55
+ /** Bahraini Dinar — 3-decimal, fils */
56
+ BHD = "BHD",
57
+ /** Kuwaiti Dinar — 3-decimal, fils */
58
+ KWD = "KWD",
59
+ /** Omani Rial — 3-decimal, baisa */
60
+ OMR = "OMR",
61
+ /** Tunisian Dinar — 3-decimal, millimes */
62
+ TND = "TND"
63
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsoCurrency = void 0;
4
+ /**
5
+ * .what = enum of iso 4217 currency codes for type-safe price operations
6
+ * .why = provides compile-time safety for the most common currencies
7
+ *
8
+ * includes:
9
+ * - top 21 currencies by forex trade volume (~$7 trillion daily)
10
+ * - 4 currencies with 3-decimal exponent (BHD, KWD, OMR, TND)
11
+ *
12
+ * note: custom currencies (BTC, ETH, etc) are supported via string generics
13
+ * this enum is for convenience, not restriction
14
+ */
15
+ var IsoCurrency;
16
+ (function (IsoCurrency) {
17
+ // top 21 by forex trade volume
18
+ /** US Dollar — ~90% of forex transactions */
19
+ IsoCurrency["USD"] = "USD";
20
+ /** Euro — 20 eurozone countries */
21
+ IsoCurrency["EUR"] = "EUR";
22
+ /** Japanese Yen — major reserve currency, 0-decimal */
23
+ IsoCurrency["JPY"] = "JPY";
24
+ /** British Pound — London as global finance hub */
25
+ IsoCurrency["GBP"] = "GBP";
26
+ /** Chinese Yuan — rapid growth in trade share */
27
+ IsoCurrency["CNY"] = "CNY";
28
+ /** Australian Dollar — commodity-linked */
29
+ IsoCurrency["AUD"] = "AUD";
30
+ /** Canadian Dollar — oil price correlation */
31
+ IsoCurrency["CAD"] = "CAD";
32
+ /** Swiss Franc — safe-haven currency */
33
+ IsoCurrency["CHF"] = "CHF";
34
+ /** Hong Kong Dollar — pegged to USD */
35
+ IsoCurrency["HKD"] = "HKD";
36
+ /** New Zealand Dollar — commodity-linked */
37
+ IsoCurrency["NZD"] = "NZD";
38
+ /** Swedish Krona — nordic economy */
39
+ IsoCurrency["SEK"] = "SEK";
40
+ /** South Korean Won — tech export economy, 0-decimal */
41
+ IsoCurrency["KRW"] = "KRW";
42
+ /** Singapore Dollar — asian finance hub */
43
+ IsoCurrency["SGD"] = "SGD";
44
+ /** Norwegian Krone — oil-linked */
45
+ IsoCurrency["NOK"] = "NOK";
46
+ /** Mexican Peso — growth market */
47
+ IsoCurrency["MXN"] = "MXN";
48
+ /** Indian Rupee — large population economy */
49
+ IsoCurrency["INR"] = "INR";
50
+ /** South African Rand — commodity-linked */
51
+ IsoCurrency["ZAR"] = "ZAR";
52
+ /** Brazilian Real — growth market */
53
+ IsoCurrency["BRL"] = "BRL";
54
+ /** Danish Krone — pegged to EUR */
55
+ IsoCurrency["DKK"] = "DKK";
56
+ /** Polish Zloty — EU non-eurozone */
57
+ IsoCurrency["PLN"] = "PLN";
58
+ /** Thai Baht — southeast asian economy */
59
+ IsoCurrency["THB"] = "THB";
60
+ // 3-decimal exponent currencies (milli.x10^-3)
61
+ /** Bahraini Dinar — 3-decimal, fils */
62
+ IsoCurrency["BHD"] = "BHD";
63
+ /** Kuwaiti Dinar — 3-decimal, fils */
64
+ IsoCurrency["KWD"] = "KWD";
65
+ /** Omani Rial — 3-decimal, baisa */
66
+ IsoCurrency["OMR"] = "OMR";
67
+ /** Tunisian Dinar — 3-decimal, millimes */
68
+ IsoCurrency["TND"] = "TND";
69
+ })(IsoCurrency || (exports.IsoCurrency = IsoCurrency = {}));
70
+ //# sourceMappingURL=IsoCurrency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IsoCurrency.js","sourceRoot":"","sources":["../../src/domain.objects/IsoCurrency.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,IAAY,WAwDX;AAxDD,WAAY,WAAW;IACrB,+BAA+B;IAE/B,6CAA6C;IAC7C,0BAAW,CAAA;IACX,mCAAmC;IACnC,0BAAW,CAAA;IACX,uDAAuD;IACvD,0BAAW,CAAA;IACX,mDAAmD;IACnD,0BAAW,CAAA;IACX,iDAAiD;IACjD,0BAAW,CAAA;IACX,2CAA2C;IAC3C,0BAAW,CAAA;IACX,8CAA8C;IAC9C,0BAAW,CAAA;IACX,wCAAwC;IACxC,0BAAW,CAAA;IACX,uCAAuC;IACvC,0BAAW,CAAA;IACX,4CAA4C;IAC5C,0BAAW,CAAA;IACX,qCAAqC;IACrC,0BAAW,CAAA;IACX,wDAAwD;IACxD,0BAAW,CAAA;IACX,2CAA2C;IAC3C,0BAAW,CAAA;IACX,mCAAmC;IACnC,0BAAW,CAAA;IACX,mCAAmC;IACnC,0BAAW,CAAA;IACX,8CAA8C;IAC9C,0BAAW,CAAA;IACX,4CAA4C;IAC5C,0BAAW,CAAA;IACX,qCAAqC;IACrC,0BAAW,CAAA;IACX,mCAAmC;IACnC,0BAAW,CAAA;IACX,qCAAqC;IACrC,0BAAW,CAAA;IACX,0CAA0C;IAC1C,0BAAW,CAAA;IAEX,+CAA+C;IAE/C,uCAAuC;IACvC,0BAAW,CAAA;IACX,sCAAsC;IACtC,0BAAW,CAAA;IACX,oCAAoC;IACpC,0BAAW,CAAA;IACX,2CAA2C;IAC3C,0BAAW,CAAA;AACb,CAAC,EAxDW,WAAW,2BAAX,WAAW,QAwDtB"}
@@ -0,0 +1,16 @@
1
+ import type { IsoPriceExponent } from './IsoPriceExponent';
2
+ import type { IsoPriceHuman } from './IsoPriceHuman';
3
+ import type { IsoPriceShape } from './IsoPriceShape';
4
+ import type { IsoPriceWords } from './IsoPriceWords';
5
+ /**
6
+ * .what = union type that accepts any iso-price format
7
+ * .why = enables functions to accept prices in any format for convenience
8
+ *
9
+ * three formats:
10
+ * - `IsoPriceWords` — code-prefixed string: 'USD 50.37' (recommended for storage)
11
+ * - `IsoPriceShape` — structured object: { amount: 5037n, currency: 'USD' }
12
+ * - `IsoPriceHuman` — symbol-prefixed string: '$50.37' (for display and quick input)
13
+ *
14
+ * @template TCurrency - the currency code type (defaults to `string`)
15
+ */
16
+ export type IsoPrice<TCurrency extends string = string> = IsoPriceWords<TCurrency> | IsoPriceShape<TCurrency, IsoPriceExponent | `${IsoPriceExponent}`> | IsoPriceHuman;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IsoPrice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IsoPrice.js","sourceRoot":"","sources":["../../src/domain.objects/IsoPrice.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * .what = enum of supported precision exponents for iso-price
3
+ * .why = explicit exponent declarations avoid conflation between iso 4217 and scientific notation
4
+ *
5
+ * the `.x10^-N` suffix makes the math unambiguous:
6
+ * - `'centi.x10^-2'` → `amount × 10^-2 = amount / 100`
7
+ *
8
+ * the si metric prefix provides human readability:
9
+ * - `centi` = hundredths (cents)
10
+ * - `milli` = thousandths (fils)
11
+ * - `micro` = millionths (llm token costs)
12
+ * - `nano` = billionths (serverless costs)
13
+ * - `pico` = trillionths (extreme precision)
14
+ */
15
+ export declare enum IsoPriceExponent {
16
+ /** whole units — JPY, KRW, VND, etc */
17
+ WHOLE = "whole.x10^0",
18
+ /** standard cents — USD, EUR, GBP, most currencies */
19
+ CENTI = "centi.x10^-2",
20
+ /** thousandths — BHD, KWD, OMR, TND (fils/baisa) */
21
+ MILLI = "milli.x10^-3",
22
+ /** millionths — llm token costs, api rates */
23
+ MICRO = "micro.x10^-6",
24
+ /** billionths — serverless invocation costs */
25
+ NANO = "nano.x10^-9",
26
+ /** trillionths — extreme precision, requires bigint */
27
+ PICO = "pico.x10^-12"
28
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsoPriceExponent = void 0;
4
+ /**
5
+ * .what = enum of supported precision exponents for iso-price
6
+ * .why = explicit exponent declarations avoid conflation between iso 4217 and scientific notation
7
+ *
8
+ * the `.x10^-N` suffix makes the math unambiguous:
9
+ * - `'centi.x10^-2'` → `amount × 10^-2 = amount / 100`
10
+ *
11
+ * the si metric prefix provides human readability:
12
+ * - `centi` = hundredths (cents)
13
+ * - `milli` = thousandths (fils)
14
+ * - `micro` = millionths (llm token costs)
15
+ * - `nano` = billionths (serverless costs)
16
+ * - `pico` = trillionths (extreme precision)
17
+ */
18
+ var IsoPriceExponent;
19
+ (function (IsoPriceExponent) {
20
+ /** whole units — JPY, KRW, VND, etc */
21
+ IsoPriceExponent["WHOLE"] = "whole.x10^0";
22
+ /** standard cents — USD, EUR, GBP, most currencies */
23
+ IsoPriceExponent["CENTI"] = "centi.x10^-2";
24
+ /** thousandths — BHD, KWD, OMR, TND (fils/baisa) */
25
+ IsoPriceExponent["MILLI"] = "milli.x10^-3";
26
+ /** millionths — llm token costs, api rates */
27
+ IsoPriceExponent["MICRO"] = "micro.x10^-6";
28
+ /** billionths — serverless invocation costs */
29
+ IsoPriceExponent["NANO"] = "nano.x10^-9";
30
+ /** trillionths — extreme precision, requires bigint */
31
+ IsoPriceExponent["PICO"] = "pico.x10^-12";
32
+ })(IsoPriceExponent || (exports.IsoPriceExponent = IsoPriceExponent = {}));
33
+ //# sourceMappingURL=IsoPriceExponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IsoPriceExponent.js","sourceRoot":"","sources":["../../src/domain.objects/IsoPriceExponent.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,IAAY,gBAaX;AAbD,WAAY,gBAAgB;IAC1B,uCAAuC;IACvC,yCAAqB,CAAA;IACrB,sDAAsD;IACtD,0CAAsB,CAAA;IACtB,oDAAoD;IACpD,0CAAsB,CAAA;IACtB,8CAA8C;IAC9C,0CAAsB,CAAA;IACtB,+CAA+C;IAC/C,wCAAoB,CAAA;IACpB,uDAAuD;IACvD,yCAAqB,CAAA;AACvB,CAAC,EAbW,gBAAgB,gCAAhB,gBAAgB,QAa3B"}
@@ -0,0 +1,19 @@
1
+ import type { AsOfGlossary } from 'domain-glossaries';
2
+ /**
3
+ * .what = branded type for iso-price in human-readable format
4
+ * .why = ensures type safety for price strings with currency symbols like '$50.37'
5
+ *
6
+ * format: `{SYMBOL}{AMOUNT}` or `{AMOUNT} {SYMBOL}` (locale-dependent)
7
+ * - symbol: currency symbol (e.g., '$', '€', '¥', '£')
8
+ * - amount: numeric with optional comma separators and decimal point
9
+ *
10
+ * examples:
11
+ * - '$50.37'
12
+ * - '€1,000,000.00'
13
+ * - '¥1,000'
14
+ * - '100 €' (suffix position, some locales)
15
+ *
16
+ * note: this is a LOSSY format — symbols are ambiguous ($ could be USD, CAD, AUD, etc)
17
+ * use IsoPriceWords for unambiguous storage and serialization
18
+ */
19
+ export type IsoPriceHuman = AsOfGlossary<string, 'iso-price-human'>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IsoPriceHuman.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IsoPriceHuman.js","sourceRoot":"","sources":["../../src/domain.objects/IsoPriceHuman.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * .what = enum of supported round modes for iso-price precision operations
3
+ * .why = explicit round mode selection prevents silent precision loss
4
+ *
5
+ * round modes follow IEEE 754-2008 names for mathematical precision:
6
+ * - `floor` = toward negative infinity
7
+ * - `ceil` = toward positive infinity
8
+ * - `half-up` = ties go away from zero (most common expectation)
9
+ * - `half-down` = ties go toward zero
10
+ * - `half-even` = ties go to nearest even (banker's round)
11
+ */
12
+ export declare enum IsoPriceRoundMode {
13
+ /** round toward negative infinity — 5.5 → 5, -5.5 → -6 */
14
+ FLOOR = "floor",
15
+ /** round toward positive infinity — 5.5 → 6, -5.5 → -5 */
16
+ CEIL = "ceil",
17
+ /** ties go away from zero — 5.5 → 6, -5.5 → -6 (most common) */
18
+ HALF_UP = "half-up",
19
+ /** ties go toward zero — 5.5 → 5, -5.5 → -5 */
20
+ HALF_DOWN = "half-down",
21
+ /** ties go to nearest even — 5.5 → 6, 4.5 → 4 (banker's round) */
22
+ HALF_EVEN = "half-even"
23
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsoPriceRoundMode = void 0;
4
+ /**
5
+ * .what = enum of supported round modes for iso-price precision operations
6
+ * .why = explicit round mode selection prevents silent precision loss
7
+ *
8
+ * round modes follow IEEE 754-2008 names for mathematical precision:
9
+ * - `floor` = toward negative infinity
10
+ * - `ceil` = toward positive infinity
11
+ * - `half-up` = ties go away from zero (most common expectation)
12
+ * - `half-down` = ties go toward zero
13
+ * - `half-even` = ties go to nearest even (banker's round)
14
+ */
15
+ var IsoPriceRoundMode;
16
+ (function (IsoPriceRoundMode) {
17
+ /** round toward negative infinity — 5.5 → 5, -5.5 → -6 */
18
+ IsoPriceRoundMode["FLOOR"] = "floor";
19
+ /** round toward positive infinity — 5.5 → 6, -5.5 → -5 */
20
+ IsoPriceRoundMode["CEIL"] = "ceil";
21
+ /** ties go away from zero — 5.5 → 6, -5.5 → -6 (most common) */
22
+ IsoPriceRoundMode["HALF_UP"] = "half-up";
23
+ /** ties go toward zero — 5.5 → 5, -5.5 → -5 */
24
+ IsoPriceRoundMode["HALF_DOWN"] = "half-down";
25
+ /** ties go to nearest even — 5.5 → 6, 4.5 → 4 (banker's round) */
26
+ IsoPriceRoundMode["HALF_EVEN"] = "half-even";
27
+ })(IsoPriceRoundMode || (exports.IsoPriceRoundMode = IsoPriceRoundMode = {}));
28
+ //# sourceMappingURL=IsoPriceRoundMode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IsoPriceRoundMode.js","sourceRoot":"","sources":["../../src/domain.objects/IsoPriceRoundMode.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,IAAY,iBAWX;AAXD,WAAY,iBAAiB;IAC3B,0DAA0D;IAC1D,oCAAe,CAAA;IACf,0DAA0D;IAC1D,kCAAa,CAAA;IACb,gEAAgE;IAChE,wCAAmB,CAAA;IACnB,+CAA+C;IAC/C,4CAAuB,CAAA;IACvB,kEAAkE;IAClE,4CAAuB,CAAA;AACzB,CAAC,EAXW,iBAAiB,iCAAjB,iBAAiB,QAW5B"}
@@ -0,0 +1,30 @@
1
+ import type { IsoPriceExponent } from './IsoPriceExponent';
2
+ /**
3
+ * .what = structured domain literal for iso-price with bigint precision
4
+ * .why = enables lossless arithmetic and explicit precision control
5
+ *
6
+ * the shape provides:
7
+ * - `amount: bigint` — integer representation in minor units (no float precision errors)
8
+ * - `currency: TCurrency` — iso 4217 code or custom currency string
9
+ * - `exponent?: TExponent` — explicit precision level (defaults to currency standard)
10
+ *
11
+ * example:
12
+ * ```ts
13
+ * // $50.37 in cents (default centi.x10^-2 for USD)
14
+ * { amount: 5037n, currency: 'USD' }
15
+ *
16
+ * // $0.000003 in micro-dollars (llm token cost)
17
+ * { amount: 3n, currency: 'USD', exponent: 'micro.x10^-6' }
18
+ * ```
19
+ *
20
+ * @template TCurrency - the currency code type (defaults to `string`)
21
+ * @template TExponent - the exponent type (defaults to `IsoPriceExponent`)
22
+ */
23
+ export interface IsoPriceShape<TCurrency extends string = string, TExponent extends IsoPriceExponent | `${IsoPriceExponent}` = IsoPriceExponent | `${IsoPriceExponent}`> {
24
+ /** integer amount in minor units — always bigint for precision safety */
25
+ amount: bigint;
26
+ /** iso 4217 currency code or custom currency string */
27
+ currency: TCurrency;
28
+ /** explicit precision exponent — defaults to currency standard when omitted */
29
+ exponent?: TExponent;
30
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IsoPriceShape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IsoPriceShape.js","sourceRoot":"","sources":["../../src/domain.objects/IsoPriceShape.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import type { AsOfGlossary } from 'domain-glossaries';
2
+ /**
3
+ * .what = branded type for iso-price in words format
4
+ * .why = ensures type safety for price strings like 'USD 50.37'
5
+ *
6
+ * format: `{CURRENCY} {AMOUNT}`
7
+ * - currency: 3-letter iso 4217 code (e.g., 'USD', 'EUR', 'JPY')
8
+ * - amount: numeric with optional underscore separators and decimal point
9
+ *
10
+ * examples:
11
+ * - 'USD 50.37'
12
+ * - 'EUR 1_000_000.00'
13
+ * - 'JPY 1_000'
14
+ * - 'USD 0.000_003'
15
+ *
16
+ * note: commas are NOT valid in words format (use underscore separators)
17
+ *
18
+ * @template TCurrency - the currency code (defaults to `string` for any currency)
19
+ */
20
+ export type IsoPriceWords<TCurrency extends string = string> = AsOfGlossary<`${TCurrency} ${string}`, 'iso-price-words'>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IsoPriceWords.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IsoPriceWords.js","sourceRoot":"","sources":["../../src/domain.objects/IsoPriceWords.ts"],"names":[],"mappings":""}
@@ -0,0 +1,48 @@
1
+ import type { IsoPrice } from '../../domain.objects/IsoPrice';
2
+ import type { IsoPriceShape } from '../../domain.objects/IsoPriceShape';
3
+ import type { IsoPriceWords } from '../../domain.objects/IsoPriceWords';
4
+ /**
5
+ * .what = remainder distribution mode
6
+ * .why = determines where leftover cents go in allocation
7
+ */
8
+ type AllocationRemainderMode = 'first' | 'last' | 'largest' | 'random';
9
+ /**
10
+ * .what = allocates a price into equal parts or by ratios
11
+ * .why = enables fair distribution without loss (sum always equals original)
12
+ *
13
+ * @example
14
+ * allocatePrice({ of: 'USD 10.00', into: { parts: 3 }, remainder: 'first' })
15
+ * // => ['USD 3.34', 'USD 3.33', 'USD 3.33']
16
+ *
17
+ * @example
18
+ * allocatePrice({ of: 'USD 5.00', into: { ratios: [7, 3] }, remainder: 'first' })
19
+ * // => ['USD 3.50', 'USD 1.50']
20
+ */
21
+ export declare function allocatePrice<TCurrency extends string = string>(input: {
22
+ of: IsoPrice<TCurrency> | string;
23
+ into: {
24
+ parts: number;
25
+ } | {
26
+ ratios: number[];
27
+ };
28
+ remainder: AllocationRemainderMode;
29
+ }, options?: {
30
+ format?: 'words';
31
+ }): IsoPriceWords<TCurrency>[];
32
+ export declare function allocatePrice<TCurrency extends string = string>(input: {
33
+ of: IsoPrice<TCurrency> | string;
34
+ into: {
35
+ parts: number;
36
+ } | {
37
+ ratios: number[];
38
+ };
39
+ remainder: AllocationRemainderMode;
40
+ }, options: {
41
+ format: 'shape';
42
+ }): IsoPriceShape<TCurrency>[];
43
+ /**
44
+ * .what = alias for allocatePrice
45
+ * .why = provides price-prefixed variant
46
+ */
47
+ export declare const priceAllocate: typeof allocatePrice;
48
+ export {};