UNPKG

1.88 kBJavaScriptView Raw
1'use strict';
2
3var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
5var _package = require('../package.json');
6
7function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
9var UserAgent = function () {
10 function UserAgent(client) {
11 _classCallCheck(this, UserAgent);
12
13 if (!client) {
14 throw new Error('"client" arg is required to create a UserAgent.');
15 }
16 this._client = client;
17 }
18
19 _createClass(UserAgent, [{
20 key: 'toString',
21 value: function toString() {
22 var client = ['Percy/' + this._apiVersion(), this._client._sdkClientInfo, this._client._clientInfo, 'percy-js/' + _package.version].filter(function (el) {
23 return el != null;
24 }).join(' ');
25
26 var environment = [this._client._sdkEnvironmentInfo, this._client._environmentInfo, 'node/' + this._nodeVersion(), this._client.environment.ciVersion].filter(function (el) {
27 return el != null;
28 }).join('; ');
29
30 return client + ' (' + environment + ')';
31 }
32 }, {
33 key: '_nodeVersion',
34 value: function _nodeVersion() {
35 return process.version;
36 }
37 }, {
38 key: '_apiVersion',
39 value: function _apiVersion() {
40 return (/\w+$/.exec(this._client.apiUrl)
41 );
42 }
43 }]);
44
45 return UserAgent;
46}();
47
48module.exports = UserAgent;
\No newline at end of file