zss-engine
Version:
Zero-runtime StyleSheet Engine
28 lines (27 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.camelToKebabCase = exports.applyCssValue = exports.isTestingDevelopment = exports.isDevelopment = exports.isServer = void 0;
const isWindowDefined = typeof window !== 'undefined';
const isDocumentDefined = typeof document !== 'undefined';
exports.isServer = !isWindowDefined || !isDocumentDefined;
exports.isDevelopment = process.env.NODE_ENV === 'development';
exports.isTestingDevelopment = process.env.NODE_ENV === 'test' || exports.isDevelopment;
const exception = ['line-height', 'font-weight', 'opacity', 'scale', 'z-index', 'column-count', 'order', 'orphans', 'widows'];
const applyCssValue = (value, cssProp) => {
if (typeof value === 'number') {
return exception.includes(cssProp) ? value.toString() : value + 'px';
}
return value;
};
exports.applyCssValue = applyCssValue;
const camelToKebabCase = (property) => {
if (/^(ms|Moz|Webkit)/.test(property)) {
property = '-' + property;
}
return (property
.replace(/([A-Z]+)([0-9]+)/g, '$1$2')
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
.toLowerCase());
};
exports.camelToKebabCase = camelToKebabCase;