decentraland-dapps 12.52.2 → 12.52.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.
- package/dist/lib/mana.d.ts +4 -0
- package/dist/lib/mana.js +30 -6
- package/dist/lib/mana.js.map +1 -1
- package/package.json +1 -1
package/dist/lib/mana.d.ts
CHANGED
|
@@ -4,3 +4,7 @@ export declare const MAXIMUM_FRACTION_DIGITS = 2;
|
|
|
4
4
|
* It'll return the value as is if it's an invalid number or it doesn't have more than decimals than the upper limit.
|
|
5
5
|
*/
|
|
6
6
|
export declare function toFixedMANAValue(strValue: string, maximumFractionDigits?: number): string;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the amount of trailing zeros
|
|
9
|
+
*/
|
|
10
|
+
export declare function getTrailingZeros(strValue: string): number;
|
package/dist/lib/mana.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toFixedMANAValue = exports.MAXIMUM_FRACTION_DIGITS = void 0;
|
|
3
|
+
exports.getTrailingZeros = exports.toFixedMANAValue = exports.MAXIMUM_FRACTION_DIGITS = void 0;
|
|
4
4
|
// Careful! This value is normally later formated by `toLocaleString` **but** if it ever goes above 3 (the default min maximumFractionDigits),
|
|
5
5
|
// we should review every call to `toLocaleString` as it will round up values beyond that decimal point
|
|
6
6
|
exports.MAXIMUM_FRACTION_DIGITS = 2;
|
|
@@ -13,15 +13,39 @@ function toFixedMANAValue(strValue, maximumFractionDigits = exports.MAXIMUM_FRAC
|
|
|
13
13
|
if (!isNaN(value)) {
|
|
14
14
|
const decimals = value.toString().split('.')[1];
|
|
15
15
|
const decimalsCount = decimals ? decimals.length : 0;
|
|
16
|
-
|
|
16
|
+
const trailingZeros = getTrailingZeros(strValue);
|
|
17
|
+
if (trailingZeros + decimalsCount >= maximumFractionDigits) {
|
|
17
18
|
return value.toFixed(maximumFractionDigits);
|
|
18
19
|
}
|
|
19
|
-
else if (Number(strValue) === value) {
|
|
20
|
-
// when the original string was a valid number, return the parsed value to remove trailing zeros
|
|
21
|
-
return value.toString();
|
|
22
|
-
}
|
|
23
20
|
}
|
|
24
21
|
return strValue;
|
|
25
22
|
}
|
|
26
23
|
exports.toFixedMANAValue = toFixedMANAValue;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the amount of trailing zeros
|
|
26
|
+
*/
|
|
27
|
+
function getTrailingZeros(strValue) {
|
|
28
|
+
// count zeros
|
|
29
|
+
let zeros = 0;
|
|
30
|
+
// parse string value to remove trailing zeros
|
|
31
|
+
const parsed = parseFloat(strValue);
|
|
32
|
+
// remove parsed value from original string value (ie. string value is "1.0576000" and parsed is "1.0576" the rest would be "000")
|
|
33
|
+
let rest = strValue.split(parsed.toString()).pop();
|
|
34
|
+
// if after removing the parsed value there's nothing left, return 0
|
|
35
|
+
if (!rest) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
// if the first char is a dot, skip it (this would be the case for an integer with decimals, like "1.00")
|
|
39
|
+
if (rest[0] === '.') {
|
|
40
|
+
rest = rest.slice(1);
|
|
41
|
+
}
|
|
42
|
+
// count zeros
|
|
43
|
+
while (rest[0] === '0') {
|
|
44
|
+
zeros++;
|
|
45
|
+
rest = rest.slice(1);
|
|
46
|
+
}
|
|
47
|
+
// return amount
|
|
48
|
+
return zeros;
|
|
49
|
+
}
|
|
50
|
+
exports.getTrailingZeros = getTrailingZeros;
|
|
27
51
|
//# sourceMappingURL=mana.js.map
|
package/dist/lib/mana.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mana.js","sourceRoot":"","sources":["../../src/lib/mana.ts"],"names":[],"mappings":";;;AAAA,8IAA8I;AAC9I,uGAAuG;AAC1F,QAAA,uBAAuB,GAAG,CAAC,CAAA;AAExC;;;GAGG;AACH,SAAgB,gBAAgB,CAC9B,QAAgB,EAChB,qBAAqB,GAAG,+BAAuB;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