browserslist-generator
Version:
A library that makes generating and validating Browserslists a breeze!
62 lines (58 loc) • 3.34 kB
text/typescript
type EcmaVersion = "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "es2023" | "es2024";
type CaniuseBrowser = "and_chr" | "and_ff" | "and_qq" | "and_uc" | "android" | "baidu" | "kaios" | "bb" | "chrome" | "edge" | "firefox" | "ie" | "ie_mob" | "ios_saf" | "op_mini" | "op_mob" | "opera" | "safari" | "samsung";
/**
* Normalizes the given Browserslist
*/
declare function normalizeBrowserslist(browserslist: string | string[]): string[];
interface EcmaFeatureFilteringOptions {
syntaxOnly: boolean;
featureFilter?(feature: string): boolean;
}
interface BrowsersWithSupportOptions {
features: string[];
}
/**
* Generates a Browserslist based on browser support for the given features
*/
declare function browsersWithSupportForFeatures(...features: string[]): string[];
declare function browsersWithSupportForFeatures(options: BrowsersWithSupportOptions): string[];
/**
* Returns true if the given Browserslist supports the given EcmaVersion
*/
declare function browserslistSupportsEcmaVersion(browserslist: string[], version: EcmaVersion, options?: Partial<EcmaFeatureFilteringOptions>): boolean;
declare function getFeaturesForEcmaVersion(version: EcmaVersion, options?: Partial<EcmaFeatureFilteringOptions>): string[];
/**
* Returns the appropriate Ecma version for the given Browserslist
*/
declare function getAppropriateEcmaVersionForBrowserslist(browserslist: string[], options?: Partial<EcmaFeatureFilteringOptions>): EcmaVersion;
/**
* Generates a Browserslist based on browser support for the given ECMA version
*/
declare function browsersWithSupportForEcmaVersion(version: EcmaVersion, options?: Partial<EcmaFeatureFilteringOptions>): string[];
/**
* Returns true if the given browserslist support all of the given features
*/
declare function browserslistSupportsFeatures(browserslist: string[], ...features: string[]): boolean;
/**
* Generates a Browserslist based on browsers that *doesn't* support the given features
*/
declare function browsersWithoutSupportForFeatures(...features: string[]): string[];
declare function browsersWithoutSupportForFeatures(options: BrowsersWithSupportOptions): string[];
/**
* Gets a Map between browser names and the first version of them that supported the given feature
*/
declare function getFirstVersionsWithFullSupport(feature: string): Map<CaniuseBrowser, string>;
/**
* Generates a browserslist from the provided useragent string
*/
declare function generateBrowserslistFromUseragent(useragent: string): string[];
/**
* Generates a browserslist from the provided useragent string and checks if it matches
* the given browserslist
*/
declare function matchBrowserslistOnUserAgent(useragent: string, browserslist: string[]): boolean;
/**
* Returns true if the given user agent supports the given features
*/
declare function userAgentSupportsFeatures(useragent: string, ...features: string[]): boolean;
export { browsersWithSupportForEcmaVersion, browsersWithSupportForFeatures, browsersWithoutSupportForFeatures, browserslistSupportsEcmaVersion, browserslistSupportsFeatures, generateBrowserslistFromUseragent, getAppropriateEcmaVersionForBrowserslist, getFeaturesForEcmaVersion, getFirstVersionsWithFullSupport, matchBrowserslistOnUserAgent, normalizeBrowserslist, userAgentSupportsFeatures };