Crate browserslist
source ·Expand description
browserslist-rs is a Rust-based implementation of Browserslist.
§Introduction
This library bundles Can I Use data, Electron versions list and Node.js releases list, so it won’t and doesn’t need to access any data files.
Except several non-widely/non-frequently used features, this library works as same as the JavaScript-based implementation Browserslist.
§Usage
It provides a simple API for querying which accepts a sequence of strings and options Opts
,
then returns the result.
use browserslist::{Distrib, Opts, resolve, Error};
let distribs = resolve(["ie <= 6"], &Opts::new()).unwrap();
assert_eq!(distribs[0].name(), "ie");
assert_eq!(distribs[0].version(), "6");
assert_eq!(distribs[1].name(), "ie");
assert_eq!(distribs[1].version(), "5.5");
assert_eq!(
resolve(["yuru 1.0"], &Opts::new()),
Err(Error::BrowserNotFound(String::from("yuru")))
);
The result isn’t a list of strings, instead, it’s a tuple struct called Distrib
.
If you need to retrieve something like JavaScript-based implementation of
Browserslist,
you can convert them to strings:
use browserslist::{Distrib, Opts, resolve, Error};
let distribs = resolve(["ie <= 6"], &Opts::new()).unwrap();
assert_eq!(
distribs.into_iter().map(|d| d.to_string()).collect::<Vec<_>>(),
vec![String::from("ie 6"), String::from("ie 5.5")]
);
§WebAssembly
This crate can be compiled as WebAssembly, without configuring any features manually.
Please note that browser and Deno can run WebAssembly,
but those environments aren’t Node.js,
so you will receive an error when querying current node
in those environments.
Macros§
Structs§
- Representation of browser name (or
node
) and its version. - Options for controlling the behavior of browserslist.
Enums§
- The errors may occur when querying with browserslist.
Functions§
- Load queries from configuration with environment information, then resolve those queries.
- Resolve browserslist queries.