UNPKG

@dailyshot/hooks

Version:

A set of hooks used in Dailyshot packages

45 lines (40 loc) 1.21 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var React = require('react'); var useIsomorphicEffect = require('../use-isomorphic-effect/use-isomorphic-effect.js'); function getOS() { if (typeof window === "undefined") { return "undetermined"; } const { userAgent } = window.navigator; const macosPlatforms = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i; const windowsPlatforms = /(Win32)|(Win64)|(Windows)|(WinCE)/i; const iosPlatforms = /(iPhone)|(iPad)|(iPod)/i; if (macosPlatforms.test(userAgent)) { return "macos"; } if (iosPlatforms.test(userAgent)) { return "ios"; } if (windowsPlatforms.test(userAgent)) { return "windows"; } if (/Android/i.test(userAgent)) { return "android"; } if (/Linux/i.test(userAgent)) { return "linux"; } return "undetermined"; } function useOs(options = { getValueInEffect: true }) { const [value, setValue] = React.useState(options.getValueInEffect ? "undetermined" : getOS()); useIsomorphicEffect.useIsomorphicEffect(() => { if (options.getValueInEffect) { setValue(getOS); } }, []); return value; } exports.useOs = useOs; //# sourceMappingURL=use-os.js.map