MCPcopy
hub / github.com/postcss/autoprefixer / normalizeRowColumn

Function normalizeRowColumn

lib/hacks/grid-utils.js:1075–1114  ·  view source on GitHub ↗

* normalize the grid-template-rows/columns values * @param {String} str grid-template-rows/columns value * @return {Array} normalized array with values * @example * let normalized = normalizeRowColumn('1fr repeat(2, 20px 50px) 1fr') * normalized // <= ['1fr', '20px', '50px', '20px', '50px', '1

(str)

Source from the content-addressed store, hash-verified

1073 * normalized // <= ['1fr', '20px', '50px', '20px', '50px', '1fr']
1074 */
1075function normalizeRowColumn(str) {
1076 let normalized = parser(str).nodes.reduce((result, node) => {
1077 if (node.type === 'function' && node.value === 'repeat') {
1078 let key = 'count'
1079
1080 let [count, value] = node.nodes.reduce(
1081 (acc, n) => {
1082 if (n.type === 'word' && key === 'count') {
1083 acc[0] = Math.abs(parseInt(n.value))
1084 return acc
1085 }
1086 if (n.type === 'div' && n.value === ',') {
1087 key = 'value'
1088 return acc
1089 }
1090 if (key === 'value') {
1091 acc[1] += parser.stringify(n)
1092 }
1093 return acc
1094 },
1095 [0, '']
1096 )
1097
1098 if (count) {
1099 for (let i = 0; i < count; i++) {
1100 result.push(value)
1101 }
1102 }
1103
1104 return result
1105 }
1106 if (node.type === 'space') {
1107 return result
1108 }
1109 result.push(parser.stringify(node))
1110 return result
1111 }, [])
1112
1113 return normalized
1114}
1115
1116exports.autoplaceGridItems = autoplaceGridItems
1117

Callers 1

autoplaceGridItemsFunction · 0.85

Calls 1

stringifyMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…