@w3ux/utils 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +12 -5
- package/index.js +12 -5
- package/package.json +1 -1
- package/unit.cjs +13 -5
- package/unit.js +13 -5
package/index.cjs
CHANGED
|
@@ -342,8 +342,10 @@ function u8aUnwrapBytes(bytes) {
|
|
|
342
342
|
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
|
|
343
343
|
var planckToUnit = (val, units) => {
|
|
344
344
|
try {
|
|
345
|
-
units = Math.max(units, 0);
|
|
346
|
-
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
345
|
+
units = Math.max(Math.round(units), 0);
|
|
346
|
+
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
347
|
+
typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
|
|
348
|
+
);
|
|
347
349
|
const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
|
|
348
350
|
const integerPart = bigIntVal / divisor;
|
|
349
351
|
const fractionalPart = bigIntVal % divisor;
|
|
@@ -355,12 +357,17 @@ var planckToUnit = (val, units) => {
|
|
|
355
357
|
};
|
|
356
358
|
var unitToPlanck = (val, units) => {
|
|
357
359
|
try {
|
|
358
|
-
|
|
360
|
+
units = Math.max(Math.round(units), 0);
|
|
361
|
+
const strVal = (typeof val === "string" ? rmCommas(val) : val.toString()) || "0";
|
|
359
362
|
const [integerPart, fractionalPart = ""] = strVal.split(".");
|
|
360
363
|
let bigIntValue = BigInt(integerPart) * BigInt(10) ** BigInt(units);
|
|
361
364
|
if (fractionalPart) {
|
|
362
|
-
|
|
363
|
-
|
|
365
|
+
let fractionalValue;
|
|
366
|
+
if (fractionalPart.length > units) {
|
|
367
|
+
fractionalValue = BigInt(fractionalPart.slice(0, units));
|
|
368
|
+
} else {
|
|
369
|
+
fractionalValue = BigInt(fractionalPart.padEnd(units, "0"));
|
|
370
|
+
}
|
|
364
371
|
bigIntValue += fractionalValue;
|
|
365
372
|
}
|
|
366
373
|
return bigIntValue;
|
package/index.js
CHANGED
|
@@ -270,8 +270,10 @@ function u8aUnwrapBytes(bytes) {
|
|
|
270
270
|
import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
|
|
271
271
|
var planckToUnit = (val, units) => {
|
|
272
272
|
try {
|
|
273
|
-
units = Math.max(units, 0);
|
|
274
|
-
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
273
|
+
units = Math.max(Math.round(units), 0);
|
|
274
|
+
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
275
|
+
typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
|
|
276
|
+
);
|
|
275
277
|
const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
|
|
276
278
|
const integerPart = bigIntVal / divisor;
|
|
277
279
|
const fractionalPart = bigIntVal % divisor;
|
|
@@ -283,12 +285,17 @@ var planckToUnit = (val, units) => {
|
|
|
283
285
|
};
|
|
284
286
|
var unitToPlanck = (val, units) => {
|
|
285
287
|
try {
|
|
286
|
-
|
|
288
|
+
units = Math.max(Math.round(units), 0);
|
|
289
|
+
const strVal = (typeof val === "string" ? rmCommas(val) : val.toString()) || "0";
|
|
287
290
|
const [integerPart, fractionalPart = ""] = strVal.split(".");
|
|
288
291
|
let bigIntValue = BigInt(integerPart) * BigInt(10) ** BigInt(units);
|
|
289
292
|
if (fractionalPart) {
|
|
290
|
-
|
|
291
|
-
|
|
293
|
+
let fractionalValue;
|
|
294
|
+
if (fractionalPart.length > units) {
|
|
295
|
+
fractionalValue = BigInt(fractionalPart.slice(0, units));
|
|
296
|
+
} else {
|
|
297
|
+
fractionalValue = BigInt(fractionalPart.padEnd(units, "0"));
|
|
298
|
+
}
|
|
292
299
|
bigIntValue += fractionalValue;
|
|
293
300
|
}
|
|
294
301
|
return bigIntValue;
|
package/package.json
CHANGED
package/unit.cjs
CHANGED
|
@@ -229,13 +229,16 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
|
229
229
|
return "..." + str.slice(amount);
|
|
230
230
|
}
|
|
231
231
|
};
|
|
232
|
+
var rmCommas = (val) => val.replace(/,/g, "");
|
|
232
233
|
|
|
233
234
|
// src/unit.ts
|
|
234
235
|
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
|
|
235
236
|
var planckToUnit = (val, units) => {
|
|
236
237
|
try {
|
|
237
|
-
units = Math.max(units, 0);
|
|
238
|
-
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
238
|
+
units = Math.max(Math.round(units), 0);
|
|
239
|
+
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
240
|
+
typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
|
|
241
|
+
);
|
|
239
242
|
const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
|
|
240
243
|
const integerPart = bigIntVal / divisor;
|
|
241
244
|
const fractionalPart = bigIntVal % divisor;
|
|
@@ -247,12 +250,17 @@ var planckToUnit = (val, units) => {
|
|
|
247
250
|
};
|
|
248
251
|
var unitToPlanck = (val, units) => {
|
|
249
252
|
try {
|
|
250
|
-
|
|
253
|
+
units = Math.max(Math.round(units), 0);
|
|
254
|
+
const strVal = (typeof val === "string" ? rmCommas(val) : val.toString()) || "0";
|
|
251
255
|
const [integerPart, fractionalPart = ""] = strVal.split(".");
|
|
252
256
|
let bigIntValue = BigInt(integerPart) * BigInt(10) ** BigInt(units);
|
|
253
257
|
if (fractionalPart) {
|
|
254
|
-
|
|
255
|
-
|
|
258
|
+
let fractionalValue;
|
|
259
|
+
if (fractionalPart.length > units) {
|
|
260
|
+
fractionalValue = BigInt(fractionalPart.slice(0, units));
|
|
261
|
+
} else {
|
|
262
|
+
fractionalValue = BigInt(fractionalPart.padEnd(units, "0"));
|
|
263
|
+
}
|
|
256
264
|
bigIntValue += fractionalValue;
|
|
257
265
|
}
|
|
258
266
|
return bigIntValue;
|
package/unit.js
CHANGED
|
@@ -172,13 +172,16 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
|
172
172
|
return "..." + str.slice(amount);
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
|
+
var rmCommas = (val) => val.replace(/,/g, "");
|
|
175
176
|
|
|
176
177
|
// src/unit.ts
|
|
177
178
|
import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
|
|
178
179
|
var planckToUnit = (val, units) => {
|
|
179
180
|
try {
|
|
180
|
-
units = Math.max(units, 0);
|
|
181
|
-
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
181
|
+
units = Math.max(Math.round(units), 0);
|
|
182
|
+
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
183
|
+
typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
|
|
184
|
+
);
|
|
182
185
|
const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
|
|
183
186
|
const integerPart = bigIntVal / divisor;
|
|
184
187
|
const fractionalPart = bigIntVal % divisor;
|
|
@@ -190,12 +193,17 @@ var planckToUnit = (val, units) => {
|
|
|
190
193
|
};
|
|
191
194
|
var unitToPlanck = (val, units) => {
|
|
192
195
|
try {
|
|
193
|
-
|
|
196
|
+
units = Math.max(Math.round(units), 0);
|
|
197
|
+
const strVal = (typeof val === "string" ? rmCommas(val) : val.toString()) || "0";
|
|
194
198
|
const [integerPart, fractionalPart = ""] = strVal.split(".");
|
|
195
199
|
let bigIntValue = BigInt(integerPart) * BigInt(10) ** BigInt(units);
|
|
196
200
|
if (fractionalPart) {
|
|
197
|
-
|
|
198
|
-
|
|
201
|
+
let fractionalValue;
|
|
202
|
+
if (fractionalPart.length > units) {
|
|
203
|
+
fractionalValue = BigInt(fractionalPart.slice(0, units));
|
|
204
|
+
} else {
|
|
205
|
+
fractionalValue = BigInt(fractionalPart.padEnd(units, "0"));
|
|
206
|
+
}
|
|
199
207
|
bigIntValue += fractionalValue;
|
|
200
208
|
}
|
|
201
209
|
return bigIntValue;
|