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
A utility for formatting CSS style values from JavaScript style objects, ensuring that numeric values are properly handled based on whether they require units.
When provided with a CSS property name and a numeric value, the formatter should determine whether the property accepts unitless values or requires units (like 'px'). Properties that accept unitless values should have the number returned as-is, while properties that require units should have 'px' appended.
Zero values should never have units appended, regardless of the property type.
Transform complete style objects where numeric values are converted to appropriate string or numeric representations.
{ flex: 1, width: 100, opacity: 0.8 }, returns { flex: "1", width: "100px", opacity: "0.8" } @test{ zIndex: 10, margin: 20, lineHeight: 1.5 }, returns { zIndex: "10", margin: "20px", lineHeight: "1.5" } @test@generates
/**
* Formats a CSS property value, adding 'px' units when necessary.
*
* @param {string} property - The CSS property name (e.g., "width", "flex", "opacity").
* @param {number} value - The numeric value to format.
* @returns {number|string} The formatted value - either the original number or a string with 'px' appended.
*/
function formatValue(property, value) {
// IMPLEMENTATION HERE
}
/**
* Processes a style object, formatting all numeric values appropriately.
*
* @param {Object} styles - An object with CSS property names as keys and values (string or number).
* @returns {Object} A new object with all numeric values properly formatted as strings.
*/
function processStyles(styles) {
// IMPLEMENTATION HERE
}
module.exports = {
formatValue,
processStyles,
};Provides lookup object for CSS properties that accept unitless numeric values.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-emotion--unitless