UNPKG

@dvcol/common-utils

Version:

Typescript library for common utility functions and constants

16 lines (10 loc) 1.59 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// lib/common/utils/navigator.utils.ts var isMacOs = () => { const userAgent = _optionalChain([navigator, 'optionalAccess', _ => _.userAgent]); if (userAgent.indexOf("Mac") !== -1) return true; const platform = _nullishCoalesce(_optionalChain([navigator, 'optionalAccess', _2 => _2.userAgentData, 'optionalAccess', _3 => _3.platform]), () => ( _optionalChain([navigator, 'optionalAccess', _4 => _4.platform]))); return platform.indexOf("mac") !== -1; }; var getShortLocale = () => _nullishCoalesce(_optionalChain([navigator, 'optionalAccess', _5 => _5.language, 'optionalAccess', _6 => _6.split, 'call', _7 => _7("-"), 'access', _8 => _8.at, 'call', _9 => _9(0)]), () => ( "en")); var getNavigatorVersion = () => /Chrome\/([0-9.]+)/.exec(navigator.userAgent).at(1); exports.isMacOs = isMacOs; exports.getShortLocale = getShortLocale; exports.getNavigatorVersion = getNavigatorVersion;