@alitu/user-agents-v2-api 0.1.2 → 0.1.4

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.
package/dist/index.d.ts CHANGED
@@ -1,11 +1,8 @@
1
1
  import type { OPAWGPatternEntry } from './user-agents-v2';
2
- type ParseUserAgentResult = (OPAWGPatternEntry & {
3
- filename: string;
4
- }) | undefined;
5
2
  /**
6
3
  * Search OPAWG user-agent-v2 lists for User-Agent string.
7
4
  * @param {string} userAgent User-Agent string
8
5
  * @returns {OPAWGPatternEntry | undefined} OPAWG pattern entry, undefined if not found
9
6
  */
10
- export default function parseUserAgent(userAgent: string): ParseUserAgentResult;
11
- export {};
7
+ export default function parseUserAgent(userAgent: string): OPAWGPatternEntry | undefined;
8
+ export { OPAWGFileType } from './user-agents-v2';
package/dist/index.js CHANGED
@@ -1,25 +1,15 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPAWGFileType = void 0;
14
4
  exports.default = parseUserAgent;
15
5
  var user_agents_v2_1 = require("./user-agents-v2");
16
6
  // Files must be searched in this order to accurately identify User-Agent
17
7
  // https://github.com/the-podcast-host/user-agents-v2?tab=readme-ov-file#quick-start
18
8
  var files = [
19
- { filename: 'bots', entries: user_agents_v2_1.default.bots },
20
- { filename: 'apps', entries: user_agents_v2_1.default.apps },
21
- { filename: 'libraries', entries: user_agents_v2_1.default.libraries },
22
- { filename: 'browsers', entries: user_agents_v2_1.default.browsers },
9
+ user_agents_v2_1.default.bots,
10
+ user_agents_v2_1.default.apps,
11
+ user_agents_v2_1.default.libraries,
12
+ user_agents_v2_1.default.browsers,
23
13
  ];
24
14
  /**
25
15
  * Check if a string is URL encoded.
@@ -48,18 +38,20 @@ function parseUserAgent(userAgent) {
48
38
  ? decodeURIComponent(userAgent)
49
39
  : userAgent;
50
40
  // Remove newlines
51
- sanitizedUserAgent = userAgent.replace(/(\r\n|\n|\r)/g, '');
41
+ sanitizedUserAgent = sanitizedUserAgent.replace(/(\r\n|\n|\r)/g, '');
52
42
  // Iterate lists in order
53
43
  for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
54
- var _a = files_1[_i], filename = _a.filename, entries = _a.entries;
55
- for (var _b = 0, entries_1 = entries; _b < entries_1.length; _b++) {
56
- var entry = entries_1[_b];
44
+ var entries = files_1[_i];
45
+ for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {
46
+ var entry = entries_1[_a];
57
47
  // Return entry if match is found
58
48
  if (sanitizedUserAgent.match(entry.regexp)) {
59
- return __assign({ filename: filename }, entry);
49
+ return entry;
60
50
  }
61
51
  }
62
52
  }
63
53
  // If no match is found, return undefined
64
54
  return undefined;
65
55
  }
56
+ var user_agents_v2_2 = require("./user-agents-v2");
57
+ Object.defineProperty(exports, "OPAWGFileType", { enumerable: true, get: function () { return user_agents_v2_2.OPAWGFileType; } });
@@ -1,74 +1,17 @@
1
1
  import type { OPAWGPatternsFile } from './patterns';
2
+ export declare const OPAWGFileType: {
3
+ readonly Apps: "apps";
4
+ readonly Bots: "bots";
5
+ readonly Browsers: "browsers";
6
+ readonly Devices: "devices";
7
+ readonly Libraries: "libraries";
8
+ readonly Referrers: "referrers";
9
+ };
10
+ type OPAWGFileType = (typeof OPAWGFileType)[keyof typeof OPAWGFileType];
2
11
  type Entry = NonNullable<OPAWGPatternsFile['entries']>[number];
3
- export interface OPAWGPatternEntry extends Entry {
12
+ export type OPAWGPatternEntry = Entry & {
13
+ type: OPAWGFileType;
4
14
  regexp: RegExp;
5
- }
6
- declare const _default: {
7
- apps: {
8
- regexp: RegExp;
9
- name: string;
10
- pattern: string;
11
- description?: string;
12
- svg?: string;
13
- comments?: string;
14
- examples?: string[];
15
- urls?: string[];
16
- category?: string;
17
- }[];
18
- bots: {
19
- regexp: RegExp;
20
- name: string;
21
- pattern: string;
22
- description?: string;
23
- svg?: string;
24
- comments?: string;
25
- examples?: string[];
26
- urls?: string[];
27
- category?: string;
28
- }[];
29
- browsers: {
30
- regexp: RegExp;
31
- name: string;
32
- pattern: string;
33
- description?: string;
34
- svg?: string;
35
- comments?: string;
36
- examples?: string[];
37
- urls?: string[];
38
- category?: string;
39
- }[];
40
- devices: {
41
- regexp: RegExp;
42
- name: string;
43
- pattern: string;
44
- description?: string;
45
- svg?: string;
46
- comments?: string;
47
- examples?: string[];
48
- urls?: string[];
49
- category?: string;
50
- }[];
51
- libraries: {
52
- regexp: RegExp;
53
- name: string;
54
- pattern: string;
55
- description?: string;
56
- svg?: string;
57
- comments?: string;
58
- examples?: string[];
59
- urls?: string[];
60
- category?: string;
61
- }[];
62
- referrers: {
63
- regexp: RegExp;
64
- name: string;
65
- pattern: string;
66
- description?: string;
67
- svg?: string;
68
- comments?: string;
69
- examples?: string[];
70
- urls?: string[];
71
- category?: string;
72
- }[];
73
15
  };
74
- export default _default;
16
+ declare const UserAgentsV2: Record<OPAWGFileType, OPAWGPatternEntry[]>;
17
+ export default UserAgentsV2;
@@ -11,28 +11,38 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.OPAWGFileType = void 0;
14
15
  var apps = require("./apps.json");
15
16
  var bots = require("./bots.json");
16
17
  var browsers = require("./browsers.json");
17
18
  var devices = require("./devices.json");
18
19
  var libraries = require("./libraries.json");
19
20
  var referrers = require("./referrers.json");
21
+ exports.OPAWGFileType = {
22
+ Apps: 'apps',
23
+ Bots: 'bots',
24
+ Browsers: 'browsers',
25
+ Devices: 'devices',
26
+ Libraries: 'libraries',
27
+ Referrers: 'referrers',
28
+ };
20
29
  /**
21
30
  * Extract entries from User-Agent lists and create RegExp for patterns.
22
31
  * @param {OPAWGPatternsFile} file patterns file
23
32
  * @returns {OPAWGPatternEntry[]} array of entries with RegExps
24
33
  */
