Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danhper/elixir-browser
Browser detection for Elixir
https://github.com/danhper/elixir-browser
Last synced: 6 days ago
JSON representation
Browser detection for Elixir
- Host: GitHub
- URL: https://github.com/danhper/elixir-browser
- Owner: danhper
- License: mit
- Created: 2015-10-31T04:42:24.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-27T11:05:28.000Z (5 months ago)
- Last Synced: 2024-11-30T02:07:44.270Z (13 days ago)
- Language: Elixir
- Homepage: https://hex.pm/packages/browser
- Size: 114 KB
- Stars: 100
- Watchers: 2
- Forks: 26
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Browser detection for Elixir. (Miscellaneous)
README
# elixir-browser
![ci](https://github.com/danhper/elixir-browser/actions/workflows/ci.yml/badge.svg)
Browser detection for Elixir.
This is a port from the [Ruby browser library](https://github.com/fnando/browser).All the detection features have been ported, but not the meta and the language ones.
## Installation
Add `browser` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:browser, "~> 0.5.4"}]
end
```## Usage
```elixir
ua = "some string"
Browser.name(ua) # readable browser name
Browser.version(ua) # major version number
Browser.full_version(ua)
Browser.full_browser_name(ua) # Chrome 5.0.375.99
Browser.full_display(ua) # example: Chrome 5.0.375.99 on MacOS 10.6.4 Snow Leopard
Browser.safari?(ua)
Browser.opera?(ua)
Browser.chrome?(ua)
Browser.chrome_os?(ua)
Browser.mobile?(ua)
Browser.tablet?(ua)
Browser.console?(ua)
Browser.firefox?(ua)
Browser.ie?(ua)
Browser.ie?(ua, 6) # detect specific IE version
Browser.edge?(ua) # Newest MS browser
Browser.modern?(ua) # Webkit, Firefox 17+, IE 9+ and Opera 12+
Browser.platform(ua) # return :ios, :android, :mac, :windows, :linux or :other
Browser.full_platform_name(ua) # example: MacOS 10.6.4 Snow Leopard
Browser.device_type(ua) # return :mobile, :tablet, :desktop, :console, :unknown
Browser.ios?(ua) # detect iOS
Browser.ios?(ua, 9) # detect specific iOS version
Browser.mac?(ua)
Browser.mac_version(ua) # display version of Mac OSX. i.e. High Sierra
Browser.windows?(ua)
Browser.windows_x64?(ua)
Browser.windows_version_name # display version of Windows. i.e. Windows 10
Browser.linux?(ua)
Browser.blackberry?(ua)
Browser.blackberry?(ua, 10) # detect specific BlackBerry version
Browser.bot?(ua)
Browser.search_engine?(ua)
Browser.phantom_js?(ua)
Browser.quicktime?(ua)
Browser.core_media?(ua)
Browser.silk?(ua)
Browser.android?(ua)
Browser.android?(ua, 4.2) # detect Android Jelly Bean 4.2
Browser.known?(ua) # has the browser been successfully detected?
```See the [original Ruby library](https://github.com/fnando/browser) for more information.
### Elixir addition
You can also pass `Plug.Conn` instead of a string, the `user-agent` header will
be extracted and used.```elixir
Browser.bot?(conn)
```### Configuration
You can specify custom bots.txt file in your project's config.
```elixir
config :browser,
bots_file: Path.join(File.cwd!, "bots.txt") # bots.txt in project's root
```Please note that option set as mobule attribute during compile time, so make sure you recompiled elixir-browser after changing this option or bots file itself.