Comparing version 0.1.3 to 0.1.4
{ | ||
"name": "indent.js", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/zebzhao/indent.js", | ||
"main": "lib/indent.js", | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"ignore": [ | ||
@@ -9,0 +8,0 @@ "node_modules", |
@@ -58,4 +58,4 @@ ;(function(root, factory) { | ||
langs: "html", | ||
name: "link|br|input|meta", | ||
startToken: [/\<(link|br|input|meta)/i], | ||
name: "link|br|hr|input|img|meta", | ||
startToken: [/\<(link|br|hr|input|img|meta)/i], | ||
endToken: [/>/], | ||
@@ -62,0 +62,0 @@ advance: true |
@@ -10,4 +10,4 @@ ;(function(root, factory) { | ||
}(this, function() { | ||
var indent=function(){function n(n){if(l[n])return l[n];var e=[];l[n]=e;for(var t=0;t<m.length;t++)m[t].langs.indexOf(n.toLowerCase())!=-1&&e.push(m[t]);return e}function e(e,t){return s(e,n("js"),t)}function t(e,t){return s(e,n("css"),t)}function a(e,t){return s(e,n("html"),t)}function s(e,t,a){function s(e){y=e.cursor,u=e.rule,p.push(u),u.indent&&m(u.lineOffset),u.rules&&(A=n(u.rules))}function d(){u.indent&&(g(),0==k.matchIndex&&l()),u.rules&&(A=null),p.pop(),u=p[p.length-1]}function l(){j=0;for(var n,e=0;e<I.length;e++)n=I[e],n.open&&n.line!=b&&j++}function h(){v[b]=r(a,j)+w,b++,y=0,l()}function m(n){var e=I[I.length-1];e&&e.line==b?e.indent++:(I.push({indent:1,open:!0,line:n?b+n:b}),n<0&&l())}function g(){var n=I[I.length-1];n&&(n.open=b==n.line,--n.indent<=0&&I.pop())}for(var u,k,f,T=e.split(/[\r]?\n/gi),x=T.length,v=[],I=[],p=[],j=0,b=0,y=0,A=null;b<x;){var w=T[b].trim(),z=o(w)+"\r\n";if(f=i(z,A||t,y),p.length)if(k=c(z,u,y),k.matchIndex==-1){if(u.ignore){h();continue}}else if(u.ignore||f.matchIndex==-1||k.matchIndex<=f.matchIndex){d(),y=k.cursor;continue}f.matchIndex!=-1?s(f):h()}return v.join("\r\n")}function r(n,e){return new Array(e+1).join(n)}function o(n){return n.replace(/\\(u[0-9A-Za-z]{4}|u\{[0-9A-Za-z]{1,6}]\}|x[0-9A-Za-z]{2}|.)/g,"0")}function i(n,e,t){n=n.substring(t,n.length);for(var a,s,r,o=null,i=n.length,c=0;c<e.length;c++)r=e[c],s=d(n,r.startToken,r),s.matchIndex!=-1&&s.matchIndex<i&&(!r.head||0==t)&&(i=s.matchIndex,a=s,o=r);return{rule:o,matchIndex:o?i+t:-1,cursor:o?i+t+a.matchLength:-1}}function c(n,e,t){n=n.substr(t,n.length);var a=d(n,e.endToken,e),s=e.advance?a.matchIndex+a.matchLength:a.matchIndex;return{matchIndex:a.matchIndex==-1?-1:a.matchIndex+t,cursor:s==-1?-1:s+t}}function d(n,e,t){for(var a,s=-1,r=0,o=0;o<e.length;o++)if(a=e[o],"function"==typeof a){var i=a(n,t);s=i.matchIndex,r=i.length}else if(s=n.search(a),s!=-1){r=n.match(a)[0].length;break}return{matchIndex:s,matchLength:r,cursor:s+r,patternIndex:o}}var l={},h=/\r*\n/,m=[{langs:"html",name:"comment",startToken:[/\<\!\-\-/],endToken:[/\-\-\>/],ignore:!0,advance:!0},{langs:"html",name:"doctype",startToken:[/\<\!/],endToken:[h],ignore:!0,advance:!0},{langs:"html",name:"link|br|input|meta",startToken:[/\<(link|br|input|meta)/i],endToken:[/>/],advance:!0},{langs:"html",name:"mode switch js",startToken:[function(n,e){var t=/<script[\s>].*/i,a=/<\/script>/i,s=t.exec(n),r=a.exec(n);return s&&(!r||r.index<s.index)?{matchIndex:s.index,length:s[0].length}:{matchIndex:-1}}],endToken:[/<\/script>/i],rules:"js",advance:!0,indent:!0},{langs:"html",name:"mode switch css",startToken:[function(n,e){var t=/<style[\s>].*/i,a=/<\/style>/i,s=t.exec(n),r=a.exec(n);return s&&(!r||r.index<s.index)?{matchIndex:s.index,length:s[0].length}:{matchIndex:-1}}],endToken:[/<\/style>/i],rules:"css",advance:!0,indent:!0},{langs:"html",name:"close-tag",startToken:[/<\/[A-Za-z0-9\-]+>/],endToken:[/./],indent:!0},{langs:"html",name:"tag attr",startToken:[/<[A-Za-z0-9\-]+/],endToken:[/>/],indent:!0},{langs:"html",name:"tag",startToken:[/>/],endToken:[/<\/[A-Za-z0-9\-]+>/],indent:!0,advance:!0},{langs:"js",name:"line comment",startToken:[/\/\//],endToken:[h],ignore:!0},{langs:"js css",name:"block comment",startToken:[/\/\*/],endToken:[/\*\//],ignore:!0},{langs:"js",name:"regex",startToken:[function(n,e){var t=/[(,=:[!&|?{};][\s]*\/[^\/]|^[\s]*\/[^\/]/,a=n.search(t);if(a!=-1){a=n.indexOf("/",a);var s=n.substring(a+1),r=d(s,e.endToken,e);if(r.matchIndex!=-1){s=s.substring(0,r.matchIndex);try{return new RegExp(s),{matchIndex:a,length:1}}catch(o){return{matchIndex:-1}}}}return{matchIndex:-1}}],endToken:[function(n,e){for(var t=0,a=n.indexOf("/");a!=-1;)try{new RegExp(n.substring(0,a));break}catch(s){a=n.indexOf("/",t),t=a+1}return{matchIndex:a,length:a==-1?0:1}}],ignore:!0,advance:!0},{langs:"js css html",name:"string",startToken:[/\"/],endToken:[/\"/,h],ignore:!0,advance:!0},{langs:"js css html",name:"string",startToken:[/\'/],endToken:[/\'/,h],ignore:!0,advance:!0},{langs:"js css html",name:"string",startToken:[/\`/],endToken:[/\`/],ignore:!0,advance:!0},{langs:"js",name:"if",startToken:[/^if[\s]*(?=\()/,/[\s]+if[\s]*(?=\()/],endToken:[/else[\s]+/,/\{/,/;/],indent:!0},{langs:"js",name:"for",startToken:[/^for[\s]*(?=\()/],endToken:[/\{/,/;/],indent:!0},{langs:"js",name:"else",startToken:[/else[\s]+/],endToken:[/if/,/\{/,/;/,h],indent:!0},{langs:"js css",name:"bracket",startToken:[/\([\s]*(var)?/],endToken:[/\)/],indent:!0,advance:!0},{langs:"js",name:"dot chain",startToken:[/^\../],endToken:[/;/,h],indent:!0,head:!0,lineOffset:-1},{langs:"js",name:"dot chain",startToken:[/\.\s*$/],endToken:[function(n,e){return{matchIndex:n.length?1:-1,length:n.length?0:1}}],indent:!0},{langs:"js css",name:"array",startToken:[/\[/],endToken:[/]/],indent:!0,advance:!0},{langs:"js css",name:"block",startToken:[/\{/],endToken:[/}/],indent:!0,advance:!0},{langs:"js",name:"var",startToken:[/var[\s]+/],endToken:[/;/],indent:!0},{langs:"js",name:"case",startToken:[/^case[\s]+/],endToken:[/break[\s;]+/,/^case[\s]+/,/^default[\s]+/,/}/],indent:!0}];return{indentCSS:t,indentJS:e,indentHTML:a}}(); | ||
var indent=function(){function n(n){if(l[n])return l[n];var e=[];l[n]=e;for(var t=0;t<m.length;t++)m[t].langs.indexOf(n.toLowerCase())!=-1&&e.push(m[t]);return e}function e(e,t){return r(e,n("js"),t)}function t(e,t){return r(e,n("css"),t)}function a(e,t){return r(e,n("html"),t)}function r(e,t,a){function r(e){y=e.cursor,u=e.rule,p.push(u),u.indent&&m(u.lineOffset),u.rules&&(A=n(u.rules))}function d(){u.indent&&(g(),0==k.matchIndex&&l()),u.rules&&(A=null),p.pop(),u=p[p.length-1]}function l(){j=0;for(var n,e=0;e<I.length;e++)n=I[e],n.open&&n.line!=b&&j++}function h(){v[b]=s(a,j)+w,b++,y=0,l()}function m(n){var e=I[I.length-1];e&&e.line==b?e.indent++:(I.push({indent:1,open:!0,line:n?b+n:b}),n<0&&l())}function g(){var n=I[I.length-1];n&&(n.open=b==n.line,--n.indent<=0&&I.pop())}for(var u,k,f,T=e.split(/[\r]?\n/gi),x=T.length,v=[],I=[],p=[],j=0,b=0,y=0,A=null;b<x;){var w=T[b].trim(),z=i(w)+"\r\n";if(f=o(z,A||t,y),p.length)if(k=c(z,u,y),k.matchIndex==-1){if(u.ignore){h();continue}}else if(u.ignore||f.matchIndex==-1||k.matchIndex<=f.matchIndex){d(),y=k.cursor;continue}f.matchIndex!=-1?r(f):h()}return v.join("\r\n")}function s(n,e){return new Array(e+1).join(n)}function i(n){return n.replace(/\\(u[0-9A-Za-z]{4}|u\{[0-9A-Za-z]{1,6}]\}|x[0-9A-Za-z]{2}|.)/g,"0")}function o(n,e,t){n=n.substring(t,n.length);for(var a,r,s,i=null,o=n.length,c=0;c<e.length;c++)s=e[c],r=d(n,s.startToken,s),r.matchIndex!=-1&&r.matchIndex<o&&(!s.head||0==t)&&(o=r.matchIndex,a=r,i=s);return{rule:i,matchIndex:i?o+t:-1,cursor:i?o+t+a.matchLength:-1}}function c(n,e,t){n=n.substr(t,n.length);var a=d(n,e.endToken,e),r=e.advance?a.matchIndex+a.matchLength:a.matchIndex;return{matchIndex:a.matchIndex==-1?-1:a.matchIndex+t,cursor:r==-1?-1:r+t}}function d(n,e,t){for(var a,r=-1,s=0,i=0;i<e.length;i++)if(a=e[i],"function"==typeof a){var o=a(n,t);r=o.matchIndex,s=o.length}else if(r=n.search(a),r!=-1){s=n.match(a)[0].length;break}return{matchIndex:r,matchLength:s,cursor:r+s,patternIndex:i}}var l={},h=/\r*\n/,m=[{langs:"html",name:"comment",startToken:[/\<\!\-\-/],endToken:[/\-\-\>/],ignore:!0,advance:!0},{langs:"html",name:"doctype",startToken:[/\<\!/],endToken:[h],ignore:!0,advance:!0},{langs:"html",name:"link|br|hr|input|img|meta",startToken:[/\<(link|br|hr|input|img|meta)/i],endToken:[/>/],advance:!0},{langs:"html",name:"mode switch js",startToken:[function(n,e){var t=/<script[\s>].*/i,a=/<\/script>/i,r=t.exec(n),s=a.exec(n);return r&&(!s||s.index<r.index)?{matchIndex:r.index,length:r[0].length}:{matchIndex:-1}}],endToken:[/<\/script>/i],rules:"js",advance:!0,indent:!0},{langs:"html",name:"mode switch css",startToken:[function(n,e){var t=/<style[\s>].*/i,a=/<\/style>/i,r=t.exec(n),s=a.exec(n);return r&&(!s||s.index<r.index)?{matchIndex:r.index,length:r[0].length}:{matchIndex:-1}}],endToken:[/<\/style>/i],rules:"css",advance:!0,indent:!0},{langs:"html",name:"close-tag",startToken:[/<\/[A-Za-z0-9\-]+>/],endToken:[/./],indent:!0},{langs:"html",name:"tag attr",startToken:[/<[A-Za-z0-9\-]+/],endToken:[/>/],indent:!0},{langs:"html",name:"tag",startToken:[/>/],endToken:[/<\/[A-Za-z0-9\-]+>/],indent:!0,advance:!0},{langs:"js",name:"line comment",startToken:[/\/\//],endToken:[h],ignore:!0},{langs:"js css",name:"block comment",startToken:[/\/\*/],endToken:[/\*\//],ignore:!0},{langs:"js",name:"regex",startToken:[function(n,e){var t=/[(,=:[!&|?{};][\s]*\/[^\/]|^[\s]*\/[^\/]/,a=n.search(t);if(a!=-1){a=n.indexOf("/",a);var r=n.substring(a+1),s=d(r,e.endToken,e);if(s.matchIndex!=-1){r=r.substring(0,s.matchIndex);try{return new RegExp(r),{matchIndex:a,length:1}}catch(i){return{matchIndex:-1}}}}return{matchIndex:-1}}],endToken:[function(n,e){for(var t=0,a=n.indexOf("/");a!=-1;)try{new RegExp(n.substring(0,a));break}catch(r){a=n.indexOf("/",t),t=a+1}return{matchIndex:a,length:a==-1?0:1}}],ignore:!0,advance:!0},{langs:"js css html",name:"string",startToken:[/\"/],endToken:[/\"/,h],ignore:!0,advance:!0},{langs:"js css html",name:"string",startToken:[/\'/],endToken:[/\'/,h],ignore:!0,advance:!0},{langs:"js css html",name:"string",startToken:[/\`/],endToken:[/\`/],ignore:!0,advance:!0},{langs:"js",name:"if",startToken:[/^if[\s]*(?=\()/,/[\s]+if[\s]*(?=\()/],endToken:[/else[\s]+/,/\{/,/;/],indent:!0},{langs:"js",name:"for",startToken:[/^for[\s]*(?=\()/],endToken:[/\{/,/;/],indent:!0},{langs:"js",name:"else",startToken:[/else[\s]+/],endToken:[/if/,/\{/,/;/,h],indent:!0},{langs:"js css",name:"bracket",startToken:[/\([\s]*(var)?/],endToken:[/\)/],indent:!0,advance:!0},{langs:"js",name:"dot chain",startToken:[/^\../],endToken:[/;/,h],indent:!0,head:!0,lineOffset:-1},{langs:"js",name:"dot chain",startToken:[/\.\s*$/],endToken:[function(n,e){return{matchIndex:n.length?1:-1,length:n.length?0:1}}],indent:!0},{langs:"js css",name:"array",startToken:[/\[/],endToken:[/]/],indent:!0,advance:!0},{langs:"js css",name:"block",startToken:[/\{/],endToken:[/}/],indent:!0,advance:!0},{langs:"js",name:"var",startToken:[/var[\s]+/],endToken:[/;/],indent:!0},{langs:"js",name:"case",startToken:[/^case[\s]+/],endToken:[/break[\s;]+/,/^case[\s]+/,/^default[\s]+/,/}/],indent:!0}];return{indentCSS:t,indentJS:e,indentHTML:a}}(); | ||
return indent; | ||
})); |
{ | ||
"name": "indent.js", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Fast minimalistic pure indentation of JavaScript, CSS, and HTML.", | ||
@@ -11,4 +11,3 @@ "main": "lib/indent.js", | ||
}, | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -15,0 +14,0 @@ "jasmine-core": "^2.2.0", |
@@ -49,4 +49,4 @@ var indent = (function() { | ||
langs: "html", | ||
name: "link|br|input|meta", | ||
startToken: [/\<(link|br|input|meta)/i], | ||
name: "link|br|hr|input|img|meta", | ||
startToken: [/\<(link|br|hr|input|img|meta)/i], | ||
endToken: [/>/], | ||
@@ -53,0 +53,0 @@ advance: true |
@@ -18,2 +18,38 @@ describe('html.spec.js', function() { | ||
it('should handle self closing tags', function() { | ||
var input = hereDoc(function() {/*! | ||
<input> | ||
<input /> | ||
<br> | ||
<br /> | ||
<img> | ||
<img /> | ||
<link> | ||
<link /> | ||
<meta> | ||
<meta /> | ||
<hr> | ||
<hr /> | ||
<random> | ||
<random />*/ | ||
}); | ||
var expected = hereDoc(function() {/*! | ||
<input> | ||
<input /> | ||
<br> | ||
<br /> | ||
<img> | ||
<img /> | ||
<link> | ||
<link /> | ||
<meta> | ||
<meta /> | ||
<hr> | ||
<hr /> | ||
<random> | ||
<random />*/ | ||
}); | ||
expect(indent.indentHTML(input, ' ')).toEqual(expected); | ||
}); | ||
it('should handle wrapped attrs', function() { | ||
@@ -20,0 +56,0 @@ var input = hereDoc(function() {/*! |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1383730
54
2946