Coder Social home page Coder Social logo

malcommac / uaparserswift Goto Github PK

View Code? Open in Web Editor NEW
39.0 6.0 9.0 523 KB

🗺 User-Agent Parser based upon ua-parser.js

License: MIT License

Swift 97.38% Ruby 2.62%
useragent useragentparser swift kitura vapor-swift browser-detection os-detection device-detection

uaparserswift's Introduction

UAParserSwift

User-Agent Parser based upon ua-parser.js

UAParserSwift is a Swift-based library to parse User Agent string; it's a port of ua-parser-js by Faisal Salman created to be mainly used in Swift Server Side applications (Kitura, Vapor etc.). You can however use it on client side, all Apple's platforms are supported (iOS, macOS, tvOS and watchOS).

This library aims to identify detailed type of web browser, layout engine, operating system, cpu architecture, and device type/model, entirely from user-agent string with a relatively small footprint.

❤️ Your Support

Hi fellow developer!
You know, maintaing and developing tools consumes resources and time. While I enjoy making them your support is foundamental to allow me continue its development.

If you are using SwiftLocation or any other of my creations please consider the following options:

How it works

Usage of UAParserSwift is pretty simple; just allocate an UAParser object along with the User-Agent string you want to parse.

let parser = UAParser(agent: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7")

// Then call properties you want to read.
// Parsed data are cached and evaluated lazily in order to
// get the best performances.

let identified_os = parser.os
let identified_device = parser.device
let identified_engine = parser.engine
let identified_os = parser.os
let identified_cpu = parser.cpu

Now you can call one of these properties to get parsed data (all properties are lazy created in order to keep parser lightweight):

  • .browser: return a Browser object with the browser's properties: name, version
  • .device: return a Device object with device's informations: vendor,type,model
  • .engine: return an Engine object with information about browser's engine: name,version
  • .os: return an OS object with the information about host operation system: name,version
  • .cpu: return a CPU object with the informations about host's device architecture: identifier

Name:

Amaya, Android Browser, Arora, Avant, Baidu, Blazer, Bolt, Bowser, Camino, Chimera,
Chrome [WebView], Chromium, Comodo Dragon, Conkeror, Dillo, Dolphin, Doris, Edge,
Epiphany, Fennec, Firebird, Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe,
IceCat, IceDragon, Iceweasel, IE[Mobile], Iron, Jasmine, K-Meleon, Konqueror, Kindle,
Links, Lunascape, Lynx, Maemo, Maxthon, Midori, Minimo, MIUI Browser, [Mobile] Safari,
Mosaic, Mozilla, Netfront, Netscape, NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet],
PhantomJS, Phoenix, Polaris, QQBrowser, RockMelt, Silk, Skyfire, SeaMonkey, Sleipnir,
SlimBrowser, Swiftfox, Tizen, UCBrowser, Vivaldi, w3m, WeChat, Yandex

Version: Determined dynamically

Type:

console, mobile, tablet, smarttv, wearable, embedded

Vendor:

Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, GeeksPhone,
Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola, Nexian,
Nintendo, Nokia, Nvidia, OnePlus, Ouya, Palm, Panasonic, Pebble, Polytron, RIM,
Samsung, Sharp, Siemens, Sony[Ericsson], Sprint, Xbox, Xiaomi, ZTE

Model: Determined dinamically

Engine:

Amaya, EdgeHTML, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto,
Tasman, Trident, w3m, WebKit

Engine Version: Determined dinamically

Name:

AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Contiki,
Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Gentoo, GNU, Haiku, Hurd, iOS,
Joli, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD,
Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS, Plan9, Playstation, QNX, RedHat,
RIM Tablet OS, RISC OS, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen,
Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk

Version: Determined dinamically

Identifier:

68k, amd64, arm[64], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]

Unit Tests are available under the Tests directory; actually they are the same tests available for ua-parser-js and all are passed successfully.

This library is written for Swift 4.x.

Swift Package Manager (Vapor or any server side framework)

Meow requires Swift 4.0 or greater to work. This is the official way to install packages for Swift Server Side. In your Package.swift, add the following to your dependencies array:

.package(url: "https://github.com/malcommac/UAParserSwift.git", from: "1.0.1")

To your target, add the "UAParserSwift" dependency.

.target(name: "Application", dependencies: ["UAParserSwift", ...])

CocoaPods

  1. Add the pod UAParserSwift to your Podfile.
pod 'UAParserSwift'

Run pod install from Terminal, then open your app's .xcworkspace file to launch Xcode.

  • If you need help or you'd like to ask a general question, open an issue.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Dual licensed under GPLv2 & MIT

Copyright © 2017 Daniele Margutti [email protected] Original ua-parser-js Copyright: Copyright © 2012-2016 Faisal Salman [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

This software is licensed under MIT License.

Consider ❤️ support the development of this library!

Follow me on:

uaparserswift's People

Contributors

ianpartridge avatar malcommac avatar omochi avatar tib avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

uaparserswift's Issues

Memory leak with regex

Hi,
image
I'm using the latest version (1.0.1) of your component with Vapor 3.
As you can see I have an issue with the 'matchingStrings'. For some reason I do not know the regex would take memory but would not release it later.

Introduced macOS Catalina (10.15) support

Hi,

first of all this library is amazing, congrats. 👍

I have a quick question about the upcoming version:
Is it possible to lower dependency so the lib could work with .macOS(.v10_15) as well?

Thanks.

Best,
Tib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.