An object of CSS properties that don't accept values with units
92
Quality
Pending
Does it follow best practices?
Impact
92%
0.92xAverage score across 7 eval scenarios
Build a style value processor that efficiently handles CSS property values for a CSS-in-JS library. The processor should convert style objects with numeric values into properly formatted CSS strings, determining when to add units based on CSS property conventions.
Your processor should handle style objects where:
--) are never modifiedThe implementation should be optimized for performance, as it may process thousands of style objects during application rendering.
@generates
/**
* Processes a single style value, adding 'px' unit where appropriate.
*
* @param {string} property - The CSS property name
* @param {string|number} value - The style value
* @returns {string|number} The processed value
*/
function processValue(property, value) {
// IMPLEMENTATION HERE
}
/**
* Processes an entire style object, converting all numeric values appropriately.
*
* @param {Object} styles - An object with CSS property names as keys
* @returns {Object} A new object with processed string values
*/
function processStyles(styles) {
// IMPLEMENTATION HERE
}
module.exports = {
processValue,
processStyles
};processValue('flex', 1) returns 1 @testprocessValue('opacity', 0.5) returns 0.5 @testprocessValue('zIndex', 100) returns 100 @testprocessValue('width', 200) returns "200px" @testprocessValue('height', 0) returns 0 @testprocessValue('margin', 0) returns 0 @testprocessValue('--custom-size', 10) returns 10 @testprocessValue('color', 'red') returns "red" @testprocessStyles({ flex: 1, width: 100, opacity: 0.8, color: 'blue' }) returns { flex: "1", width: "100px", opacity: "0.8", color: "blue" } @testprocessStyles({ zIndex: 999, padding: 20, lineHeight: 1.5 }) returns { zIndex: "999", padding: "20px", lineHeight: "1.5" } @testProvides efficient lookup of CSS properties that accept unitless numeric values.
Install with Tessl CLI
npx tessl i tessl/npm-emotion--unitless