New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@alitu/user-agents-v2-api

Package Overview
Dependencies
Maintainers
0
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alitu/user-agents-v2-api - npm Package Compare versions

Comparing version 0.1.6 to 0.2.1

3

dist/index.d.ts

@@ -5,5 +5,6 @@ import type { OPAWGPatternEntry } from './user-agents-v2';

* @param {string} userAgent User-Agent string
* @param {string} [referrer] Referer string
* @returns {OPAWGPatternEntry | undefined} OPAWG pattern entry, undefined if not found
*/
export default function parseUserAgent(userAgent: string): OPAWGPatternEntry | undefined;
export default function parseUserAgent(userAgent: string, referrer?: string): OPAWGPatternEntry | undefined;
export { OPAWGFileType } from './user-agents-v2';

@@ -30,5 +30,6 @@ "use strict";

* @param {string} userAgent User-Agent string
* @param {string} [referrer] Referer string
* @returns {OPAWGPatternEntry | undefined} OPAWG pattern entry, undefined if not found
*/
function parseUserAgent(userAgent) {
function parseUserAgent(userAgent, referrer) {
// Skip empty strings

@@ -43,4 +44,5 @@ if (!userAgent)

sanitizedUserAgent = sanitizedUserAgent.replace(/(\r\n|\n|\r)/g, '');
var userAgentMatch;
// Iterate lists in order
for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
filesLoop: for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
var entries = files_1[_i];

@@ -51,2 +53,12 @@ for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {

if (sanitizedUserAgent.match(entry.regexp)) {
userAgentMatch = entry;
break filesLoop;
}
}
}
// Attempt to lookup referrers if possible
if (userAgentMatch.type === 'browsers' && referrer) {
for (var _b = 0, _c = user_agents_v2_1.default.referrers; _b < _c.length; _b++) {
var entry = _c[_b];
if (referrer.match(entry.regexp)) {
return entry;

@@ -56,6 +68,5 @@ }

}
// If no match is found, return undefined
return undefined;
return userAgentMatch;
}
var user_agents_v2_2 = require("./user-agents-v2");
Object.defineProperty(exports, "OPAWGFileType", { enumerable: true, get: function () { return user_agents_v2_2.OPAWGFileType; } });

@@ -25,1 +25,5 @@ "use strict";

});
test('identifies web apps by referrers', function () {
var entry = (0, _1.default)('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36', 'https://podcasts.apple.com/us/podcast/xya/id12341');
expect(entry.name).toBe('Apple Podcasts');
});
{
"name": "@alitu/user-agents-v2-api",
"version": "0.1.6",
"version": "0.2.1",
"description": "API for identifying User-Agent strings using OPAWG's user-agents-v2 lists.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc