npm detect-browser 4.0.0

latest releases: 5.3.0, 5.2.1, 5.2.0...
5 years ago

Summary

A TypeScript rewrite.

Breaking Changes

The only potential breaking change is that the bot boolean flag has been removed for all "non-bot" detection results, i.e. when we have detected a browser or the node environment.

In the majority of cases this should not affect usage as detecting for bots will still succeed due to the "falsiness" evaluation of the undefined value. The only corner case is if you are doing an equality comparison against false at any point.

For instance, the following would no longer work:

const { detect } = require('detect-browser');
const result = detect();

if (result && result.bot == false) {
  console.log('browser or node detected');
}

A simple change to the following, however, would resolve the issue:

const { detect } = require('detect-browser');
const result = detect();

if (result && !result.bot) {
  console.log('browser or node detected');
}

Extra Goodness

As this is a full TypeScript rewrite, the type definitions are now included in the package by default. So with an upgrade to detect-browser@4 you should probably also remove the @types/detect-browser package if you are working in a TypeScript environment.

Thanks

A big thanks goes to @sargant for being the catalyst for a source conversion to TypeScript with a couple of solid PRs, and also to @carusology for an excellent review and challenging some of the early design decisions that I had made with the initial conversion. What we have ended up with I think is a solid result.

Don't miss a new detect-browser release

NewReleases is sending notifications on new releases.