zss-engine
Version:
Zero-runtime StyleSheet Engine
57 lines (56 loc) • 1.52 kB
JavaScript
const isWindowDefined = typeof window !== 'undefined';
const isDocumentDefined = typeof document !== 'undefined';
export const isServer = !isWindowDefined || !isDocumentDefined;
export const isDevelopment = process.env.NODE_ENV === 'development';
export const isTestingDevelopment = process.env.NODE_ENV === 'test' || isDevelopment;
const exception = [
'animation-iteration-count',
'aspect-ratio',
'column-count',
'columns',
'fill-opacity',
'flex',
'flex-grow',
'flex-shrink',
'flood-opacity',
'font-size-adjust',
'font-weight',
'grid-column',
'grid-column-end',
'grid-column-start',
'grid-row',
'grid-row-end',
'grid-row-start',
'hyphenate-limit-chars',
'initial-letter',
'line-height',
'math-depth',
'opacity',
'order',
'orphans',
'scale',
'shape-image-threshold',
'stop-opacity',
'stroke-miterlimit',
'stroke-opacity',
'tab-size',
'widows',
'z-index',
'zoom',
];
export const applyCssValue = (value, cssProp) => {
if (typeof value === 'number') {
return exception.includes(cssProp) ? value.toString() : value + 'px';
}
return value;
};
export 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());
};