npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

seeagent

v1.0.3

Published

useragent,mobile,browser

Downloads

16

Readme

seeagent NPM version Build Status Dependency Status Coverage percentage

useragent,mobile,browser

Install

$ npm install --save seeagent
$ yarn add seeagent

Features

  • support Wechat, Meituan, Dianping, Maoyan, Alipay, Taobao, Weibo etc.
  • support device type detection, includes tv, desktop, phone, tablet
  • custom parser or custom rules
  • LRU cache
  • all info of useragent

Usage

const seeagent = require('seeagent');
// es5 version
// var seeagent = require('seeagent/es5');

// config agent
seeagent.config({
  size: 5000, // cache limit, default is 1000
  rule: {
    app: [],
    browser: [],
    os: [],
    device: []
  }
})

const info = seeagent('Mozilla/5.0 (iPhone; CPU iPhone OS 9_2_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13D15 MicroMessenger/6.3.9 NetType/WIFI Language/zh_CN');

console.log(info);
// {
//   "Mozilla": {
//     "name": "Mozilla",
//     "detail": "iPhone; CPU iPhone OS 9_2_1 like Mac OS X",
//     "unit": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_2_1 like Mac OS X)",
//     "version": "5.0"
//   },
//   "AppleWebKit": {
//     "name": "AppleWebKit",
//     "detail": "KHTML, like Gecko",
//     "unit": "AppleWebKit/601.1.46 (KHTML, like Gecko)",
//     "version": "601.1.46"
//   },
//   "Mobile": {
//     "name": "Mobile",
//     "detail": "",
//     "unit": "Mobile/13D15",
//     "version": "13D15"
//   },
//   "MicroMessenger": {
//     "name": "Wechat",
//     "detail": "",
//     "unit": "MicroMessenger/6.3.9",
//     "version": "6.3.9"
//   },
//   "NetType": {
//     "name": "NetType",
//     "detail": "",
//     "unit": "NetType/WIFI",
//     "version": "WIFI"
//   },
//   "Language": {
//     "name": "Language",
//     "detail": "",
//     "unit": "Language/zh_CN",
//     "version": "zh_CN"
//   },
//   "app": {
//     "name": "Wechat",
//     "detail": "",
//     "unit": "MicroMessenger/6.3.9",
//     "version": "6.3.9"
//   },
//   "os": {
//     "name": "iOS",
//     "version": "9.2.1"
//   },
//   "device": {
//     "name": "iPhone",
//     "version": "",
//     "type": "phone"
//   }
// }

more examples see test/useragents

Result Explanation

First, seeagent will parse the User-Agent into object by the rule of https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent. The property of object is the product of a User-Agent unit. After get the parsed object, seeagent use the property rules to find the app and browser info and use the regular expression find the os and device info.

Performance

1000 useragent samples, cache 5000 items

10 times, useragent consume: 5ms
10 times, ua-parser-js consume: 5ms
10 times, seeagent consume: 3ms

100 times, useragent consume: 11ms
100 times, ua-parser-js consume: 6ms
100 times, seeagent consume: 5ms

10000 times, useragent consume: 71ms
10000 times, ua-parser-js consume: 338ms
10000 times, seeagent consume: 35ms

100000 times, useragent consume: 83ms
100000 times, ua-parser-js consume: 2983ms
100000 times, seeagent consume: 14ms

API

seeagent.config(options?: Options) config the cache size or custom rules

// [name, props]
type KeyRule = [string, string[]];
// [name, rules, meta?]
type RegExpRule = [string, Array<string | RegExp>, Object];

interface Options {
  size?: number, // the cache max size, default is 1000
  rule?: {app?: KeyRule[], os?: RegExpRule[], device?: RegExpRule[]}
}

function seeagent(ua: string): Object

Development

$ git clone [email protected]:wenshin/seeagent.git
$ yarn install
$ npm test

ChangeLog

2017-01-11 1.0.3

* fix lodash and handlebars security alerts

2017-01-11 1.0.2

* performance enhancement

2017-01-02 1.0.1

* remove ua-device-type, it not have enough information for all types
* support windows productions

2017-01-02 1.0.0

License

© yuanwen