UNPKG

judocss

Version:

The functional CSS toolkit designed for minimal effort and maximum efficiency.

34 lines (21 loc) 731 B
(function(){ const byAscendingLength = (a, b) => a.length - b.length; const replaceDollarVarsWithCapturingGroups = (str, dollarVars) => { var capture = "([A-Za-z0-9%#.\-]+)" var i = dollarVars.length dollarVars.sort(byAscendingLength) while(i--) { str = str.replace(dollarVars[i], capture) } return str } const queryModifierCapture = "(?:--(?:small|medium|large|small-only|medium-only))?" const classRegex = (str) => { var dollarVars = str.match(/(\$([A-Za-z0-9]+)[^\-\_]?)/g) if(dollarVars){ str = replaceDollarVarsWithCapturingGroups(str, dollarVars) } return new RegExp('^'+str+queryModifierCapture+"(?:\\*)?"+'$') } module.exports = classRegex })()