@morpho-org/blue-sdk 1.0.0-integ-650.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 (86) hide show
  1. package/README.md +106 -0
  2. package/lib/addresses.d.ts +113 -0
  3. package/lib/addresses.js +162 -0
  4. package/lib/chain.d.ts +29 -0
  5. package/lib/chain.js +289 -0
  6. package/lib/chain.test.d.ts +1 -0
  7. package/lib/chain.test.js +21 -0
  8. package/lib/constants.d.ts +29 -0
  9. package/lib/constants.js +33 -0
  10. package/lib/errors.d.ts +58 -0
  11. package/lib/errors.js +119 -0
  12. package/lib/helpers/format/format.d.ts +122 -0
  13. package/lib/helpers/format/format.js +286 -0
  14. package/lib/helpers/format/format.test.d.ts +1 -0
  15. package/lib/helpers/format/format.test.js +255 -0
  16. package/lib/helpers/format/index.d.ts +1 -0
  17. package/lib/helpers/format/index.js +17 -0
  18. package/lib/helpers/index.d.ts +2 -0
  19. package/lib/helpers/index.js +18 -0
  20. package/lib/helpers/locale.d.ts +46 -0
  21. package/lib/helpers/locale.js +96 -0
  22. package/lib/holding/AssetBalances.d.ts +48 -0
  23. package/lib/holding/AssetBalances.js +42 -0
  24. package/lib/holding/Holding.d.ts +59 -0
  25. package/lib/holding/Holding.js +59 -0
  26. package/lib/holding/index.d.ts +2 -0
  27. package/lib/holding/index.js +18 -0
  28. package/lib/index.d.ts +25 -0
  29. package/lib/index.js +54 -0
  30. package/lib/market/Market.d.ts +329 -0
  31. package/lib/market/Market.js +460 -0
  32. package/lib/market/MarketConfig.d.ts +52 -0
  33. package/lib/market/MarketConfig.js +76 -0
  34. package/lib/market/MarketUtils.d.ts +232 -0
  35. package/lib/market/MarketUtils.js +263 -0
  36. package/lib/market/MarketUtils.test.d.ts +1 -0
  37. package/lib/market/MarketUtils.test.js +38 -0
  38. package/lib/market/index.d.ts +3 -0
  39. package/lib/market/index.js +19 -0
  40. package/lib/maths/AdaptiveCurveIrmLib.d.ts +39 -0
  41. package/lib/maths/AdaptiveCurveIrmLib.js +134 -0
  42. package/lib/maths/MathLib.d.ts +114 -0
  43. package/lib/maths/MathLib.js +175 -0
  44. package/lib/maths/SharesMath.d.ts +12 -0
  45. package/lib/maths/SharesMath.js +21 -0
  46. package/lib/maths/index.d.ts +3 -0
  47. package/lib/maths/index.js +19 -0
  48. package/lib/position/Position.d.ts +126 -0
  49. package/lib/position/Position.js +203 -0
  50. package/lib/position/index.d.ts +1 -0
  51. package/lib/position/index.js +17 -0
  52. package/lib/tests/mocks/markets.d.ts +19 -0
  53. package/lib/tests/mocks/markets.js +121 -0
  54. package/lib/token/ConstantWrappedToken.d.ts +18 -0
  55. package/lib/token/ConstantWrappedToken.js +36 -0
  56. package/lib/token/ExchangeRateWrappedToken.d.ts +11 -0
  57. package/lib/token/ExchangeRateWrappedToken.js +21 -0
  58. package/lib/token/Token.d.ts +46 -0
  59. package/lib/token/Token.js +64 -0
  60. package/lib/token/VaultToken.d.ts +14 -0
  61. package/lib/token/VaultToken.js +23 -0
  62. package/lib/token/WrappedToken.d.ts +17 -0
  63. package/lib/token/WrappedToken.js +33 -0
  64. package/lib/token/index.d.ts +5 -0
  65. package/lib/token/index.js +21 -0
  66. package/lib/types.d.ts +30 -0
  67. package/lib/types.js +22 -0
  68. package/lib/user/User.d.ts +20 -0
  69. package/lib/user/User.js +23 -0
  70. package/lib/user/index.d.ts +1 -0
  71. package/lib/user/index.js +17 -0
  72. package/lib/vault/Vault.d.ts +166 -0
  73. package/lib/vault/Vault.js +234 -0
  74. package/lib/vault/VaultConfig.d.ts +22 -0
  75. package/lib/vault/VaultConfig.js +32 -0
  76. package/lib/vault/VaultMarketAllocation.d.ts +20 -0
  77. package/lib/vault/VaultMarketAllocation.js +30 -0
  78. package/lib/vault/VaultMarketConfig.d.ts +43 -0
  79. package/lib/vault/VaultMarketConfig.js +43 -0
  80. package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
  81. package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
  82. package/lib/vault/VaultUtils.d.ts +18 -0
  83. package/lib/vault/VaultUtils.js +20 -0
  84. package/lib/vault/index.d.ts +6 -0
  85. package/lib/vault/index.js +22 -0
  86. package/package.json +53 -0
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.format = exports.PercentFormatter = exports.ShortFormatter = exports.CommasFormatter = exports.NumberFormatter = exports.CommonFormatter = exports.HexFormatter = exports.BaseFormatter = void 0;
4
+ const locale_1 = require("../locale");
5
+ var Format;
6
+ (function (Format) {
7
+ Format["number"] = "number";
8
+ Format["commas"] = "commas";
9
+ Format["short"] = "short";
10
+ Format["hex"] = "hex";
11
+ Format["percent"] = "percent";
12
+ })(Format || (Format = {}));
13
+ String.prototype.insert = function (index, substr, fillWith) {
14
+ if (index < 0)
15
+ index = this.length + index;
16
+ let filler = "";
17
+ if (index < 0) {
18
+ if (fillWith)
19
+ filler = fillWith.repeat(-index).slice(index);
20
+ index = 0;
21
+ }
22
+ return this.slice(0, index) + substr + filler + this.slice(index);
23
+ };
24
+ const RANGES = [
25
+ {
26
+ minDecimals: 24,
27
+ symbol: "Y",
28
+ },
29
+ {
30
+ minDecimals: 21,
31
+ symbol: "Z",
32
+ },
33
+ {
34
+ minDecimals: 18,
35
+ symbol: "E",
36
+ },
37
+ {
38
+ minDecimals: 15,
39
+ symbol: "P",
40
+ },
41
+ {
42
+ minDecimals: 12,
43
+ symbol: "T",
44
+ },
45
+ {
46
+ minDecimals: 9,
47
+ symbol: "B",
48
+ },
49
+ {
50
+ minDecimals: 6,
51
+ symbol: "M",
52
+ },
53
+ {
54
+ minDecimals: 4,
55
+ power: 3,
56
+ symbol: "k",
57
+ },
58
+ ];
59
+ const _formatShort = (bi, decimals, formatOptions) => {
60
+ const stringValue = bi.toString();
61
+ const params = RANGES.find((range) => stringValue.length > range.minDecimals + decimals);
62
+ if (params) {
63
+ return (_applyOptions(stringValue.insert(-((params.power ?? params.minDecimals) + decimals), ".", "0"), formatOptions) + params.symbol);
64
+ }
65
+ if (formatOptions.smallValuesWithCommas) {
66
+ return _formatCommas(bi, decimals, formatOptions);
67
+ }
68
+ return _applyOptions(stringValue.insert(-decimals, ".", "0"), formatOptions);
69
+ };
70
+ const _formatCommas = (bi, decimals, formatOptions) => {
71
+ const stringValue = decimals
72
+ ? bi.toString().insert(-decimals, ".", "0")
73
+ : bi.toString();
74
+ const [wholePart, decimalPart] = stringValue.split(".");
75
+ return _applyOptions(wholePart
76
+ .split("")
77
+ .reduce((formattedNumber, digit, i, arr) => `${formattedNumber}${!i || (arr.length - i) % 3 ? "" : ","}${digit}`, "") + (decimalPart ? "." + decimalPart : ""), formatOptions);
78
+ };
79
+ const _formatNumber = (bi, decimals, formatOptions) => {
80
+ if (decimals === 0)
81
+ return _applyOptions(bi.toString(), formatOptions);
82
+ return _applyOptions(bi.toString().insert(-decimals, ".", "0"), formatOptions);
83
+ };
84
+ const _withUnit = (value, unit) => {
85
+ switch (unit) {
86
+ case "$":
87
+ return `$${value}`;
88
+ case "":
89
+ case "%":
90
+ return `${value}${unit}`;
91
+ default:
92
+ return `${value} ${unit}`;
93
+ }
94
+ };
95
+ const _applyOptions = (value, formatOptions) => {
96
+ let [wholePart, decimalPart = ""] = value.split(".");
97
+ const isZero = value.match(/[1-9]/)?.index === undefined;
98
+ if (formatOptions.digits !== undefined) {
99
+ decimalPart = decimalPart + "0".repeat(formatOptions.digits);
100
+ decimalPart = decimalPart.slice(0, formatOptions.digits);
101
+ }
102
+ if (formatOptions.removeTrailingZero) {
103
+ decimalPart = decimalPart.replace(/\.?0+$/, "");
104
+ }
105
+ value = (wholePart || "0") + (decimalPart ? "." + decimalPart : "");
106
+ const { value: _value, decimalSymbol } = (0, locale_1.getEnUSNumberToLocalParts)(value, formatOptions.locale);
107
+ value = _value;
108
+ const firstNonZero = value.match(/[1-9]/);
109
+ if (firstNonZero?.index === undefined &&
110
+ formatOptions.digits &&
111
+ !isZero &&
112
+ formatOptions.readable)
113
+ return `< 0${decimalSymbol}${"0".repeat(formatOptions.digits - 1)}1`;
114
+ return value;
115
+ };
116
+ function formatBI(bi, decimals, formatOptions = { format: Format.hex }) {
117
+ if (formatOptions.format === Format.hex)
118
+ return bi.toString(16);
119
+ if (formatOptions.max != null) {
120
+ const maxBI = BigInt(formatOptions.max.toFixed(decimals).replace(".", ""));
121
+ if (bi > maxBI)
122
+ return `> ${formatBI(maxBI, decimals, formatOptions)}`;
123
+ }
124
+ if (formatOptions.min != null) {
125
+ const minBI = BigInt(formatOptions.min.toFixed(decimals).replace(".", ""));
126
+ if (bi < minBI && bi !== 0n)
127
+ return `< ${formatBI(minBI, decimals, formatOptions)}`;
128
+ }
129
+ let value;
130
+ const isNegative = bi < 0n;
131
+ const absBI = bi > 0n ? bi : -bi;
132
+ switch (formatOptions.format) {
133
+ case Format.commas:
134
+ value = _formatCommas(absBI, decimals, formatOptions);
135
+ break;
136
+ case Format.number:
137
+ value = _formatNumber(absBI, decimals, formatOptions);
138
+ break;
139
+ case Format.short:
140
+ value = _formatShort(absBI, decimals, formatOptions);
141
+ break;
142
+ case Format.percent:
143
+ value = _formatNumber(absBI * 100n, decimals, formatOptions);
144
+ break;
145
+ }
146
+ const formattedValue = (isNegative && !/^0\.0+$/.test(value)
147
+ ? "-"
148
+ : formatOptions.sign
149
+ ? "+"
150
+ : "") + value;
151
+ if (formatOptions.unit) {
152
+ return _withUnit(formattedValue, formatOptions.unit);
153
+ }
154
+ return formattedValue;
155
+ }
156
+ /**
157
+ * @deprecated Import from `@morpho-org/morpho-ts`
158
+ */
159
+ class BaseFormatter {
160
+ constructor() { }
161
+ of(value, decimals) {
162
+ if (typeof value === "number") {
163
+ const str = value.toString();
164
+ const [significant] = str.split(/[eE]/);
165
+ const [, digits = ""] = significant.split(".");
166
+ decimals =
167
+ Math.min(100, Math.max(0, Math.floor(-Math.log10(value)))) +
168
+ digits.length;
169
+ value = BigInt(value.toFixed(decimals).replace(".", ""));
170
+ }
171
+ return formatBI(value, decimals, this._options);
172
+ }
173
+ }
174
+ exports.BaseFormatter = BaseFormatter;
175
+ /**
176
+ * @deprecated Import from `@morpho-org/morpho-ts`
177
+ */
178
+ class HexFormatter extends BaseFormatter {
179
+ _options = { format: Format.hex };
180
+ }
181
+ exports.HexFormatter = HexFormatter;
182
+ /**
183
+ * @deprecated Import from `@morpho-org/morpho-ts`
184
+ */
185
+ class CommonFormatter extends BaseFormatter {
186
+ digits(_d) {
187
+ this._options.digits = _d;
188
+ return this;
189
+ }
190
+ removeTrailingZero() {
191
+ this._options.removeTrailingZero = true;
192
+ return this;
193
+ }
194
+ readable() {
195
+ this._options.readable = true;
196
+ return this;
197
+ }
198
+ min(_m) {
199
+ this._options.min = _m;
200
+ return this;
201
+ }
202
+ max(_m) {
203
+ this._options.max = _m;
204
+ return this;
205
+ }
206
+ sign() {
207
+ this._options.sign = true;
208
+ return this;
209
+ }
210
+ unit(_u) {
211
+ this._options.unit = _u;
212
+ return this;
213
+ }
214
+ locale(_l) {
215
+ this._options.locale = _l;
216
+ return this;
217
+ }
218
+ }
219
+ exports.CommonFormatter = CommonFormatter;
220
+ /**
221
+ * @deprecated Import from `@morpho-org/morpho-ts`
222
+ */
223
+ class NumberFormatter extends CommonFormatter {
224
+ _options = { format: Format.number };
225
+ }
226
+ exports.NumberFormatter = NumberFormatter;
227
+ /**
228
+ * @deprecated Import from `@morpho-org/morpho-ts`
229
+ */
230
+ class CommasFormatter extends CommonFormatter {
231
+ _options = { format: Format.commas };
232
+ }
233
+ exports.CommasFormatter = CommasFormatter;
234
+ /**
235
+ * @deprecated Import from `@morpho-org/morpho-ts`
236
+ */
237
+ class ShortFormatter extends CommonFormatter {
238
+ _options = { format: Format.short };
239
+ smallValuesWithCommas() {
240
+ this._options.smallValuesWithCommas = true;
241
+ return this;
242
+ }
243
+ }
244
+ exports.ShortFormatter = ShortFormatter;
245
+ /**
246
+ * @deprecated Import from `@morpho-org/morpho-ts`
247
+ */
248
+ class PercentFormatter extends CommonFormatter {
249
+ _options = { format: Format.percent };
250
+ }
251
+ exports.PercentFormatter = PercentFormatter;
252
+ /**
253
+ * @deprecated Import from `@morpho-org/morpho-ts`
254
+ */
255
+ exports.format = {
256
+ /**
257
+ * Return the value as an integer in hex format
258
+ */
259
+ get hex() {
260
+ return new HexFormatter();
261
+ },
262
+ /**
263
+ * Return the value as a stringified number (12345.6789)
264
+ */
265
+ get number() {
266
+ return new NumberFormatter();
267
+ },
268
+ /**
269
+ * Return the value as a commas-separated stringified number (12,345.6789)
270
+ */
271
+ get commas() {
272
+ return new CommasFormatter();
273
+ },
274
+ /**
275
+ * Return the value as a shorted stringified number (12.3456789k)
276
+ */
277
+ get short() {
278
+ return new ShortFormatter();
279
+ },
280
+ /**
281
+ * Return the value as a percent based stringified number (10.00 instead of 0.1)
282
+ */
283
+ get percent() {
284
+ return new PercentFormatter();
285
+ },
286
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const format_1 = require("./format");
4
+ describe("format", () => {
5
+ const number = 12345.6789;
6
+ const bigint = 123456789n;
7
+ const decimals = 4;
8
+ describe("hex", () => {
9
+ describe("should properly format number in hex format", () => {
10
+ it("without option", () => {
11
+ expect(format_1.format.hex.of(number)).toEqual((123456789).toString(16));
12
+ });
13
+ });
14
+ describe("should properly format bigint in hex format", () => {
15
+ it("without option", () => {
16
+ expect(format_1.format.hex.of(bigint, decimals)).toEqual((123456789).toString(16));
17
+ });
18
+ });
19
+ });
20
+ describe("number", () => {
21
+ describe("should properly format number in number format", () => {
22
+ it("without option", () => {
23
+ expect(format_1.format.number.of(number)).toEqual("12345.6789");
24
+ });
25
+ it("with digits", () => {
26
+ expect(format_1.format.number.digits(2).of(number)).toEqual("12345.67");
27
+ });
28
+ it("with min", () => {
29
+ expect(format_1.format.number.min(20000).of(number)).toEqual("< 20000.0000");
30
+ });
31
+ it("with max", () => {
32
+ expect(format_1.format.number.max(10000).of(number)).toEqual("> 10000.0000");
33
+ });
34
+ it("with sign", () => {
35
+ expect(format_1.format.number.sign().of(number)).toEqual("+12345.6789");
36
+ });
37
+ it("with unit", () => {
38
+ expect(format_1.format.number.unit("$").of(number)).toEqual("$12345.6789");
39
+ });
40
+ it("without trailing zeros", () => {
41
+ expect(format_1.format.number.digits(6).of(number)).toEqual("12345.678900");
42
+ expect(format_1.format.number.digits(6).removeTrailingZero().of(number)).toEqual("12345.6789");
43
+ });
44
+ it("with locale", () => {
45
+ expect(format_1.format.number.locale("fr-FR").of(number)).toEqual("12345,6789");
46
+ });
47
+ });
48
+ describe("should properly format bigint in number format", () => {
49
+ it("without option", () => {
50
+ expect(format_1.format.number.of(bigint, decimals)).toEqual("12345.6789");
51
+ });
52
+ it("with digits", () => {
53
+ expect(format_1.format.number.digits(2).of(bigint, decimals)).toEqual("12345.67");
54
+ });
55
+ it("with min", () => {
56
+ expect(format_1.format.number.min(20000).of(bigint, decimals)).toEqual("< 20000.0000");
57
+ });
58
+ it("with max", () => {
59
+ expect(format_1.format.number.max(10000).of(bigint, decimals)).toEqual("> 10000.0000");
60
+ });
61
+ it("with sign", () => {
62
+ expect(format_1.format.number.sign().of(bigint, decimals)).toEqual("+12345.6789");
63
+ });
64
+ it("with unit", () => {
65
+ expect(format_1.format.number.unit("$").of(bigint, decimals)).toEqual("$12345.6789");
66
+ });
67
+ it("without trailing zeros", () => {
68
+ expect(format_1.format.number.digits(6).of(bigint, decimals)).toEqual("12345.678900");
69
+ expect(format_1.format.number.digits(6).removeTrailingZero().of(bigint, decimals)).toEqual("12345.6789");
70
+ });
71
+ it("with locale", () => {
72
+ expect(format_1.format.number.locale("fr-FR").of(bigint, decimals)).toEqual("12345,6789");
73
+ });
74
+ });
75
+ });
76
+ describe("short", () => {
77
+ describe("should properly format number in short format", () => {
78
+ it("without option", () => {
79
+ expect(format_1.format.short.of(number)).toEqual("12.3456789k");
80
+ });
81
+ it("with digits", () => {
82
+ expect(format_1.format.short.digits(2).of(number)).toEqual("12.34k");
83
+ });
84
+ it("with min", () => {
85
+ expect(format_1.format.short.min(20000).of(number)).toEqual("< 20.0000000k");
86
+ });
87
+ it("with max", () => {
88
+ expect(format_1.format.short.max(10000).of(number)).toEqual("> 10.0000000k");
89
+ });
90
+ it("with sign", () => {
91
+ expect(format_1.format.short.sign().of(number)).toEqual("+12.3456789k");
92
+ });
93
+ it("with unit", () => {
94
+ expect(format_1.format.short.unit("€").of(number)).toEqual("12.3456789k €");
95
+ });
96
+ it("without trailing zeros", () => {
97
+ expect(format_1.format.short.digits(8).of(number)).toEqual("12.34567890k");
98
+ expect(format_1.format.short.digits(8).removeTrailingZero().of(number)).toEqual("12.3456789k");
99
+ });
100
+ it("with small numbers with commas", () => {
101
+ expect(format_1.format.short.smallValuesWithCommas().of(number / 10)).toEqual("1,234.56789");
102
+ });
103
+ it("with locale", () => {
104
+ expect(format_1.format.short.locale("fr-FR").of(number)).toEqual("12,3456789k");
105
+ });
106
+ });
107
+ describe("should properly format bigint in short format", () => {
108
+ it("without option", () => {
109
+ expect(format_1.format.short.of(bigint, decimals)).toEqual("12.3456789k");
110
+ });
111
+ it("with digits", () => {
112
+ expect(format_1.format.short.digits(2).of(bigint, decimals)).toEqual("12.34k");
113
+ });
114
+ it("with min", () => {
115
+ expect(format_1.format.short.min(20000).of(bigint, decimals)).toEqual("< 20.0000000k");
116
+ });
117
+ it("with max", () => {
118
+ expect(format_1.format.short.max(10000).of(bigint, decimals)).toEqual("> 10.0000000k");
119
+ });
120
+ it("with sign", () => {
121
+ expect(format_1.format.short.sign().of(bigint, decimals)).toEqual("+12.3456789k");
122
+ });
123
+ it("with unit", () => {
124
+ expect(format_1.format.short.unit("€").of(bigint, decimals)).toEqual("12.3456789k €");
125
+ });
126
+ it("without trailing zeros", () => {
127
+ expect(format_1.format.short.digits(8).of(bigint, decimals)).toEqual("12.34567890k");
128
+ expect(format_1.format.short.digits(8).removeTrailingZero().of(bigint, decimals)).toEqual("12.3456789k");
129
+ });
130
+ it("with locale", () => {
131
+ expect(format_1.format.short.locale("fr-FR").of(bigint, decimals)).toEqual("12,3456789k");
132
+ });
133
+ it("with small numbers with commas", () => {
134
+ expect(format_1.format.short.smallValuesWithCommas().of(bigint, decimals + 1)).toEqual("1,234.56789");
135
+ });
136
+ it("with small numbers with commas with locale", () => {
137
+ expect(format_1.format.short
138
+ .smallValuesWithCommas()
139
+ .locale("fr-FR")
140
+ .of(bigint, decimals + 1)).toEqual("1\u202F234,56789");
141
+ });
142
+ });
143
+ });
144
+ describe("commas", () => {
145
+ describe("should properly format number in commas format", () => {
146
+ it("without option", () => {
147
+ expect(format_1.format.commas.of(number)).toEqual("12,345.6789");
148
+ });
149
+ it("with digits", () => {
150
+ expect(format_1.format.commas.digits(2).of(number)).toEqual("12,345.67");
151
+ });
152
+ it("with min", () => {
153
+ expect(format_1.format.commas.min(20000).of(number)).toEqual("< 20,000.0000");
154
+ });
155
+ it("with max", () => {
156
+ expect(format_1.format.commas.max(10000).of(number)).toEqual("> 10,000.0000");
157
+ });
158
+ it("with sign", () => {
159
+ expect(format_1.format.commas.sign().of(number)).toEqual("+12,345.6789");
160
+ });
161
+ it("with unit", () => {
162
+ expect(format_1.format.commas.unit("ETH").of(number)).toEqual("12,345.6789 ETH");
163
+ });
164
+ it("without trailing zeros", () => {
165
+ expect(format_1.format.commas.digits(6).of(number)).toEqual("12,345.678900");
166
+ expect(format_1.format.commas.digits(6).removeTrailingZero().of(number)).toEqual("12,345.6789");
167
+ });
168
+ it("with locale", () => {
169
+ expect(format_1.format.commas.locale("fr-FR").of(number)).toEqual("12\u202F345,6789");
170
+ });
171
+ });
172
+ describe("should properly format bigint in commas format", () => {
173
+ it("without option", () => {
174
+ expect(format_1.format.commas.of(bigint, decimals)).toEqual("12,345.6789");
175
+ });
176
+ it("with digits", () => {
177
+ expect(format_1.format.commas.digits(2).of(bigint, decimals)).toEqual("12,345.67");
178
+ });
179
+ it("with min", () => {
180
+ expect(format_1.format.commas.min(20000).of(bigint, decimals)).toEqual("< 20,000.0000");
181
+ });
182
+ it("with max", () => {
183
+ expect(format_1.format.commas.max(10000).of(bigint, decimals)).toEqual("> 10,000.0000");
184
+ });
185
+ it("with sign", () => {
186
+ expect(format_1.format.commas.sign().of(bigint, decimals)).toEqual("+12,345.6789");
187
+ });
188
+ it("with unit", () => {
189
+ expect(format_1.format.commas.unit("ETH").of(bigint, decimals)).toEqual("12,345.6789 ETH");
190
+ });
191
+ it("without trailing zeros", () => {
192
+ expect(format_1.format.commas.digits(6).of(bigint, decimals)).toEqual("12,345.678900");
193
+ expect(format_1.format.commas.digits(6).removeTrailingZero().of(bigint, decimals)).toEqual("12,345.6789");
194
+ });
195
+ it("with locale", () => {
196
+ // the correct space in fr-FR is narrow no-break space (U+202F)
197
+ expect(format_1.format.commas.locale("fr-FR").of(bigint, decimals)).toEqual("12\u202F345,6789");
198
+ });
199
+ });
200
+ });
201
+ describe("percent", () => {
202
+ describe("should properly format number in percent format", () => {
203
+ it("without option", () => {
204
+ expect(format_1.format.percent.of(number)).toEqual("1234567.8900");
205
+ });
206
+ it("with digits", () => {
207
+ expect(format_1.format.percent.digits(1).of(number)).toEqual("1234567.8");
208
+ });
209
+ it("with min", () => {
210
+ expect(format_1.format.percent.min(20000).of(number)).toEqual("< 2000000.0000");
211
+ });
212
+ it("with max", () => {
213
+ expect(format_1.format.percent.max(10000).of(number)).toEqual("> 1000000.0000");
214
+ });
215
+ it("with sign", () => {
216
+ expect(format_1.format.percent.sign().of(number)).toEqual("+1234567.8900");
217
+ });
218
+ it("with unit", () => {
219
+ expect(format_1.format.percent.unit("%").of(number)).toEqual("1234567.8900%");
220
+ });
221
+ it("without trailing zeros", () => {
222
+ expect(format_1.format.percent.removeTrailingZero().of(number)).toEqual("1234567.89");
223
+ });
224
+ it("with locale", () => {
225
+ expect(format_1.format.percent.locale("fr-FR").of(number)).toEqual("1234567,8900");
226
+ });
227
+ });
228
+ describe("should properly format bigint in percent format", () => {
229
+ it("without option", () => {
230
+ expect(format_1.format.percent.of(bigint, decimals)).toEqual("1234567.8900");
231
+ });
232
+ it("with digits", () => {
233
+ expect(format_1.format.percent.digits(1).of(bigint, decimals)).toEqual("1234567.8");
234
+ });
235
+ it("with min", () => {
236
+ expect(format_1.format.percent.min(20000).of(bigint, decimals)).toEqual("< 2000000.0000");
237
+ });
238
+ it("with max", () => {
239
+ expect(format_1.format.percent.max(10000).of(bigint, decimals)).toEqual("> 1000000.0000");
240
+ });
241
+ it("with sign", () => {
242
+ expect(format_1.format.percent.sign().of(bigint, decimals)).toEqual("+1234567.8900");
243
+ });
244
+ it("with unit", () => {
245
+ expect(format_1.format.percent.unit("%").of(bigint, decimals)).toEqual("1234567.8900%");
246
+ });
247
+ it("without trailing zeros", () => {
248
+ expect(format_1.format.percent.removeTrailingZero().of(bigint, decimals)).toEqual("1234567.89");
249
+ });
250
+ it("with locale", () => {
251
+ expect(format_1.format.percent.locale("fr-FR").of(bigint, decimals)).toEqual("1234567,8900");
252
+ });
253
+ });
254
+ });
255
+ });
@@ -0,0 +1 @@
1
+ export * from "./format";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./format"), exports);
@@ -0,0 +1,2 @@
1
+ export * from "./locale";
2
+ export * from "./format";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./locale"), exports);
18
+ __exportStar(require("./format"), exports);
@@ -0,0 +1,46 @@
1
+ type LocaleSymbols = {
2
+ decimalSymbol: string;
3
+ groupSymbol: string;
4
+ locale: string;
5
+ };
6
+ export type LocaleParts = LocaleSymbols & {
7
+ value: string;
8
+ };
9
+ /**
10
+ * @returns the locale symbols for the given locale defaulting to en-US
11
+ *
12
+ * @deprecated Import from `@morpho-org/morpho-ts`
13
+ */
14
+ export declare const getLocaleSymbols: (locale: string) => LocaleSymbols;
15
+ /**
16
+ * @returns the effective browser locale
17
+ *
18
+ * @deprecated Import from `@morpho-org/morpho-ts`
19
+ */
20
+ export declare const getEffectiveLocale: () => string;
21
+ /**
22
+ * @returns the value as a string with the given locale symbols
23
+ * @param numStr the number as a string in the "from" locale (e.g. "1,2345.6" for en-US)
24
+ * @param from the locale the numStr is in (e.g. "en-US")
25
+ * @param to the locale to convert to (e.g. "fr-FR")
26
+ *
27
+ * @deprecated Import from `@morpho-org/morpho-ts`
28
+ */
29
+ export declare const convertNumStrToLocal: (numStr: string, from: string, to: string) => string;
30
+ /**
31
+ * @returns the value as a string in the effective browser locale
32
+ * @param numStr the number as a string in the effective browser locale (e.g. "1,2345.6" for en-US)
33
+ * @param to the locale to use (e.g. "fr-FR")
34
+ *
35
+ * @deprecated Import from `@morpho-org/morpho-ts`
36
+ */
37
+ export declare const convertNumStrFromEffectiveTo: (numStr: string, to: string) => string;
38
+ /**
39
+ * @returns the value as a string with the given locale symbols either from the given locale or the effective browser locale
40
+ * @param numStr the number as a string in english format (e.g. "1,2345.6")
41
+ * @param locale optional - the locale to use (e.g. "fr-FR")
42
+ *
43
+ * @deprecated Import from `@morpho-org/morpho-ts`
44
+ */
45
+ export declare const getEnUSNumberToLocalParts: (numStr: string, locale?: string) => LocaleParts;
46
+ export {};