Comparing version 0.1.0 to 0.1.2
{ | ||
"name": "indent.js", | ||
"version": "0.1.0", | ||
"version": "0.1.2", | ||
"homepage": "https://github.com/zebzhao/indent.js", | ||
"main": "lib/indent.js", | ||
"dependencies": { | ||
@@ -6,0 +7,0 @@ }, |
@@ -0,0 +0,0 @@ ;(function(root, factory) { |
@@ -0,0 +0,0 @@ var sectionHeight = function() { |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ var gulp = require('gulp'); |
@@ -0,0 +0,0 @@ module.exports = function(config){ |
@@ -219,4 +219,4 @@ ;(function(root, factory) { | ||
while (l < lineCount) { | ||
var line = lines[l].trim() + '\r\n'; | ||
var lineToMatch = cleanEscapedChars(line); | ||
var line = lines[l].trim(); | ||
var lineToMatch = cleanEscapedChars(line) + '\r\n'; | ||
@@ -256,3 +256,3 @@ matchStart = matchStartRule(lineToMatch, rules, pos); | ||
return newLines.join(""); | ||
return newLines.join('\r\n'); | ||
@@ -259,0 +259,0 @@ function implementRule(match) { |
@@ -10,4 +10,4 @@ ;(function(root, factory) { | ||
}(this, function() { | ||
var indent=function(){function n(n,e){return t(n,s,e)}function e(n,e){return t(n,m,e)}function t(n,e,t){function d(n){y=n.cursor,k=n.rule,I.push(k),k.indent&&u()}function c(){I.pop(),k=I[I.length-1]}function s(){p=0;for(var n,e=0;e<v.length;e++)n=v[e],n.open&&n.line!=b&&p++}function m(){x[b]=a(t,p)+A,b++,y=0,s()}function u(){var n=v[v.length-1];n&&n.line==b?n.indent++:v.push({indent:1,open:!0,line:b})}function h(){var n=v[v.length-1];n&&(n.open=b==n.line,--n.indent<=0&&v.pop())}for(var k,g,f,T=n.split(/[\r]?\n/gi),l=T.length,x=[],v=[],I=[],p=0,b=0,y=0;b<l;){var A=T[b].trim()+"\r\n",L=r(A);if(f=o(L,e,y),I.length)if(g=i(L,k,y),g.matchIndex==-1){if(k.ignore){m();continue}}else if(k.ignore||f.matchIndex==-1||g.matchIndex<=f.matchIndex){k.indent&&(h(),0==g.matchIndex&&s()),y=g.cursor,c();continue}f.matchIndex!=-1?d(f):m()}return x.join("")}function a(n,e){return new Array(e+1).join(n)}function r(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,o,i=null,c=n.length,s=0;s<e.length;s++)o=e[s],r=d(n,o.startToken,o),r.matchIndex!=-1&&r.matchIndex<c&&(c=r.matchIndex,a=r,i=o);return{rule:i,matchIndex:i?c+t:-1,cursor:i?c+t+a.matchLength:-1}}function i(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,o=0,i=0;i<e.length;i++)if(a=e[i],"function"==typeof a){var d=a(n,t);r=d.matchIndex,o=d.length}else if(r=n.search(a),r!=-1){o=n.match(a)[0].length;break}return{matchIndex:r,matchLength:o,cursor:r+o,patternIndex:i}}var c=/\r*\n/,s=[{name:"line comment",startToken:[/\/\//],endToken:[c],ignore:!0,indent:!1},{name:"block comment",startToken:[/\/\*/],endToken:[/\*\//],ignore:!0,indent:!1},{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),o=d(r,e.endToken,e);if(o.matchIndex!=-1){r=r.substring(0,o.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,indent:!1,advance:!0},{name:"string",startToken:[/\"/],endToken:[/\"/,c],ignore:!0,indent:!1,advance:!0},{name:"string",startToken:[/\'/],endToken:[/\'/,c],ignore:!0,indent:!1,advance:!0},{name:"string",startToken:[/\`/],endToken:[/\`/],ignore:!0,indent:!1,advance:!0},{name:"if",startToken:[/^if[\s]*(?=\()/,/[\s]+if[\s]*(?=\()/],endToken:[/else[\s]+/,/\{/,/\;/],indent:!0},{name:"for",startToken:[/^for[\s]*(?=\()/],endToken:[/\{/,/\;/],indent:!0},{name:"else",startToken:[/else[\s]+/],endToken:[/if/,/\{/,/\;/,c],indent:!0},{name:"bracket",startToken:[/\(/],endToken:[/\)/],indent:!0,advance:!0},{name:"array",startToken:[/\[/],endToken:[/\]/],indent:!0,advance:!0},{name:"block",startToken:[/\{/],endToken:[/\}/],indent:!0,advance:!0},{name:"var",startToken:[/var[\s]+/],endToken:[/\;/],indent:!0},{name:"case",startToken:[/^case[\s]+/],endToken:[/break[\s;]+/,/^case[\s]+/,/^default[\s]+/,/\}/],indent:!0}],m=[{name:"comment",startToken:[/\<\!\-\-/],endToken:[/\-\-\>/],ignore:!0,indent:!1,advance:!0},{name:"doctype",startToken:[/\<\!/],endToken:[c],ignore:!0,indent:!1,advance:!0},{name:"link|br|input|meta",startToken:[/\<(link|br|input|meta)/i],endToken:[/(\"[^\"]*\"|'[^']*'|[^'\">])*>/],ignore:!0,indent:!1,advance:!0},{name:"tag",startToken:[/<(\"[^\"]*\"|'[^']*'|[^'\">])*>/],endToken:[/\<\/[^\>]+\>/],indent:!0,advance:!0},{name:"tag",startToken:[/<(\"[^\"]*\"|'[^']*'|[^'\">])*/],endToken:[/\/\>/],indent:!1,advance:!0}].concat(s);return{indentCSS:n,indentJS:n,indentHTML:e}}(); | ||
var indent=function(){function n(n,e){return t(n,s,e)}function e(n,e){return t(n,m,e)}function t(n,e,t){function d(n){y=n.cursor,k=n.rule,I.push(k),k.indent&&u()}function c(){I.pop(),k=I[I.length-1]}function s(){p=0;for(var n,e=0;e<v.length;e++)n=v[e],n.open&&n.line!=b&&p++}function m(){x[b]=a(t,p)+A,b++,y=0,s()}function u(){var n=v[v.length-1];n&&n.line==b?n.indent++:v.push({indent:1,open:!0,line:b})}function h(){var n=v[v.length-1];n&&(n.open=b==n.line,--n.indent<=0&&v.pop())}for(var k,g,f,T=n.split(/[\r]?\n/gi),l=T.length,x=[],v=[],I=[],p=0,b=0,y=0;b<l;){var A=T[b].trim(),L=r(A)+"\r\n";if(f=o(L,e,y),I.length)if(g=i(L,k,y),g.matchIndex==-1){if(k.ignore){m();continue}}else if(k.ignore||f.matchIndex==-1||g.matchIndex<=f.matchIndex){k.indent&&(h(),0==g.matchIndex&&s()),y=g.cursor,c();continue}f.matchIndex!=-1?d(f):m()}return x.join("\r\n")}function a(n,e){return new Array(e+1).join(n)}function r(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,o,i=null,c=n.length,s=0;s<e.length;s++)o=e[s],r=d(n,o.startToken,o),r.matchIndex!=-1&&r.matchIndex<c&&(c=r.matchIndex,a=r,i=o);return{rule:i,matchIndex:i?c+t:-1,cursor:i?c+t+a.matchLength:-1}}function i(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,o=0,i=0;i<e.length;i++)if(a=e[i],"function"==typeof a){var d=a(n,t);r=d.matchIndex,o=d.length}else if(r=n.search(a),r!=-1){o=n.match(a)[0].length;break}return{matchIndex:r,matchLength:o,cursor:r+o,patternIndex:i}}var c=/\r*\n/,s=[{name:"line comment",startToken:[/\/\//],endToken:[c],ignore:!0,indent:!1},{name:"block comment",startToken:[/\/\*/],endToken:[/\*\//],ignore:!0,indent:!1},{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),o=d(r,e.endToken,e);if(o.matchIndex!=-1){r=r.substring(0,o.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,indent:!1,advance:!0},{name:"string",startToken:[/\"/],endToken:[/\"/,c],ignore:!0,indent:!1,advance:!0},{name:"string",startToken:[/\'/],endToken:[/\'/,c],ignore:!0,indent:!1,advance:!0},{name:"string",startToken:[/\`/],endToken:[/\`/],ignore:!0,indent:!1,advance:!0},{name:"if",startToken:[/^if[\s]*(?=\()/,/[\s]+if[\s]*(?=\()/],endToken:[/else[\s]+/,/\{/,/\;/],indent:!0},{name:"for",startToken:[/^for[\s]*(?=\()/],endToken:[/\{/,/\;/],indent:!0},{name:"else",startToken:[/else[\s]+/],endToken:[/if/,/\{/,/\;/,c],indent:!0},{name:"bracket",startToken:[/\(/],endToken:[/\)/],indent:!0,advance:!0},{name:"array",startToken:[/\[/],endToken:[/\]/],indent:!0,advance:!0},{name:"block",startToken:[/\{/],endToken:[/\}/],indent:!0,advance:!0},{name:"var",startToken:[/var[\s]+/],endToken:[/\;/],indent:!0},{name:"case",startToken:[/^case[\s]+/],endToken:[/break[\s;]+/,/^case[\s]+/,/^default[\s]+/,/\}/],indent:!0}],m=[{name:"comment",startToken:[/\<\!\-\-/],endToken:[/\-\-\>/],ignore:!0,indent:!1,advance:!0},{name:"doctype",startToken:[/\<\!/],endToken:[c],ignore:!0,indent:!1,advance:!0},{name:"link|br|input|meta",startToken:[/\<(link|br|input|meta)/i],endToken:[/(\"[^\"]*\"|'[^']*'|[^'\">])*>/],ignore:!0,indent:!1,advance:!0},{name:"tag",startToken:[/<(\"[^\"]*\"|'[^']*'|[^'\">])*>/],endToken:[/\<\/[^\>]+\>/],indent:!0,advance:!0},{name:"tag",startToken:[/<(\"[^\"]*\"|'[^']*'|[^'\">])*/],endToken:[/\/\>/],indent:!1,advance:!0}].concat(s);return{indentCSS:n,indentJS:n,indentHTML:e}}(); | ||
return indent; | ||
})); |
{ | ||
"name": "indent.js", | ||
"version": "0.1.0", | ||
"version": "0.1.2", | ||
"description": "Fast minimalistic pure indentation of JavaScript, CSS, and HTML.", | ||
@@ -5,0 +5,0 @@ "main": "lib/indent.js", |
@@ -0,0 +0,0 @@ # indent.js |
@@ -210,4 +210,4 @@ var indent = (function() { | ||
while (l < lineCount) { | ||
var line = lines[l].trim() + '\r\n'; | ||
var lineToMatch = cleanEscapedChars(line); | ||
var line = lines[l].trim(); | ||
var lineToMatch = cleanEscapedChars(line) + '\r\n'; | ||
@@ -247,3 +247,3 @@ matchStart = matchStartRule(lineToMatch, rules, pos); | ||
return newLines.join(""); | ||
return newLines.join('\r\n'); | ||
@@ -250,0 +250,0 @@ function implementRule(match) { |
@@ -29,3 +29,2 @@ describe('comment.spec.js', function() { | ||
} | ||
*/ | ||
@@ -53,5 +52,5 @@ }); | ||
*/ | ||
}) + '*/\r\n'; | ||
}) + '*/'; | ||
expect(indent.indentJS(input, ' ')).toEqual(expected); | ||
}); | ||
}); |
@@ -21,3 +21,2 @@ describe('core.spec.js', function() { | ||
})(); | ||
*/ | ||
@@ -24,0 +23,0 @@ }); |
@@ -23,3 +23,2 @@ describe('css.spec.js', function() { | ||
} | ||
*/ | ||
@@ -26,0 +25,0 @@ }); |
@@ -273,3 +273,2 @@ describe('html.spec.js', function() { | ||
</html> | ||
*/ | ||
@@ -276,0 +275,0 @@ }); |
@@ -15,3 +15,2 @@ describe('regex.spec.js', function() { | ||
var rscriptType = ( /^$|\/(?:java|ecma)script/i ); | ||
*/ | ||
@@ -32,3 +31,2 @@ }); | ||
followingDoc(); | ||
*/ | ||
@@ -97,3 +95,2 @@ }); | ||
} | ||
*/ | ||
@@ -100,0 +97,0 @@ }); |
@@ -29,3 +29,2 @@ describe('statements.spec.js', function() { | ||
} | ||
*/ | ||
@@ -60,3 +59,2 @@ }); | ||
} | ||
*/ | ||
@@ -101,3 +99,2 @@ }); | ||
rtypenamespace = /^([^.]*)(?:\.(.+)|)/; | ||
*/ | ||
@@ -124,3 +121,2 @@ }); | ||
); | ||
*/ | ||
@@ -150,3 +146,2 @@ }); | ||
execute(); | ||
*/ | ||
@@ -153,0 +148,0 @@ }); |
@@ -13,3 +13,3 @@ describe('string.spec.js', function() { | ||
} | ||
*/ | ||
*/ | ||
}); | ||
@@ -26,3 +26,2 @@ var expected = hereDoc(function() {/*! | ||
} | ||
*/ | ||
@@ -48,3 +47,2 @@ }); | ||
var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); | ||
*/ | ||
@@ -51,0 +49,0 @@ }); |
@@ -0,0 +0,0 @@ function hereDoc(f) { |
@@ -0,0 +0,0 @@ var fs = require('fs'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1369328
2563