* Recursive deep style passing function
(prop, value, options)
| 20 | * Recursive deep style passing function |
| 21 | */ |
| 22 | function iterate(prop, value, options) { |
| 23 | if (value == null) return value |
| 24 | |
| 25 | if (Array.isArray(value)) { |
| 26 | for (let i = 0; i < value.length; i++) { |
| 27 | value[i] = iterate(prop, value[i], options) |
| 28 | } |
| 29 | } else if (typeof value === 'object') { |
| 30 | if (prop === 'fallbacks') { |
| 31 | for (const innerProp in value) { |
| 32 | value[innerProp] = iterate(innerProp, value[innerProp], options) |
| 33 | } |
| 34 | } else { |
| 35 | for (const innerProp in value) { |
| 36 | value[innerProp] = iterate(`${prop}-${innerProp}`, value[innerProp], options) |
| 37 | } |
| 38 | } |
| 39 | // eslint-disable-next-line no-restricted-globals |
| 40 | } else if (typeof value === 'number' && isNaN(value) === false) { |
| 41 | const unit = options[prop] || units[prop] |
| 42 | |
| 43 | // Add the unit if available, except for the special case of 0px. |
| 44 | if (unit && !(value === 0 && unit === px)) { |
| 45 | return typeof unit === 'function' ? unit(value).toString() : `${value}${unit}` |
| 46 | } |
| 47 | |
| 48 | return value.toString() |
| 49 | } |
| 50 | |
| 51 | return value |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Add unit to numeric values. |
no test coverage detected
searching dependent graphs…