Skip to main content

browserslist_data/
baseline.rs

1//! Baseline browser data, generated from the [`baseline-browser-mapping`]
2//! npm package's Baseline support timeline.
3//!
4//! [`baseline-browser-mapping`]: https://www.npmjs.com/package/baseline-browser-mapping
5
6use crate::{decode_browser_name, utils::PooledStr};
7
8include!("generated/baseline.rs");
9
10/// caniuse names of the seven core Baseline browsers; the remaining browsers
11/// in the dataset are downstream browsers sharing a core browser's engine.
12static CORE_BROWSERS: &[&str] = &[
13    "and_chr", "and_ff", "chrome", "edge", "firefox", "ios_saf", "safari",
14];
15
16pub fn is_core_browser(name: &str) -> bool {
17    CORE_BROWSERS.contains(&name)
18}
19
20/// All browsers tracked by the Baseline dataset, by caniuse name.
21pub fn browsers() -> impl Iterator<Item = &'static str> {
22    BASELINE_BROWSERS.iter().map(|&id| decode_browser_name(id))
23}
24
25/// Minimum compatible versions (by caniuse browser name) for the Baseline
26/// feature set as of `cutoff_date`, a baseline-low threshold encoded as
27/// decimal `yyyymmdd` (the query date minus 30 months for widely-available
28/// queries).
29///
30/// Returns `None` if the date predates the first Baseline feature; every
31/// version of every browser is considered compatible in that case.
32pub fn min_versions_on(
33    cutoff_date: u32,
34) -> Option<impl Iterator<Item = (&'static str, &'static str)>> {
35    let index = BASELINE_TIMELINE.partition_point(|(date, ..)| *date <= cutoff_date);
36    index.checked_sub(1).map(|index| {
37        let (_, start, end) = BASELINE_TIMELINE[index];
38        BASELINE_VERSIONS[usize::from(start)..usize::from(end)]
39            .iter()
40            .map(|(id, version)| (decode_browser_name(*id), version.as_str()))
41    })
42}