Javascript validate css

I allow css user input.

What is an easy and efficient way to test this css on client side?

I am looking for a solution for javascript. I do not want to send css to some remote server or something else.

Context: User Permission css

Thanks.

Edit: NVM on this. I started using the server side validator: https://github.com/chriso/node-validator

+4
source share
2 answers
function getDefinedCss(s){ if(!document.styleSheets) return ''; if(typeof s== 'string') s= RegExp('\\b'+s+'\\b','i'); // IE capitalizes html selectors var A, S, DS= document.styleSheets, n= DS.length, SA= []; while(n){ S= DS[--n]; A= (S.rules)? S.rules: S.cssRules; for(var i= 0, L= A.length; i<L; i++){ tem= A[i].selectorText? [A[i].selectorText, A[i].style.cssText]: [A[i]+'']; if(s.test(tem[0])) SA[SA.length]= tem; } } return SA.join('\n\n'); } // Then you check the class if exists by calling getDefinedCss('myclassname') 
0
source

You can use the CSSLint engine in the application . Its source is available at https://github.com/stubbornella/csslint

0
source

Source: https://habr.com/ru/post/1393104/


All Articles