Socket
Socket
Sign inDemoInstall

wants-mobile

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

wants-mobile

Parse request headers to see if a mobile bundle is wanted


Version published
Maintainers
1
Weekly downloads
1
decreased by-66.67%

Weekly downloads

Readme

Source

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.

Keywords

FAQs

Last updated on 23 Jan 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc