@coingecko/cryptoformat 0.8.1 → 0.8.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.
- package/lib/cryptoformat.cjs.js +11 -5
- package/lib/cryptoformat.esm.js +11 -5
- package/lib/cryptoformat.umd.js +11 -5
- package/package.json +1 -1
package/lib/cryptoformat.cjs.js
CHANGED
|
@@ -152,12 +152,12 @@ function generateIntlNumberFormatter(isoCode, locale, numDecimals, numSigFig) {
|
|
|
152
152
|
} catch (e) {
|
|
153
153
|
// Unsupported currency, etc.
|
|
154
154
|
// Use primitive fallback
|
|
155
|
-
return generateFallbackFormatter(isoCode, locale, numDecimals);
|
|
155
|
+
return generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// Generates a primitive fallback formatter with no symbol support.
|
|
160
|
-
function generateFallbackFormatter(isoCode, locale, numDecimals = 2) {
|
|
160
|
+
function generateFallbackFormatter(isoCode, locale, numDecimals = 2, maximumSignificantDigits = 4) {
|
|
161
161
|
isoCode = isoCode.toUpperCase();
|
|
162
162
|
|
|
163
163
|
if (numDecimals > 2) {
|
|
@@ -171,9 +171,15 @@ function generateFallbackFormatter(isoCode, locale, numDecimals = 2) {
|
|
|
171
171
|
} else {
|
|
172
172
|
return {
|
|
173
173
|
format: (value) => {
|
|
174
|
+
let formattedValue = value;
|
|
175
|
+
// try using Intl.NumberFormat when possible to support max significant digits
|
|
176
|
+
try {
|
|
177
|
+
formattedValue = new Intl.NumberFormat(locale, { maximumSignificantDigits }).format(value);
|
|
178
|
+
} catch (e) {}
|
|
179
|
+
|
|
174
180
|
return isCrypto(isoCode)
|
|
175
|
-
? `${
|
|
176
|
-
: `${isoCode} ${
|
|
181
|
+
? `${formattedValue.toLocaleString(locale)} ${isoCode}`
|
|
182
|
+
: `${isoCode} ${formattedValue.toLocaleString(locale)}`;
|
|
177
183
|
},
|
|
178
184
|
};
|
|
179
185
|
}
|
|
@@ -203,7 +209,7 @@ function generateFormatter(isoCode, locale, numDecimals, numSigFig) {
|
|
|
203
209
|
isNumberFormatSupported && (!isCrypto(isoCode) || isBTCETH(isoCode));
|
|
204
210
|
return useIntlNumberFormatter
|
|
205
211
|
? generateIntlNumberFormatter(isoCode, locale, numDecimals, numSigFig)
|
|
206
|
-
: generateFallbackFormatter(isoCode, locale, numDecimals);
|
|
212
|
+
: generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig);
|
|
207
213
|
}
|
|
208
214
|
|
|
209
215
|
// State variables
|
package/lib/cryptoformat.esm.js
CHANGED
|
@@ -148,12 +148,12 @@ function generateIntlNumberFormatter(isoCode, locale, numDecimals, numSigFig) {
|
|
|
148
148
|
} catch (e) {
|
|
149
149
|
// Unsupported currency, etc.
|
|
150
150
|
// Use primitive fallback
|
|
151
|
-
return generateFallbackFormatter(isoCode, locale, numDecimals);
|
|
151
|
+
return generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// Generates a primitive fallback formatter with no symbol support.
|
|
156
|
-
function generateFallbackFormatter(isoCode, locale, numDecimals = 2) {
|
|
156
|
+
function generateFallbackFormatter(isoCode, locale, numDecimals = 2, maximumSignificantDigits = 4) {
|
|
157
157
|
isoCode = isoCode.toUpperCase();
|
|
158
158
|
|
|
159
159
|
if (numDecimals > 2) {
|
|
@@ -167,9 +167,15 @@ function generateFallbackFormatter(isoCode, locale, numDecimals = 2) {
|
|
|
167
167
|
} else {
|
|
168
168
|
return {
|
|
169
169
|
format: (value) => {
|
|
170
|
+
let formattedValue = value;
|
|
171
|
+
// try using Intl.NumberFormat when possible to support max significant digits
|
|
172
|
+
try {
|
|
173
|
+
formattedValue = new Intl.NumberFormat(locale, { maximumSignificantDigits }).format(value);
|
|
174
|
+
} catch (e) {}
|
|
175
|
+
|
|
170
176
|
return isCrypto(isoCode)
|
|
171
|
-
? `${
|
|
172
|
-
: `${isoCode} ${
|
|
177
|
+
? `${formattedValue.toLocaleString(locale)} ${isoCode}`
|
|
178
|
+
: `${isoCode} ${formattedValue.toLocaleString(locale)}`;
|
|
173
179
|
},
|
|
174
180
|
};
|
|
175
181
|
}
|
|
@@ -199,7 +205,7 @@ function generateFormatter(isoCode, locale, numDecimals, numSigFig) {
|
|
|
199
205
|
isNumberFormatSupported && (!isCrypto(isoCode) || isBTCETH(isoCode));
|
|
200
206
|
return useIntlNumberFormatter
|
|
201
207
|
? generateIntlNumberFormatter(isoCode, locale, numDecimals, numSigFig)
|
|
202
|
-
: generateFallbackFormatter(isoCode, locale, numDecimals);
|
|
208
|
+
: generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig);
|
|
203
209
|
}
|
|
204
210
|
|
|
205
211
|
// State variables
|
package/lib/cryptoformat.umd.js
CHANGED
|
@@ -154,12 +154,12 @@
|
|
|
154
154
|
} catch (e) {
|
|
155
155
|
// Unsupported currency, etc.
|
|
156
156
|
// Use primitive fallback
|
|
157
|
-
return generateFallbackFormatter(isoCode, locale, numDecimals);
|
|
157
|
+
return generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
// Generates a primitive fallback formatter with no symbol support.
|
|
162
|
-
function generateFallbackFormatter(isoCode, locale, numDecimals = 2) {
|
|
162
|
+
function generateFallbackFormatter(isoCode, locale, numDecimals = 2, maximumSignificantDigits = 4) {
|
|
163
163
|
isoCode = isoCode.toUpperCase();
|
|
164
164
|
|
|
165
165
|
if (numDecimals > 2) {
|
|
@@ -173,9 +173,15 @@
|
|
|
173
173
|
} else {
|
|
174
174
|
return {
|
|
175
175
|
format: (value) => {
|
|
176
|
+
let formattedValue = value;
|
|
177
|
+
// try using Intl.NumberFormat when possible to support max significant digits
|
|
178
|
+
try {
|
|
179
|
+
formattedValue = new Intl.NumberFormat(locale, { maximumSignificantDigits }).format(value);
|
|
180
|
+
} catch (e) {}
|
|
181
|
+
|
|
176
182
|
return isCrypto(isoCode)
|
|
177
|
-
? `${
|
|
178
|
-
: `${isoCode} ${
|
|
183
|
+
? `${formattedValue.toLocaleString(locale)} ${isoCode}`
|
|
184
|
+
: `${isoCode} ${formattedValue.toLocaleString(locale)}`;
|
|
179
185
|
},
|
|
180
186
|
};
|
|
181
187
|
}
|
|
@@ -205,7 +211,7 @@
|
|
|
205
211
|
isNumberFormatSupported && (!isCrypto(isoCode) || isBTCETH(isoCode));
|
|
206
212
|
return useIntlNumberFormatter
|
|
207
213
|
? generateIntlNumberFormatter(isoCode, locale, numDecimals, numSigFig)
|
|
208
|
-
: generateFallbackFormatter(isoCode, locale, numDecimals);
|
|
214
|
+
: generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig);
|
|
209
215
|
}
|
|
210
216
|
|
|
211
217
|
// State variables
|
package/package.json
CHANGED