@pallasoft/ps-utilities 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,3 +7,4 @@ export * from './user-token-config';
7
7
  export * from './validation-config';
8
8
  export * from './file-size-config';
9
9
  export * from './socket-token-config';
10
+ export * from './user-agent-config';
@@ -23,3 +23,4 @@ __exportStar(require("./user-token-config"), exports);
23
23
  __exportStar(require("./validation-config"), exports);
24
24
  __exportStar(require("./file-size-config"), exports);
25
25
  __exportStar(require("./socket-token-config"), exports);
26
+ __exportStar(require("./user-agent-config"), exports);
@@ -0,0 +1,36 @@
1
+ export declare const UserAgentConfig: {
2
+ readonly browsers: readonly [{
3
+ readonly name: "Edge";
4
+ readonly pattern: RegExp;
5
+ }, {
6
+ readonly name: "Opera";
7
+ readonly pattern: RegExp;
8
+ }, {
9
+ readonly name: "Firefox";
10
+ readonly pattern: RegExp;
11
+ }, {
12
+ readonly name: "Chrome";
13
+ readonly pattern: RegExp;
14
+ }, {
15
+ readonly name: "Safari";
16
+ readonly pattern: RegExp;
17
+ }];
18
+ readonly systems: readonly [{
19
+ readonly name: "iOS";
20
+ readonly pattern: RegExp;
21
+ }, {
22
+ readonly name: "Android";
23
+ readonly pattern: RegExp;
24
+ }, {
25
+ readonly name: "Windows";
26
+ readonly pattern: RegExp;
27
+ }, {
28
+ readonly name: "macOS";
29
+ readonly pattern: RegExp;
30
+ }, {
31
+ readonly name: "Linux";
32
+ readonly pattern: RegExp;
33
+ }];
34
+ readonly unknown: "Unknown device";
35
+ readonly joiner: " on ";
36
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserAgentConfig = void 0;
4
+ exports.UserAgentConfig = {
5
+ browsers: [
6
+ { name: 'Edge', pattern: /Edg\//i },
7
+ { name: 'Opera', pattern: /OPR\//i },
8
+ { name: 'Firefox', pattern: /Firefox\//i },
9
+ { name: 'Chrome', pattern: /(Chrome|CriOS)\//i },
10
+ { name: 'Safari', pattern: /Safari\//i },
11
+ ],
12
+ systems: [
13
+ { name: 'iOS', pattern: /iPhone|iPad|iPod/i },
14
+ { name: 'Android', pattern: /Android/i },
15
+ { name: 'Windows', pattern: /Windows/i },
16
+ { name: 'macOS', pattern: /Mac OS X|Macintosh/i },
17
+ { name: 'Linux', pattern: /Linux/i },
18
+ ],
19
+ unknown: 'Unknown device',
20
+ joiner: ' on ',
21
+ };
@@ -16,5 +16,6 @@ export * from './socket-token-service';
16
16
  export * from './string-service';
17
17
  export * from './transform-service';
18
18
  export * from './url-service';
19
+ export * from './user-agent-service';
19
20
  export * from './user-token-service';
20
21
  export * from './validation-service';
@@ -32,5 +32,6 @@ __exportStar(require("./socket-token-service"), exports);
32
32
  __exportStar(require("./string-service"), exports);
33
33
  __exportStar(require("./transform-service"), exports);
34
34
  __exportStar(require("./url-service"), exports);
35
+ __exportStar(require("./user-agent-service"), exports);
35
36
  __exportStar(require("./user-token-service"), exports);
36
37
  __exportStar(require("./validation-service"), exports);
@@ -0,0 +1,5 @@
1
+ export declare class UserAgentService {
2
+ static browser(userAgent: string | null): string | null;
3
+ static system(userAgent: string | null): string | null;
4
+ static describe(userAgent: string | null): string;
5
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserAgentService = void 0;
4
+ var user_agent_config_1 = require("./constants/user-agent-config");
5
+ var UserAgentService = /** @class */ (function () {
6
+ function UserAgentService() {
7
+ }
8
+ UserAgentService.browser = function (userAgent) {
9
+ if (userAgent === null)
10
+ return null;
11
+ var match = user_agent_config_1.UserAgentConfig.browsers.find(function (browser) { return browser.pattern.test(userAgent); });
12
+ return match === undefined ? null : match.name;
13
+ };
14
+ UserAgentService.system = function (userAgent) {
15
+ if (userAgent === null)
16
+ return null;
17
+ var match = user_agent_config_1.UserAgentConfig.systems.find(function (system) { return system.pattern.test(userAgent); });
18
+ return match === undefined ? null : match.name;
19
+ };
20
+ UserAgentService.describe = function (userAgent) {
21
+ var browser = UserAgentService.browser(userAgent);
22
+ var system = UserAgentService.system(userAgent);
23
+ if (browser === null && system === null)
24
+ return user_agent_config_1.UserAgentConfig.unknown;
25
+ if (browser === null)
26
+ return String(system);
27
+ if (system === null)
28
+ return browser;
29
+ return "".concat(browser).concat(user_agent_config_1.UserAgentConfig.joiner).concat(system);
30
+ };
31
+ return UserAgentService;
32
+ }());
33
+ exports.UserAgentService = UserAgentService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-utilities",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -87,5 +87,15 @@
87
87
  "socket.io-client": {
88
88
  "optional": true
89
89
  }
90
+ },
91
+ "typesVersions": {
92
+ "*": {
93
+ "server": [
94
+ "dist/server/index.d.ts"
95
+ ],
96
+ "sockets": [
97
+ "dist/sockets/index.d.ts"
98
+ ]
99
+ }
90
100
  }
91
101
  }