25
- function initializePatternFile(_a) {
34
+ function initializePatternFile(type, _a) {
26
35
  var entries = _a.entries;
27
36
  return entries.map(function (entry) {
28
- return __assign(__assign({}, entry), { regexp: new RegExp(entry.pattern) });
37
+ return __assign(__assign({}, entry), { type: type, regexp: new RegExp(entry.pattern) });
29
38
  });
30
39
  }
31
- exports.default = {
32
- apps: initializePatternFile(apps),
33
- bots: initializePatternFile(bots),
34
- browsers: initializePatternFile(browsers),
35
- devices: initializePatternFile(devices),
36
- libraries: initializePatternFile(libraries),
37
- referrers: initializePatternFile(referrers),
40
+ var UserAgentsV2 = {
41
+ apps: initializePatternFile(exports.OPAWGFileType.Apps, apps),
42
+ bots: initializePatternFile(exports.OPAWGFileType.Bots, bots),
43
+ browsers: initializePatternFile(exports.OPAWGFileType.Browsers, browsers),
44
+ devices: initializePatternFile(exports.OPAWGFileType.Devices, devices),
45
+ libraries: initializePatternFile(exports.OPAWGFileType.Libraries, libraries),
46
+ referrers: initializePatternFile(exports.OPAWGFileType.Referrers, referrers),
38
47
  };
48
+ exports.default = UserAgentsV2;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * This file was automatically generated by json-schema-to-typescript.
3
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
+ * and run json-schema-to-typescript to regenerate this file.
5
+ */
6
+ /**
7
+ * Top-level file, containing a list of named entries, their associated regular expression patterns, and other properties
8
+ */
9
+ export interface OPAWGPatternsFile {
10
+ /**
11
+ * Usage notes about this file.
12
+ */
13
+ comments?: string[];
14
+ /**
15
+ * Ordered list of named entries, their associated regular expression patterns, and other properties.
16
+ */
17
+ entries?: {
18
+ /**
19
+ * Name of this entry, must be unique within the file.
20
+ */
21
+ name: string;
22
+ /**
23
+ * Regular expression pattern identifying this entry. For max compatibility: avoid lookaheads or programming-language-specific character classes. Example: "^MyThing/"
24
+ */
25
+ pattern: string;
26
+ /**
27
+ * Optional summary description of this entry.
28
+ */
29
+ description?: string;
30
+ /**
31
+ * Optional associated icon filename as found in the svg directory. Example: "my-thing.svg"
32
+ */
33
+ svg?: string;
34
+ /**
35
+ * Optional notes about this entry.
36
+ */
37
+ comments?: string;
38
+ /**
39
+ * Optional examples found in the wild that this entry is intended to match against, useful for pattern development and automated testing.
40
+ */
41
+ examples?: string[];
42
+ /**
43
+ * One or more optional informational urls about this entry. Example: "https://my-thing.example.com"
44
+ */
45
+ urls?: string[];
46
+ /**
47
+ * Optional category for this entry, depends on the type of the containing entry file (e.g. "mobile" in the 'devices' file, or "app" in the 'referrers' file).
48
+ */
49
+ category?: string;
50
+ [k: string]: unknown;
51
+ }[];
52
+ [k: string]: unknown;
53
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ /**
4
+ * This file was automatically generated by json-schema-to-typescript.
5
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
6
+ * and run json-schema-to-typescript to regenerate this file.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alitu/user-agents-v2-api",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "API for identifying User-Agent strings using OPAWG's user-agents-v2 lists.",
5
5
  "main": "dist/index.js",
6
6
  "repository": {