i18n-number
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -32,2 +32,3 @@ /** | ||
var _setupIntlPolyfillCalled = false; | ||
var formatCache = new Map(); | ||
@@ -570,2 +571,19 @@ /** | ||
/** | ||
* Get a cached Intl.NumberFormat object | ||
* | ||
* @param {string} lang Locale for formatting. | ||
* @param {Object} options Options for Intl.NumberFormat. | ||
* @return {Object} Intl.NumberFormat object. | ||
*/ | ||
_getNumberFormatObject(lang, options) { | ||
let formatId = lang + JSON.stringify(options); | ||
let formatObject = formatCache.get(formatId); | ||
if (!formatObject) { | ||
formatObject = new Intl.NumberFormat(lang, options); | ||
formatCache.set(formatId, formatObject); | ||
} | ||
return formatObject; | ||
}, | ||
/** | ||
* Formats the number | ||
@@ -591,3 +609,3 @@ * | ||
}.bind(this))) { | ||
return new Intl.NumberFormat(lang, options).format(number); | ||
return this._getNumberFormatObject(lang, options).format(number); | ||
} | ||
@@ -607,3 +625,3 @@ else { | ||
try { | ||
return new Intl.NumberFormat(lang, options).format(number); | ||
return this._getNumberFormatObject(lang, options).format(number); | ||
} | ||
@@ -610,0 +628,0 @@ catch (e) { |
@@ -18,3 +18,3 @@ { | ||
"name": "i18n-number", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"main": "i18n-number.js", | ||
@@ -21,0 +21,0 @@ "directories": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
269586
5618