Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const filterItem = (item: Declaration | DeclarationGroup, browsers: string[]): string[] => {
if ('prop' in item) {
const supportsProperty = getSupported({ property: item.prop }, browsers);
const supportsValue = supportsProperty && getSupported({ property: item.prop, value: item.value }, supportsProperty);
return supportsValue || [];
}
switch (item.type) {
case 'and':
return intersection(...item.nodes.map((child) => {
return filterItem(child, browsers);
}));
case 'or':
return union(...item.nodes.map((child) => {
return filterItem(child, browsers);
}));
case 'not':
return difference(browsers, filterItem(item.nodes[0], browsers));
const filterItem = (item: Declaration | DeclarationGroup, browsers: string[]): string[] => {
if ('prop' in item) {
const supportsProperty = getSupported({ property: item.prop }, browsers);
const supportsValue = supportsProperty && getSupported({ property: item.prop, value: item.value }, supportsProperty);
return supportsValue || [];
}
switch (item.type) {
case 'and':
return intersection(...item.nodes.map((child) => {
return filterItem(child, browsers);
}));
case 'or':
return union(...item.nodes.map((child) => {
return filterItem(child, browsers);
}));
case 'not':
return difference(browsers, filterItem(item.nodes[0], browsers));
default:
export const filterSupports = (params: string, browsers: string[]): string[] | null => {
const hasAtSupports = getSupported({ rule: 'supports'}, browsers);
if (!hasAtSupports) {
return null;
}
const root = parseSupports(params);
if (!root) {
return null;
}
try {
const supported = filterItem(root, hasAtSupports);
return supported.length ? supported : null;
} catch (e) {