Last active
April 17, 2020 10:53
-
-
Save vincentorback/1dbf671de067589bc48869969e929e15 to your computer and use it in GitHub Desktop.
List z-index values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const postcss = require('postcss') | |
module.exports = postcss.plugin('postcss-zindex', (options) => { | |
return (css) => { | |
let nodes = [] | |
// TODO: Some options? | |
// Get all z-index declarations | |
css.walkDecls('z-index', (decl, i) => { | |
nodes.push({ | |
selector: decl.parent.selector, | |
value: parseInt(decl.value) | |
}) | |
}) | |
// Sort them by weight | |
nodes.sort((a, b) => { | |
if (a.value < b.value) { | |
return 1 | |
} | |
if (a.value > b.value) { | |
return -1 | |
} | |
return 0 | |
}) | |
// Log them | |
nodes.forEach(node => { | |
console.log(node.selector + ' ' + node.value) | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: