Just copy the namespaces.js
and past it in the console for the site you're checking and it will log out any namespaces that are used.
Last active
June 8, 2016 22:01
-
-
Save tjbenton/7692539e5416a1a1fe14406a94e6cfbe to your computer and use it in GitHub Desktop.
Checks for namespacing classes.
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 $ = (selector) => [].slice.call(document.querySelectorAll(selector)) | |
const classes = $('[class]') | |
.reduce((prev, next) => { | |
let _class = next.className | |
if (typeof _class !== 'string') { | |
_class = _class.baseVal | |
} | |
return prev.concat(_class.split(' ')) | |
}, []) // combine all the classes together | |
const ids = $('[id]').map((item) => item.id) | |
const namespaces = [].concat(classes, ids) | |
.filter((name, i, array) => !!name && array.indexOf(name, i + 1) < 0) | |
.sort() // makes the output consistent | |
.reduce((prev, next) => { | |
let namespace = (next + '').match(/^#?(js|has|is|[a-z])(?:-|[A-Z])+/) || [ '', 'nonamespace' ] | |
namespace = namespace[1].replace('-', '') | |
if (!prev[namespace]) prev[namespace] = [] | |
prev[namespace].push(next) | |
return prev | |
}, {}) | |
// moves the nonamespaces to the bottom | |
if (namespaces.nonamespace) { | |
const nonamespace = namespaces.nonamespace | |
delete namespaces.nonamespace | |
namespaces.nonamespace = nonamespace | |
} | |
for (let namespace in namespaces) { | |
console.group(`namespace: ${namespace}`) | |
console.dir(namespaces[namespace]) | |
console.groupEnd() | |
} | |
})(); |
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
!function(){var e=function(e){return[].slice.call(document.querySelectorAll(e))},n=e("[class]").reduce(function(e,n){var a=n.className;return"string"!=typeof a&&(a=a.baseVal),e.concat(a.split(" "))},[]),a=e("[id]").map(function(e){return e.id}),c=[].concat(n,a).filter(function(e,n,a){return!!e&&a.indexOf(e,n+1)<0}).sort().reduce(function(e,n){var a=(n+"").match(/^#?(js|has|is|[a-z])(?:-|[A-Z])+/)||["","nonamespace"];return a=a[1].replace("-",""),e[a]||(e[a]=[]),e[a].push(n),e},{});if(c.nonamespace){var r=c.nonamespace;delete c.nonamespace,c.nonamespace=r}for(var o in c)console.group("namespace: "+o),console.dir(c[o]),console.groupEnd()}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment