bowser-js / bowser

a browser detector
Other
5.48k stars 486 forks source link

[feature]: add `isEngine()` into `is()` for simplicity #480

Open ivodolenc opened 3 years ago

ivodolenc commented 3 years ago

Hi and thanks for your awesome work 👋

I want to mention, this isn't a issue but a possible feature-request. And I'm sorry if I misunderstood or missed something, I don't think this is documented at the moment.

Current behavior

.is(anything, includingAlias) checks only for isBrowser, isOS and isPlatform but not for isEngine.

const browser = Bowser.getParser(window.navigator.userAgent)

// Is Platform
browser.is('desktop') // true

// Is OS
browser.is('macos') // true

// Is Browser
browser.is('chrome') // true

// ---

// Is Engine
browser.is('blink') // false -> doesn't work

// but
browser.isEngine('blink') // true -> works as expected

Feature request

It would be great if we could use .is('isEngine') to check if the engine is called anything, just like we use it for platform, os or browser.

This makes it easier to use and removes possible doubts as to whether it's an bug or not.

// Currently this doesn't work
browser.is('blink') 

Additional info

I did a quick test and add || this.isEngine(anything) to this line. It turned out to work as expected.

  is(anything, includingAlias = false) {
    return this.isBrowser(anything, includingAlias) || this.isOS(anything)
+      || this.isPlatform(anything) || this.isEngine(anything);
  }

Now we can check for Engine like this:

// Is Engine
browser.is('blink') // true -> works as expected

// or
browser.isEngine('blink') // true -> works as expected