From c6dbf0450566c40efc4a26f4f0717452b6ef95cd Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 10 Aug 2022 10:38:44 +0200 Subject: Initial commit --- node_modules/ua-parser/js/lib/device.js | 41 +++++++++++++++++ node_modules/ua-parser/js/lib/helpers.js | 6 +++ node_modules/ua-parser/js/lib/os.js | 78 ++++++++++++++++++++++++++++++++ node_modules/ua-parser/js/lib/results.js | 47 +++++++++++++++++++ node_modules/ua-parser/js/lib/ua.js | 53 ++++++++++++++++++++++ 5 files changed, 225 insertions(+) create mode 100644 node_modules/ua-parser/js/lib/device.js create mode 100644 node_modules/ua-parser/js/lib/helpers.js create mode 100644 node_modules/ua-parser/js/lib/os.js create mode 100644 node_modules/ua-parser/js/lib/results.js create mode 100644 node_modules/ua-parser/js/lib/ua.js (limited to 'node_modules/ua-parser/js/lib') diff --git a/node_modules/ua-parser/js/lib/device.js b/node_modules/ua-parser/js/lib/device.js new file mode 100644 index 0000000..374e971 --- /dev/null +++ b/node_modules/ua-parser/js/lib/device.js @@ -0,0 +1,41 @@ +exports.Device = Device +function Device(family) { + this.family = family || 'Other'; +} + +Device.prototype.toString = function() { + return this.family; +}; + + +exports.makeParser = function(regexes) { + var parsers = regexes.map(function (obj) { + var regexp = new RegExp(obj.regex), + deviceRep = obj.device_replacement; + + function parser(str) { + var m = str.match(regexp); + if (!m) { return null; } + + var family = deviceRep ? deviceRep.replace('$1', m[1]) : m[1]; + return new Device(family); + } + + return parser; + }); + + function parser(str, ua_family, os_family) { + var obj; + + if (typeof str === 'string') { + for (var i = 0, length = parsers.length; i < length; i++) { + obj = parsers[i](str, ua_family, os_family); + if (obj) { return obj; } + } + } + + return obj || new Device(); + } + + return parser; +}; diff --git a/node_modules/ua-parser/js/lib/helpers.js b/node_modules/ua-parser/js/lib/helpers.js new file mode 100644 index 0000000..19f305d --- /dev/null +++ b/node_modules/ua-parser/js/lib/helpers.js @@ -0,0 +1,6 @@ +var DIGITS = /^\d/; + +exports.startsWithDigit = startsWithDigit; +function startsWithDigit(str) { + return DIGITS.test(str); +} \ No newline at end of file diff --git a/node_modules/ua-parser/js/lib/os.js b/node_modules/ua-parser/js/lib/os.js new file mode 100644 index 0000000..f54b99a --- /dev/null +++ b/node_modules/ua-parser/js/lib/os.js @@ -0,0 +1,78 @@ +var startsWithDigit = require('./helpers').startsWithDigit; + +exports.OS = OS +function OS(family, major, minor, patch, patchMinor) { + this.family = family || 'Other'; + this.major = major || null; + this.minor = minor || null; + this.patch = patch || null; + this.patchMinor = patchMinor || null; +} + +OS.prototype.toVersionString = function() { + var output = ''; + if (this.major != null) { + output += this.major; + if (this.minor != null) { + output += '.' + this.minor; + if (this.patch != null) { + if (startsWithDigit(this.patch)) { output += '.'; } + output += this.patch; + if (this.patchMinor != null) { + if (startsWithDigit(this.patchMinor)) { output += '.'; } + output += this.patchMinor; + } + } + } + } + return output; +}; + +OS.prototype.toString = function() { + var suffix = this.toVersionString(); + if (suffix) { suffix = ' ' + suffix; } + return this.family + suffix; +}; + +function _makeParsers(obj) { + var regexp = new RegExp(obj.regex), + famRep = obj.os_replacement, + majorRep = obj.os_v1_replacement, + minorRep = obj.os_v2_replacement, + patchRep = obj.os_v3_replacement, + patchMinorRep = obj.os_v4_replacement; + + function parser(str) { + var m = str.match(regexp); + if (!m) { return null; } + + var family = famRep ? famRep.replace('$1', m[1]) : m[1], + major = majorRep || m[2], + minor = minorRep || m[3], + patch = patchRep || m[4], + patchMinor = patchMinorRep || m[5]; + + return new OS(family, major, minor, patch, patchMinor); + } + + return parser; +} + +exports.makeParser = function(regexes) { + var parsers = regexes.map(_makeParsers) + + function parser(str) { + var obj; + + if (typeof str === 'string') { + for (var i = 0, length = parsers.length; i < length; i++) { + obj = parsers[i](str); + if (obj) { return obj; } + } + } + + return obj || new OS(); + } + + return parser; +} \ No newline at end of file diff --git a/node_modules/ua-parser/js/lib/results.js b/node_modules/ua-parser/js/lib/results.js new file mode 100644 index 0000000..0b30cd0 --- /dev/null +++ b/node_modules/ua-parser/js/lib/results.js @@ -0,0 +1,47 @@ +var UNDEF = void 0; + +exports.BackwardsCompatResults = BackwardsCompatResults; +function BackwardsCompatResults(ua_str, ua, os, device) { + this.string = ua_str; + this.userAgent = this.ua = ua; + this.os = os; + this.device = device + + // Backwards compat + var major = ua.major, + minor = ua.minor, + patch = ua.patch; + + this.family = ua.family; + this.major = major === null ? UNDEF : parseInt(major); + this.minor = minor === null ? UNDEF : parseInt(minor); + this.patch = patch === null ? UNDEF : parseInt(patch); +} + +// Backwards compat +BackwardsCompatResults.prototype.toVersionString = function() { + var output = '', + ua = this.ua; + if (ua.major != null) { + output += ua.major; + if (ua.minor != null) { + output += '.' + ua.minor; + if (ua.patch != null) { + output += '.' + ua.patch; + } + } + } + return output; +}; + +// Backwards compat +BackwardsCompatResults.prototype.toString = function() { + var suffix = this.toVersionString(); + if (suffix) { suffix = ' ' + suffix; } + return this.ua.family + suffix; +}; + +// Backwards compat +BackwardsCompatResults.prototype.toFullString = function() { + return this.toString() + (this.os ? '/' + this.os : ''); +}; diff --git a/node_modules/ua-parser/js/lib/ua.js b/node_modules/ua-parser/js/lib/ua.js new file mode 100644 index 0000000..d8876d6 --- /dev/null +++ b/node_modules/ua-parser/js/lib/ua.js @@ -0,0 +1,53 @@ +var startsWithDigit = require('./helpers').startsWithDigit, + OS = require('./os').OS; + +exports.UA = UA +function UA(family, major, minor, patch) { + this.family = family || 'Other'; + this.major = major || null; + this.minor = minor || null; + this.patch = patch || null; +} + +require('util').inherits(UA, OS) + +function _makeParsers(obj) { + var regexp = new RegExp(obj.regex), + famRep = obj.family_replacement, + majorRep = obj.v1_replacement, + minorRep = obj.v2_replacement, + patchRep = obj.v3_replacement; + + function parser(str) { + var m = str.match(regexp); + if (!m) { return null; } + + var family = famRep ? famRep.replace('$1', m[1]) : m[1], + major = majorRep || m[2], + minor = minorRep || m[3], + patch = patchRep || m[4]; + + return new UA(family, major, minor, patch); + } + + return parser; +} + +exports.makeParser = function(regexes) { + var parsers = regexes.map(_makeParsers) + + function parser(str) { + var obj; + + if (typeof str === 'string') { + for (var i = 0, length = parsers.length; i < length; i++) { + obj = parsers[i](str); + if (obj) { return obj; } + } + } + + return obj || new UA(); + } + + return parser; +} \ No newline at end of file -- cgit