MCPcopy
hub / github.com/cssinjs/jss / iterate

Function iterate

packages/jss-plugin-default-unit/src/index.js:22–52  ·  view source on GitHub ↗

* Recursive deep style passing function

(prop, value, options)

Source from the content-addressed store, hash-verified

20 * Recursive deep style passing function
21 */
22function 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.

Callers 2

onProcessStyleFunction · 0.85
onChangeValueFunction · 0.85

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…