Skip to content

Instantly share code, notes, and snippets.

@frankinedinburgh
Created July 15, 2018 11:06
Show Gist options
  • Save frankinedinburgh/b01b76be656d84d0ed3c9d15bece59ef to your computer and use it in GitHub Desktop.
Save frankinedinburgh/b01b76be656d84d0ed3c9d15bece59ef to your computer and use it in GitHub Desktop.
detect compatible browser
const minimumChromeCompatableVersion = 53;
export default function detectIncompatibleBrowser() {
/*
-- INCOMPATIBLE browsers --
whatsmybrowser.org/b/PC36ZMV
whatsmybrowser.org/b/UMYYENJ
whatsmybrowser.org/b/QJ96W2C
whatsmybrowser.org/b/9PU8664
whatsmybrowser.org/b/NZ7QMK4
whatsmybrowser.org/b/CS8S8WJ
whatsmybrowser.org/b/PASXHQT
whatsmybrowser.org/b/2AKGZ6G
-- COMPATIBLE browsers --
whatsmybrowser.org/b/JC7BXQW
*/
// samsung devices running stock browser
const isIncomptaible =
/SamsungBrowser/.test(navigator.userAgent) ||
(/SAMSUNG/.test(navigator.userAgent) && /Version\/[1-5]/.test(navigator.userAgent));
if (isIncomptaible) {
return true;
}
// devices running chrome version < minimumChromeCompatableVersion
const matches = navigator.userAgent.match(/Chrome\/([0-9]{1,2})/);
if (matches) {
const version = parseInt(matches[1], 10);
if (version < minimumChromeCompatableVersion) {
return true;
}
}
return false;
}
export default function formatNumberToAbbreviation(number) {
if (number >= 1000000) {
return `${(number / 1000000).toFixed(1)}M`;
} else if (number >= 1000) {
return `${(number / 1000).toFixed(1)}K`;
}
return (`${number}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment