diffusion
Version:
Diffusion JavaScript client
36 lines (35 loc) • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEnvironmentString = void 0;
var ua_parser_js_1 = require("ua-parser-js");
/**
* Queries the current environment and returns a string that can be used to
* set the `$Environment` session property.
*
* @returns The environment string
*/ // istanbul ignore next
function getEnvironmentString() {
var _a;
// check for browser
try {
if (typeof navigator !== 'undefined') {
var parser = new ua_parser_js_1.UAParser(navigator.userAgent);
var browser = parser.getBrowser();
return "BROWSER_" + browser.name + "_" + browser.version;
}
}
catch (e) {
/* no-op */
}
// check for node
try {
if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) !== undefined) {
return "NODE_" + process.platform + "_" + process.versions.node;
}
}
catch (e) {
/* no-op */
}
return 'BROWSER_UNKNOWN';
}
exports.getEnvironmentString = getEnvironmentString;