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

@kmdavis/baskerville

v0.2.6

Published

Sir Arthur Conan Doyle's The Hound of the User Agent

Downloads

4

Readme

Baskerville

Sir Arthur Conan Doyle's The Hound of the User Agent

NPM Version Build Status Downloads Stats

Baskerville will sniff a user agent string and provide some analysis of what it might mean.

Installation

npm install @kmdavis/baskerville

Usage

Baskerville has 2 main methods: tokenize, and process.

Tokenize will return an array of tokens, for example:

import Baskerville from "@kmdavis/baskerville";
Baskerville.tokenize("Mozilla/5.0 (compatible; Konqueror/4.4; Linux 2.6.32-22-generic; X11; en_US) KHTML/4.4.3 (like Gecko) Kubuntu");

will return the following tokens:

[
    {
        name: "compatible",
    },
    {
        name: "en_US",
    },
    {
        name: "KHTML",
        version: "4.4.3",
        like: "Gecko",
    },
    {
        name: "Konqueror",
        version: "4.4",
    },
    {
        name: "Kubuntu",
    },
    {
        name: "Linux",
        version: "2.6.32-22-generic",
    },
    {
        name: "Mozilla",
        version: "5.0",
    },
    {
        name: "X",
        version: "11",
    },
]

Process takes that array of tokens and does a little... processing... on it.

Baskerville.process("Mozilla/5.0 (compatible; Konqueror/4.4; Linux 2.6.32-22-generic; X11; en_US) KHTML/4.4.3 (like Gecko) Kubuntu");

will return:

[
    {
        name: "compatible",
    },
    {
        name: "en_US",
    },
    {
        type: "browser",
        name: "KHTML",
        version: "4.4.3",
        like: "Gecko",
    },
    {
        type: "browser",
        name: "Konqueror",
        version: "4.4",
    },
    {
        type: "os",
        name: "Kubuntu",
    },
    {
        type: "os",
        name: "Linux",
        version: "2.6.32-22-generic",
    },
    {
        type: "browser",
        name: "Mozilla",
        version: "5.0",
    },
    {
        name: "X",
        version: "11",
    },
]

The built-in processing is rather minimal: it will normalize version strings (replacing underscores with dots), identify browsers and operating systems, and the "security token" (N, U, or I). For additional processing, we expose a registerProcessor method that allows you to create a processor plugin. For example, you could use this to sort browsers or operating systems into buckets, like mobile vs desktop, linux-based, etc. You could also use it to convert our string versions into Version objects:

Baskerville.registerProcessor(function wrapVersions (token) {
    if (token.version) {
        token.version = new Version(token.version);
    }
});

Or you could parse the locale token ("en_US" in the example above):

var carmen = require("@kmdavis/carmen"); // https://github.com/kmdavis/carmen
Baskerville.registerProcessor(function identifyLocale (token) {
    var locale = carmen.parse(token.name); // will return undefined if it can't parse
    if (locale) {
        token.type = "locale";
        token.details = locale;
        return true; // We assume full ownership and responsibility for this token.
    }
    return false; // Let the other children play
});

In the example above, if a processor returns true, no further processing will be performed on that token. Also, don't be scared to modify the token, you're not modifying the original token, but rather a copy. The token or array of tokens passed into baskerville.process is not modified in any way.

Development setup

npm install
npm test

Release History

  • 0.1.0
    • Initial public release
  • 0.2.0
    • Rewrite using modern javascript
  • 0.2.1
    • Removed unnecessary (boilerplate) dependencies
    • Added a test using large numbers of randomly generated useragent strings
  • 0.2.2
    • Updating README
  • 0.2.3
    • Removing an unused rc file
  • 0.2.4
    • Fixing a licensing issue
  • 0.2.5
    • Switching to webpack
  • 0.2.6
    • Updating readme

Meta

Kevan Davis [email protected]

Distributed under the MIT license.

https://github.com/kmdavis/baskerville

Contributing

  1. Fork it (https://github.com/kmdavis/baskerville/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request