Created
February 22, 2019 20:50
-
-
Save techieshark/f4f5c9404b934e3fb98eb92b165beb53 to your computer and use it in GitHub Desktop.
browserFeatures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns whether the current browser supports | |
* the `locales` argument of Number.prototype.toLocaleString(). | |
* IE < 11 does not. | |
* Copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Checking_for_support_for_locales_and_options_arguments | |
* @return {boolean} true if browser supports it, otherwise false. | |
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Browser_compatibility | |
*/ | |
function toLocaleStringSupportsLocales() { | |
const number = 0; | |
try { | |
number.toLocaleString('i'); | |
} catch (e) { | |
return e.name === 'RangeError'; | |
} | |
return false; | |
} | |
/** | |
* Returns whether the current browser supports | |
* the `locales` argument of Number.prototype.toLocaleString(). | |
* IE < 11 does not. | |
* Copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Checking_for_support_for_locales_and_options_arguments | |
* @return {boolean} true if browser supports it, otherwise false. | |
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Browser_compatibility | |
*/ | |
function toLocaleStringSupportsOptions() { | |
return !!(typeof Intl === 'object' && Intl && typeof Intl.NumberFormat === 'function'); | |
} | |
export default { | |
toLocaleStringSupportsLocales, | |
toLocaleStringSupportsOptions, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment