Skip to content

Commit

Permalink
BREAKING CHANGE - Add new property to browser: type
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalman committed Jun 2, 2024
1 parent 1a22c69 commit 39590f1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 14 deletions.
11 changes: 10 additions & 1 deletion src/enums/ua-parser-enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ const Browser = Object.freeze({
// TODO : test!
});

const BrowserType = Object.freeze({
BOT: 'bot',
CLI: 'cli',
EMAIL: 'email',
INAPP: 'inapp',
MODULE: 'module'
});

const CPU = Object.freeze({
ARM : 'arm',
ARM_64: 'arm64',
Expand Down Expand Up @@ -341,7 +349,8 @@ const OS = Object.freeze({
});

module.exports = {
Browser,
Browser,
BrowserType,
CPU,
Device,
Vendor,
Expand Down
14 changes: 7 additions & 7 deletions src/extensions/ua-parser-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ const VERSION = 'version';
const MOBILE = 'mobile';
const TABLET = 'tablet';

const Apps = Object.freeze({
browser : [
[/chatlyio\/([\d\.]+)/i], [VERSION, 'Slack', [TYPE, 'app']]
]
});

const Bots = Object.freeze({
browser : [
// Googlebot / BingBot / MSNBot / FacebookBot
Expand Down Expand Up @@ -124,6 +118,12 @@ const Emails = Object.freeze({
]
});

const InApps = Object.freeze({
browser : [
[/chatlyio\/([\d\.]+)/i], [VERSION, 'Slack', [TYPE, 'inapp']]
]
});

const MediaPlayers = Object.freeze({
browser : [[

Expand Down Expand Up @@ -238,11 +238,11 @@ const Modules = Object.freeze({
});

module.exports = {
Apps,
Bots,
CLIs,
ExtraDevices,
Emails,
InApps,
MediaPlayers,
Modules
};
1 change: 1 addition & 0 deletions src/main/ua-parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ declare namespace UAParser {
NAME: 'name';
VERSION: 'version';
MAJOR: 'major';
TYPE: 'type';
};
static readonly CPU: {
ARCHITECTURE: 'architecture';
Expand Down
4 changes: 2 additions & 2 deletions src/main/ua-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@
var defaultProps = (function () {
var props = { init : {}, isIgnore : {}, isIgnoreRgx : {}, toString : {}};
setProps.call(props.init, [
[UA_BROWSER, [NAME, VERSION, MAJOR]],
[UA_BROWSER, [NAME, VERSION, MAJOR, TYPE]],
[UA_CPU, [ARCHITECTURE]],
[UA_DEVICE, [TYPE, MODEL, VENDOR]],
[UA_ENGINE, [NAME, VERSION]],
Expand Down Expand Up @@ -1225,7 +1225,7 @@
}

UAParser.VERSION = LIBVERSION;
UAParser.BROWSER = enumerize([NAME, VERSION, MAJOR]);
UAParser.BROWSER = enumerize([NAME, VERSION, MAJOR, TYPE]);
UAParser.CPU = enumerize([ARCHITECTURE]);
UAParser.DEVICE = enumerize([MODEL, VENDOR, TYPE, CONSOLE, MOBILE, SMARTTV, TABLET, WEARABLE, EMBEDDED]);
UAParser.ENGINE = UAParser.OS = enumerize([NAME, VERSION]);
Expand Down
1 change: 1 addition & 0 deletions test/dts-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ expectType<IBrowser>(browser);
expectType<string | undefined>(browser.name);
expectType<string | undefined>(browser.version);
expectType<string | undefined>(browser.major);
expectType<string | undefined>(browser.type);
expectType<boolean>(browser.is(''));
expectType<string>(browser.toString());
expectType<IBrowser | PromiseLike<IBrowser>>(browser.withClientHints());
Expand Down
3 changes: 1 addition & 2 deletions test/mocha-test-es6.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ describe('Returns', () => {
assert.deepEqual(new UAParser('').getResult(),
{
ua : '',
//ua_ch : { architecture: undefined, bitness: undefined, brands: undefined, fullVersionList: undefined, mobile: false, model: undefined, platform: undefined, platformVersion: undefined },
browser: { name: undefined, version: undefined, major: undefined },
browser: { name: undefined, version: undefined, major: undefined, type: undefined },
cpu: { architecture: undefined },
device: { vendor: undefined, model: undefined, type: undefined },
engine: { name: undefined, version: undefined},
Expand Down
2 changes: 1 addition & 1 deletion test/mocha-test-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Bots', () => {
assert.deepEqual(botParser.setUA(gptBot).getBrowser(), {name: "GPTBot", version: "1.0", major: "1", type: "bot"});
assert.deepEqual(botParser.setUA(msnBot).getBrowser(), {name: "msnbot-media", version: "1.1", major: "1", type: "bot"});
assert.deepEqual(botParser.setUA(bingPreview).getBrowser(), {name: "BingPreview", version: "1.0b", major: "1", type: "bot"});
assert.deepEqual(botParser.setUA(opera).getBrowser(), {name: "Opera", version: "8.5", major: "8"});
assert.deepEqual(botParser.setUA(opera).getBrowser(), {name: "Opera", version: "8.5", major: "8", type: undefined});

// try merging Bots & CLIs
const botsAndCLIs = { browser : [...Bots.browser, ...CLIs.browser]};
Expand Down
3 changes: 2 additions & 1 deletion test/mocha-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var cpus = require('./specs/cpu-all.json');
var devices = require('./specs/device-all.json');
var engines = require('./specs/engine-all.json');
var os = require('./specs/os-all.json');

var parser = new UAParser();
var methods = [
{
Expand Down Expand Up @@ -82,7 +83,7 @@ describe('Returns', function () {
assert.deepEqual(new UAParser('').getResult(),
{
ua : '',
browser: { name: undefined, version: undefined, major: undefined },
browser: { name: undefined, version: undefined, major: undefined, type: undefined },
cpu: { architecture: undefined },
device: { vendor: undefined, model: undefined, type: undefined },
engine: { name: undefined, version: undefined},
Expand Down

0 comments on commit 39590f1

Please sign in to comment.