bowser-cache
v2.0.0
Published
Browser detection for node, with caching
Downloads
805
Readme
bowser-cache
Cache Bowser lookups in LRU
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 }