-
Notifications
You must be signed in to change notification settings - Fork 22
/
vkbeautify.min.js
1 lines (1 loc) · 4.76 KB
/
vkbeautify.min.js
1
!function(){function a(a){var b=" ";if(isNaN(parseInt(a)))b=a;else switch(a){case 1:b=" ";break;case 2:b=" ";break;case 3:b=" ";break;case 4:b=" ";break;case 5:b=" ";break;case 6:b=" ";break;case 7:b=" ";break;case 8:b=" ";break;case 9:b=" ";break;case 10:b=" ";break;case 11:b=" ";break;case 12:b=" "}var c=["\n"];for(ix=0;100>ix;ix++)c.push(c[ix]+b);return c}function b(){this.step=" ",this.shift=a(this.step)}function c(a,b){return b-(a.replace(/\(/g,"").length-a.replace(/\)/g,"").length)}function d(a,b){return a.replace(/\s{1,}/g," ").replace(/ AND /gi,"~::~"+b+b+"AND ").replace(/ BETWEEN /gi,"~::~"+b+"BETWEEN ").replace(/ CASE /gi,"~::~"+b+"CASE ").replace(/ ELSE /gi,"~::~"+b+"ELSE ").replace(/ END /gi,"~::~"+b+"END ").replace(/ FROM /gi,"~::~FROM ").replace(/ GROUP\s{1,}BY/gi,"~::~GROUP BY ").replace(/ HAVING /gi,"~::~HAVING ").replace(/ IN /gi," IN ").replace(/ JOIN /gi,"~::~JOIN ").replace(/ CROSS~::~{1,}JOIN /gi,"~::~CROSS JOIN ").replace(/ INNER~::~{1,}JOIN /gi,"~::~INNER JOIN ").replace(/ LEFT~::~{1,}JOIN /gi,"~::~LEFT JOIN ").replace(/ RIGHT~::~{1,}JOIN /gi,"~::~RIGHT JOIN ").replace(/ ON /gi,"~::~"+b+"ON ").replace(/ OR /gi,"~::~"+b+b+"OR ").replace(/ ORDER\s{1,}BY/gi,"~::~ORDER BY ").replace(/ OVER /gi,"~::~"+b+"OVER ").replace(/\(\s{0,}SELECT /gi,"~::~(SELECT ").replace(/\)\s{0,}SELECT /gi,")~::~SELECT ").replace(/ THEN /gi," THEN~::~"+b).replace(/ UNION /gi,"~::~UNION~::~").replace(/ USING /gi,"~::~USING ").replace(/ WHEN /gi,"~::~"+b+"WHEN ").replace(/ WHERE /gi,"~::~WHERE ").replace(/ WITH /gi,"~::~WITH ").replace(/ ALL /gi," ALL ").replace(/ AS /gi," AS ").replace(/ ASC /gi," ASC ").replace(/ DESC /gi," DESC ").replace(/ DISTINCT /gi," DISTINCT ").replace(/ EXISTS /gi," EXISTS ").replace(/ NOT /gi," NOT ").replace(/ NULL /gi," NULL ").replace(/ LIKE /gi," LIKE ").replace(/\s{0,}SELECT /gi,"SELECT ").replace(/\s{0,}UPDATE /gi,"UPDATE ").replace(/ SET /gi," SET ").replace(/~::~{1,}/g,"~::~").split("~::~")}b.prototype.xml=function(b,c){var d=b.replace(/>\s{0,}</g,"><").replace(/</g,"~::~<").replace(/\s*xmlns\:/g,"~::~xmlns:").replace(/\s*xmlns\=/g,"~::~xmlns=").split("~::~"),e=d.length,f=!1,g=0,h="",i=0,j=c?a(c):this.shift;for(i=0;e>i;i++)d[i].search(/<!/)>-1?(h+=j[g]+d[i],f=!0,(d[i].search(/-->/)>-1||d[i].search(/\]>/)>-1||d[i].search(/!DOCTYPE/)>-1)&&(f=!1)):d[i].search(/-->/)>-1||d[i].search(/\]>/)>-1?(h+=d[i],f=!1):/^<\w/.exec(d[i-1])&&/^<\/\w/.exec(d[i])&&/^<[\w:\-\.\,]+/.exec(d[i-1])==/^<\/[\w:\-\.\,]+/.exec(d[i])[0].replace("/","")?(h+=d[i],f||g--):d[i].search(/<\w/)>-1&&-1==d[i].search(/<\//)&&-1==d[i].search(/\/>/)?h=h+=f?d[i]:j[g++]+d[i]:d[i].search(/<\w/)>-1&&d[i].search(/<\//)>-1?h=h+=f?d[i]:j[g]+d[i]:d[i].search(/<\//)>-1?h=h+=f?d[i]:j[--g]+d[i]:d[i].search(/\/>/)>-1?h=h+=f?d[i]:j[g]+d[i]:h+=d[i].search(/<\?/)>-1?j[g]+d[i]:d[i].search(/xmlns\:/)>-1||d[i].search(/xmlns\=/)>-1?j[g]+d[i]:d[i];return"\n"==h[0]?h.slice(1):h},b.prototype.json=function(a,b){var b=b?b:this.step;return"undefined"==typeof JSON?a:"string"==typeof a?JSON.stringify(JSON.parse(a),null,b):"object"==typeof a?JSON.stringify(a,null,b):a},b.prototype.css=function(b,c){var d=b.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),e=d.length,f=0,g="",h=0,i=c?a(c):this.shift;for(h=0;e>h;h++)g+=/\{/.exec(d[h])?i[f++]+d[h]:/\}/.exec(d[h])?i[--f]+d[h]:/\*\\/.exec(d[h])?i[f]+d[h]:i[f]+d[h];return g.replace(/^\n{1,}/,"")},b.prototype.sql=function(b,e){var f=b.replace(/\s{1,}/g," ").replace(/\'/gi,"~::~'").split("~::~"),g=f.length,h=[],i=0,j=this.step,m=0,n="",o=0,p=e?a(e):this.shift;for(o=0;g>o;o++)h=o%2?h.concat(f[o]):h.concat(d(f[o],j));for(g=h.length,o=0;g>o;o++)m=c(h[o],m),/\s{0,}\s{0,}SELECT\s{0,}/.exec(h[o])&&(h[o]=h[o].replace(/\,/g,",\n"+j+j)),/\s{0,}\s{0,}SET\s{0,}/.exec(h[o])&&(h[o]=h[o].replace(/\,/g,",\n"+j+j)),/\s{0,}\(\s{0,}SELECT\s{0,}/.exec(h[o])?(i++,n+=p[i]+h[o]):/\'/.exec(h[o])?(1>m&&i&&i--,n+=h[o]):(n+=p[i]+h[o],1>m&&i&&i--);return n=n.replace(/^\n{1,}/,"").replace(/\n{1,}/g,"\n")},b.prototype.xmlmin=function(a,b){var c=b?a:a.replace(/\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return c.replace(/>\s{0,}</g,"><")},b.prototype.jsonmin=function(a){return"undefined"==typeof JSON?a:JSON.stringify(JSON.parse(a),null,0)},b.prototype.cssmin=function(a,b){var c=b?a:a.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return c.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},b.prototype.sqlmin=function(a){return a.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},window.vkbeautify=new b}();