uaparser-rs

Crates.iouaparser-rs
lib.rsuaparser-rs
version0.1.0
sourcesrc
created_at2024-04-17 17:19:52.170128
updated_at2024-04-17 17:19:52.170128
descriptionA simple user agent parser for rust
homepagehttps://github.com/OssamaZ/uaparser-rs
repositoryhttps://github.com/OssamaZ/uaparser-rs
max_upload_size
id1211569
size3,853,537
Ossama Zaid (OssamaZ)

documentation

README

User Agent Parser

Simple implementation of the user agent parser based on the ua-parser/specification.

Usage

use uaparser_rs::UAParser;

let uap = UAParser::from_yaml("./regexes.yaml").unwrap();
let ua_str = "Mozilla/5.0 (Linux; Android 4.0.1; Galaxy Nexus Build/ITL41F) AppleWebKit 537.31 (KHTML, like Gecko) Chrome/26.0.1410.58 Mobile Safari/537.31";

let client = uap.parse(ua_str);

/*
  client {
    user_agent: {
      family,
      major,
      minor,
      patch,
      patch_minor,
    },
    os: {
      family,
      major,
      minor,
      patch,
      patch_minor,
    },
    device: {
      family,
      brand,
      model,
    }
  }
*/

// User Agent
assert_eq!(client.user_agent.family, "Chrome Mobile");
assert_eq!(client.user_agent.major, Some(String::from("26")));
assert_eq!(client.user_agent.minor, Some(String::from("0")));
assert_eq!(client.user_agent.patch, Some(String::from("1410")));
assert_eq!(client.user_agent.patch_minor, Some(String::from("58")));

// Os
assert_eq!(client.os.family, "Android");
assert_eq!(client.os.major, Some(String::from("4")));
assert_eq!(client.os.minor, Some(String::from("0")));
assert_eq!(client.os.patch, Some(String::from("1")));

// Device
assert_eq!(client.device.family, "Samsung Galaxy Nexus");
assert_eq!(client.device.brand, Some(String::from("Samsung")));
assert_eq!(client.device.model, Some(String::from("Galaxy Nexus")));
Commit count: 16

cargo fmt