Skip to content
This repository was archived by the owner on May 18, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions src/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,32 @@ import camelCase from 'lodash/camelCase';
* @returns {boolean}
*/
const isSupported = (property, value) => {
// Try the native standard method first
if ('CSS' in window && 'supports' in window.CSS) {
return window.CSS.supports(property, value);
}
// Handle when running in NodeJS and not a browser
if (typeof window !== "undefined" && typeof document !== "undefined") {
// Try the native standard method first
if ('CSS' in window && 'supports' in window.CSS) {
return window.CSS.supports(property, value);
}

// Check Opera's native method
if ('supportsCSS' in window) {
return window.supportsCSS(property, value);
}
// Check Opera's native method
if ('supportsCSS' in window) {
return window.supportsCSS(property, value);
}

// Convert to camel-case for DOM interactions
const camelCaseProperty = camelCase(property);
// Convert to camel-case for DOM interactions
const camelCaseProperty = camelCase(property);

// Check if the property is supported
const element = document.createElement('div');
const support = (camelCaseProperty in element.style);
// Check if the property is supported
const element = document.createElement('div');
const support = (camelCaseProperty in element.style);

// Assign the property and value to invoke the CSS interpreter
element.style.cssText = `${property}:${value}`;
// Assign the property and value to invoke the CSS interpreter
element.style.cssText = `${property}:${value}`;

// Ensure both the property and value are
// supported and return
return support && (element.style[camelCaseProperty] !== '');
// Ensure both the property and value are
// supported and return
return support && (element.style[camelCaseProperty] !== '');
}
};

export default isSupported;