2.0.0 • Published 5 years ago

bowser-cache v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

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 }
2.0.0

5 years ago

1.1.0

8 years ago

1.0.0

8 years ago