UNPKG

use-breakpoint-agent

Version:
19 lines (18 loc) 765 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDeviceTypeFromString = getDeviceTypeFromString; const types_1 = require("../types/index.js"); const ua_parser_js_1 = require("ua-parser-js"); function getDeviceTypeFromString(input) { var _a; if (typeof window === "undefined") { throw new Error("use-breakpoint-agent/client cannot be used on the server side"); } const data = (0, ua_parser_js_1.UAParser)(input || navigator.userAgent); const device = (_a = data.device) === null || _a === void 0 ? void 0 : _a.type; if (device === "mobile") return types_1.DeviceEnum.MOBILE; if (device === "tablet") return types_1.DeviceEnum.TABLET; return types_1.DeviceEnum.DESKTOP; }