Skip to content

Instantly share code, notes, and snippets.

@techieshark
Created February 22, 2019 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techieshark/f4f5c9404b934e3fb98eb92b165beb53 to your computer and use it in GitHub Desktop.
Save techieshark/f4f5c9404b934e3fb98eb92b165beb53 to your computer and use it in GitHub Desktop.
browserFeatures
/**
* 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