wants-mobile
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

wants-mobile

Parse request headers to see if a mobile-specific bundle is wanted.

Supports both Node.js and Web Workers.

Usage

import wantsMobile from 'wants-mobile'

The wantsMobile function takes a headers object and returns true when a mobile-specific bundle should be served, otherwise false.

The headers object is expected to be:

  • a plain object with lowercase keys, or
  • an object whose get(key) method supports lowercase keys

It first checks the Sec-CH-Mobile header (part of the WICG "Client Hints" proposal). If defined, wantsMobile returns a boolean (true when ?1, else false).

If that header is undefined, it then parses the User-Agent header using a small set of regular expressions, which can be found here.

Package Sidebar

Install

npm i wants-mobile

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

7.58 kB

Total Files

10

Last publish

Collaborators

  • aleclarson