
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
trie-uaparser
Advanced tools
As of time of writing (3rd june 2018), the fastest user agent parser.
$ node benchmark/benchmark-parse.js
trie-uaparser v1.0.5 x 106,078 ops/sec ±0.82% (92 runs sampled)
useragent v2.3.0 x 9,442 ops/sec ±1.10% (88 runs sampled)
useragent_parser v1.0.0 x 59,402 ops/sec ±0.98% (91 runs sampled)
useragent-parser v0.1.1 x 21,017 ops/sec ±1.39% (87 runs sampled)
ua-parser v0.3.5 x 41,224 ops/sec ±1.33% (89 runs sampled)
Fastest is trie-uaparser v1.0.5
const {parse} = require("trie-uaparser");
const ua = "Mozilla/5.0 (Linux; U; Android 4.1.2; fr-fr; G740-L00 Build/HuaweiG740-L00) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";
expect(parse(ua)).to.equal("Android Browser");
const match = parse(ua, {
match: true
});
expect(match).not.to.equal(false);
expect(match.family).to.equal("Android Browser");
expect(match.version).to.equal("4.0");
expect(match.os).not.to.equal(null);
expect(typeof match.os).to.equal("object");
expect(match.os.family).to.equal("Android");
expect(match.os.version).to.equal("4.1.2");
Most of the user agents parser use multiple regular expressions, each of them associated to a particular software/os.
This library instead, split the user agent into tokens and determines the software/os using a trie data structure.
It leads to:
Search using trie data structure will always be faster than looping through regexes execution. And if you have lots of data to analyse, speed is not only a nice thing to have.
Adding a new pattern does not conflict with existing patterns.
In regexes based parsers, to detect Edge in "Mozilla/5.0 (Windows NT 10.0; Win64; x64; ServiceUI 11) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299", /edge/ has to be tested before /chrome/ to detect Safari without conflicting with Edge, /safari/ has to be between /chrome/ and /edge/
The more patterns you add, the harder it is to make it play well with existing patterns.
More over, adding a new pattern has a small impact on speed because it is similar to add an entry in a hashmap which is not the case for regexes based parsers.
FAQs
Yet another user agent parser
The npm package trie-uaparser receives a total of 0 weekly downloads. As such, trie-uaparser popularity was classified as not popular.
We found that trie-uaparser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.