bowser-cache

2.0.0 • Public • Published

bowser-cache

Cache Bowser lookups in LRU

NPM Version Linux build Status Windows build Status Coverage Status

Dependency Status Dev Dependency Status Greenkeeper badge

Usage

This module uses bowser to parse user agent (ua) strings, and puts the result into an LRU cache. This cache holds up to 100 cache entries.

API

The default export caches the raw form returned by bowser.

import bowserCache from 'bowser-cache';
 
const parsedInfo = bowserCache(ua);
 
// Do something with `parsedInfo`

You can also provide a transformation function to massage the data before it's put into the cache.

import { withTransformer } from 'bowser-cache';
 
const bowserCache = withTransformer(parsedData => ({ isMobile: parsedData.mobile }));
 
const parsedInfo = bowserCache(ua);
 
// `parsedInfo` is now just { isMobile: true|false }

Additionally, you can specify custom cache size (default is 100).

import { withCacheCapacity } from 'bowser-cache';
 
// Cache will have a maximum of 10 entries
const bowserCache = withCacheCapacity(10);
 
const parsedInfo = bowserCache(ua);
 
// Do something with `parsedInfo`
import { withTransformerAndCacheCapacity } from 'bowser-cache';
 
// Cache will have a maximum of 10 entries
const bowserCache = withTransformerAndCacheCapacity(parsedData => ({ isMobile: parsedData.mobile }), 10);
 
const parsedInfo = bowserCache(ua);
 
// `parsedInfo` is now just { isMobile: true|false }

Readme

Keywords

none

Package Sidebar

Install

npm i bowser-cache

Weekly Downloads

367

Version

2.0.0

License

MIT

Unpacked Size

5.94 kB

Total Files

4

Last publish

Collaborators

  • simenb