Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

indent.js

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

indent.js - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

docs/css/github-dark.css

2

bower.json
{
"name": "indent.js",
"version": "0.1.5",
"version": "0.2.0",
"homepage": "https://github.com/zebzhao/indent.js",

@@ -5,0 +5,0 @@ "main": "lib/indent.js",

@@ -6,3 +6,3 @@ var gulp = require('gulp');

gulp.task('build', ['build-minify', 'build-debug']);
gulp.task('build', ['build-minify', 'build-debug', 'build-docs']);

@@ -12,3 +12,2 @@ gulp.task('build-minify', function (cb) {

.pipe(concat('indent.min.js'))
.pipe(uglify())
.pipe(umd({

@@ -22,5 +21,11 @@ exports: function(file) {

}))
.pipe(gulp.dest('./lib'));
.pipe(uglify())
.pipe(gulp.dest('./lib'))
});
gulp.task('build-docs', function (cb) {
return gulp.src(['src/**/*.js'])
.pipe(gulp.dest('./docs/js'))
});
gulp.task('build-debug', function (cb) {

@@ -27,0 +32,0 @@ return gulp.src(['src/**/*.js'])

@@ -35,2 +35,3 @@ ;(function(root, factory) {

* lineOffset - added to the line field when rule is applied
* countdown - terminate rule after this number of lines
*

@@ -221,2 +222,3 @@ * Always keep NEW_LINE_REGEX endToken as last element,

endToken: [/else[\s]+/, /\{/, /;/],
countdown: 2,
indent: true

@@ -229,2 +231,3 @@ },

endToken: [/\{/, /;/],
countdown: 2,
indent: true

@@ -236,3 +239,4 @@ },

startToken: [/else[\s]+/],
endToken: [/if/, /\{/, /;/, NEW_LINE_REGEX],
endToken: [/if/, /\{/, /;/],
countdown: 2,
indent: true

@@ -310,20 +314,38 @@ },

return {
indentCSS: indentCSS,
indentJS: indentJS,
indentHTML: indentHTML
var exports = {
css: function (code, indentString) {
return indent(code || '', filterRules('css'), indentString || '\t');
},
js: function (code, indentString) {
return indent(code || '', filterRules('js'), indentString || '\t');
},
html: function (code, indentString) {
return indent(code || '', filterRules('html'), indentString || '\t');
},
/**
* @deprecated Since version 0.2.0. Will be deleted in version 0.3.0. Use js instead.
*/
indentJS: function(code, indentString) {
if (console && console.warn) console.warn("Calling deprecated function!");
return exports.js(code, indentString);
},
/**
* @deprecated Since version 0.2.0. Will be deleted in version 0.3.0. Use css instead.
*/
indentCSS: function(code, indentString) {
if (console && console.warn) console.warn("Calling deprecated function!");
return exports.css(code, indentString);
},
/**
* @deprecated Since version 0.2.0. Will be deleted in version 0.3.0. Use html instead.
*/
indentHTML: function(code, indentString) {
if (console && console.warn) console.warn("Calling deprecated function!");
return exports.html(code, indentString);
}
};
function indentJS(code, indentString) {
return indent(code, filterRules('js'), indentString);
}
return exports;
function indentCSS(code, indentString) {
return indent(code, filterRules('css'), indentString);
}
function indentHTML(code, indentString) {
return indent(code, filterRules('html'), indentString);
}
function indent(code, baseRules, indentation) {

@@ -335,3 +357,5 @@ var lines = code.split(/[\r]?\n/gi);

var activeRules = [];
var activeCountdowns = [];
var lastRule;
var lastCountdown;
var indents = 0;

@@ -356,5 +380,13 @@ var l = 0;

continue;
} else if (lastCountdown) {
lastCountdown--;
if (lastCountdown === 0) {
removeLastRule();
}
}
}
else if (lastRule.ignore || matchStart.matchIndex == -1 || matchEnd.matchIndex <= matchStart.matchIndex) {
else if (
lastRule.ignore ||
matchStart.matchIndex == -1 ||
matchEnd.matchIndex <= matchStart.matchIndex) {
removeLastRule();

@@ -380,3 +412,5 @@ pos = matchEnd.cursor;

lastRule = match.rule;
lastCountdown = match.countdown;
activeRules.push(lastRule);
activeCountdowns.push(lastRule.countdown);
if (lastRule.indent) {

@@ -401,3 +435,5 @@ incrementIndentation(lastRule.lineOffset);

activeRules.pop();
activeCountdowns.pop();
lastRule = activeRules[activeRules.length - 1];
lastCountdown = activeCountdowns[activeCountdowns.length - 1];
}

@@ -404,0 +440,0 @@

@@ -1,12 +0,1 @@

;(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.indent = 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,j.push(u),u.indent&&m(u.lineOffset),u.rules&&(A=n(u.rules))}function c(){u.indent&&(g(),u.endTokenIndent||0!=k.matchIndex||l()),u.rules&&(A=null),j.pop(),u=j[j.length-1]}function l(){p=0;for(var n,e=0;e<I.length;e++)n=I[e],n.open&&n.line!=b&&p++}function h(){v[b]=r(a,p)+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=[],j=[],p=0,b=0,y=0,A=null;b<x;){var w=T[b].trim(),z=o(w)+"\r\n";if(f=d(z,A||t,y),j.length)if(k=i(z,u,y),k.matchIndex==-1){if(u.ignore){h();continue}}else if(u.ignore||f.matchIndex==-1||k.matchIndex<=f.matchIndex){c(),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 d(n,e,t){n=n.substring(t,n.length);for(var a,s,r,o=null,d=n.length,i=0;i<e.length;i++)r=e[i],s=c(n,r.startToken,r),s.matchIndex!=-1&&s.matchIndex<d&&(!r.head||0==t)&&(d=s.matchIndex,a=s,o=r);return{rule:o,matchIndex:o?d+t:-1,cursor:o?d+t+a.matchLength:-1}}function i(n,e,t){n=n.substr(t,n.length);var a=c(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 c(n,e,t){for(var a,s=-1,r=0,o=0;o<e.length;o++)if(a=e[o],"function"==typeof a){var d=a(n,t);s=d.matchIndex,r=d.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|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,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=c(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]+/,/^return([\s]+|;)/,/}/],endTokenIndent:!0,indent:!0},{langs:"js",name:"default",startToken:[/^default[\s]*:/],endToken:[/break[\s;]+/,/^case[\s]+/,/^default[\s]+/,/^return([\s]+|;)/,/}/],endTokenIndent:!0,indent:!0}];return{indentCSS:t,indentJS:e,indentHTML:a}}();
return indent;
}));
!function(n,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():n.indent=e()}(this,function(){var n=function(){function n(n){if(c[n])return c[n];var e=[];c[n]=e;for(var t=0;t<i.length;t++)i[t].langs.indexOf(n.toLowerCase())!=-1&&e.push(i[t]);return e}function e(e,o,c){function d(e){A=e.cursor,g=e.rule,f=e.countdown,j.push(g),w.push(g.countdown),g.indent&&h(g.lineOffset),g.rules&&(z=n(g.rules))}function i(){g.indent&&(m(),g.endTokenIndent||0!=k.matchIndex||l()),g.rules&&(z=null),j.pop(),w.pop(),g=j[j.length-1],f=w[w.length-1]}function l(){b=0;for(var n,e=0;e<I.length;e++)n=I[e],n.open&&n.line!=y&&b++}function u(){p[y]=t(c,b)+O,y++,A=0,l()}function h(n){var e=I[I.length-1];e&&e.line==y?e.indent++:(I.push({indent:1,open:!0,line:n?y+n:y}),n<0&&l())}function m(){var n=I[I.length-1];n&&(n.open=y==n.line,--n.indent<=0&&I.pop())}for(var g,f,k,T,x=e.split(/[\r]?\n/gi),v=x.length,p=[],I=[],j=[],w=[],b=0,y=0,A=0,z=null;y<v;){var O=x[y].trim(),Z=a(O)+"\r\n";if(T=s(Z,z||o,A),j.length)if(k=r(Z,g,A),k.matchIndex==-1){if(g.ignore){u();continue}f&&(f--,0===f&&i())}else if(g.ignore||T.matchIndex==-1||k.matchIndex<=T.matchIndex){i(),A=k.cursor;continue}T.matchIndex!=-1?d(T):u()}return p.join("\r\n")}function t(n,e){return new Array(e+1).join(n)}function a(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 s(n,e,t){n=n.substring(t,n.length);for(var a,s,r,c=null,d=n.length,i=0;i<e.length;i++)r=e[i],s=o(n,r.startToken,r),s.matchIndex!=-1&&s.matchIndex<d&&(!r.head||0==t)&&(d=s.matchIndex,a=s,c=r);return{rule:c,matchIndex:c?d+t:-1,cursor:c?d+t+a.matchLength:-1}}function r(n,e,t){n=n.substr(t,n.length);var a=o(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 o(n,e,t){for(var a,s=-1,r=0,o=0;o<e.length;o++)if(a=e[o],"function"==typeof a){var c=a(n,t);s=c.matchIndex,r=c.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 c={},d=/\r*\n/,i=[{langs:"html",name:"comment",startToken:[/\<\!\-\-/],endToken:[/\-\-\>/],ignore:!0,advance:!0},{langs:"html",name:"doctype",startToken:[/\<\!/],endToken:[d],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,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:[d],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=o(s,e.endToken,e);if(r.matchIndex!=-1){s=s.substring(0,r.matchIndex);try{return new RegExp(s),{matchIndex:a,length:1}}catch(c){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:[/\"/,d],ignore:!0,advance:!0},{langs:"js css html",name:"string",startToken:[/\'/],endToken:[/\'/,d],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]+/,/\{/,/;/],countdown:2,indent:!0},{langs:"js",name:"for",startToken:[/^for[\s]*(?=\()/],endToken:[/\{/,/;/],countdown:2,indent:!0},{langs:"js",name:"else",startToken:[/else[\s]+/],endToken:[/if/,/\{/,/;/],countdown:2,indent:!0},{langs:"js css",name:"bracket",startToken:[/\([\s]*(var)?/],endToken:[/\)/],indent:!0,advance:!0},{langs:"js",name:"dot chain",startToken:[/^\../],endToken:[/;/,d],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]+/,/^return([\s]+|;)/,/}/],endTokenIndent:!0,indent:!0},{langs:"js",name:"default",startToken:[/^default[\s]*:/],endToken:[/break[\s;]+/,/^case[\s]+/,/^default[\s]+/,/^return([\s]+|;)/,/}/],endTokenIndent:!0,indent:!0}],l={css:function(t,a){return e(t||"",n("css"),a||"\t")},js:function(t,a){return e(t||"",n("js"),a||"\t")},html:function(t,a){return e(t||"",n("html"),a||"\t")},indentJS:function(n,e){return console&&console.warn&&console.warn("Calling deprecated function!"),l.js(n,e)},indentCSS:function(n,e){return console&&console.warn&&console.warn("Calling deprecated function!"),l.css(n,e)},indentHTML:function(n,e){return console&&console.warn&&console.warn("Calling deprecated function!"),l.html(n,e)}};return l}();return n});
{
"name": "indent.js",
"version": "0.1.5",
"version": "0.2.0",
"description": "Fast minimalistic pure indentation of JavaScript, CSS, and HTML.",

@@ -14,3 +14,3 @@ "main": "lib/indent.js",

"jasmine-core": "^2.2.0",
"karma": "^0.12.31",
"karma": "^1.7.0",
"karma-coverage": "^0.3.1",

@@ -17,0 +17,0 @@ "karma-jasmine": "^0.3.5",

@@ -26,3 +26,3 @@ # indent.js

```javascript
var indented = indent.indentJS(code, '\t');
var indented = indent.js(code, '\t');
console.log(indented);

@@ -34,3 +34,3 @@ ```

define(['indent'] , function (indent) {
var indented = indent.indentJS(code, '\t');
var indented = indent.js(code, '\t');
console.log(indented);

@@ -43,3 +43,8 @@ });

var indent = require('indent');
var indented = indent.indentJS(code, ' ');
// JS code
var indented = indent.js(js, ' ');
// CSS code
var indented = indent.css(css, ' ');
// HTML code
var indented = indent.html(html, ' ');
console.log(indented);

@@ -52,18 +57,12 @@ ```

##Projects with indent.js:
1. [JsWriter - Web-base JavaScript IDE](https://jswriter.com/)
Developers
---
ISupport for other languages would be nice, and greatly welcomed!
Unfortunately, I do not know these languages well enough to construct rules for them.
The rules this library uses are very simple and work on most languages with syntax using (), {}, etc...
The languages below have not been fully tested and may fail to indent properly for some special cases.
###Languages still not supported:
###Languages still not fully supported:
1. TypeScript
2. CoffeeScript
3. Pug
4. Less/Sass
1. TypeScript (partial?)
2. Less/Sass (partial?)

@@ -78,4 +77,5 @@ ###Getting the project

This project follows the [GitFlow branching model](http://nvie.com/posts/a-successful-git-branching-model). The ```master``` branch always reflects a production-ready state while the latest development is taking place in the ```develop``` branch.
This project follows the [GitFlow branching model](http://nvie.com/posts/a-successful-git-branching-model).
The ```master``` branch always reflects a production-ready state while the latest development is taking place in the ```develop``` branch.
Each time you want to work on a fix or a new feature, create a new branch based on the ```develop``` branch: ```git checkout -b BRANCH_NAME develop```. Only pull requests to the ```develop``` branch will be merged.

@@ -26,2 +26,3 @@ var indent = (function() {

* lineOffset - added to the line field when rule is applied
* countdown - terminate rule after this number of lines
*

@@ -212,2 +213,3 @@ * Always keep NEW_LINE_REGEX endToken as last element,

endToken: [/else[\s]+/, /\{/, /;/],
countdown: 2,
indent: true

@@ -220,2 +222,3 @@ },

endToken: [/\{/, /;/],
countdown: 2,
indent: true

@@ -227,3 +230,4 @@ },

startToken: [/else[\s]+/],
endToken: [/if/, /\{/, /;/, NEW_LINE_REGEX],
endToken: [/if/, /\{/, /;/],
countdown: 2,
indent: true

@@ -301,20 +305,38 @@ },

return {
indentCSS: indentCSS,
indentJS: indentJS,
indentHTML: indentHTML
var exports = {
css: function (code, indentString) {
return indent(code || '', filterRules('css'), indentString || '\t');
},
js: function (code, indentString) {
return indent(code || '', filterRules('js'), indentString || '\t');
},
html: function (code, indentString) {
return indent(code || '', filterRules('html'), indentString || '\t');
},
/**
* @deprecated Since version 0.2.0. Will be deleted in version 0.3.0. Use js instead.
*/
indentJS: function(code, indentString) {
if (console && console.warn) console.warn("Calling deprecated function!");
return exports.js(code, indentString);
},
/**
* @deprecated Since version 0.2.0. Will be deleted in version 0.3.0. Use css instead.
*/
indentCSS: function(code, indentString) {
if (console && console.warn) console.warn("Calling deprecated function!");
return exports.css(code, indentString);
},
/**
* @deprecated Since version 0.2.0. Will be deleted in version 0.3.0. Use html instead.
*/
indentHTML: function(code, indentString) {
if (console && console.warn) console.warn("Calling deprecated function!");
return exports.html(code, indentString);
}
};
function indentJS(code, indentString) {
return indent(code, filterRules('js'), indentString);
}
return exports;
function indentCSS(code, indentString) {
return indent(code, filterRules('css'), indentString);
}
function indentHTML(code, indentString) {
return indent(code, filterRules('html'), indentString);
}
function indent(code, baseRules, indentation) {

@@ -326,3 +348,5 @@ var lines = code.split(/[\r]?\n/gi);

var activeRules = [];
var activeCountdowns = [];
var lastRule;
var lastCountdown;
var indents = 0;

@@ -347,5 +371,13 @@ var l = 0;

continue;
} else if (lastCountdown) {
lastCountdown--;
if (lastCountdown === 0) {
removeLastRule();
}
}
}
else if (lastRule.ignore || matchStart.matchIndex == -1 || matchEnd.matchIndex <= matchStart.matchIndex) {
else if (
lastRule.ignore ||
matchStart.matchIndex == -1 ||
matchEnd.matchIndex <= matchStart.matchIndex) {
removeLastRule();

@@ -371,3 +403,5 @@ pos = matchEnd.cursor;

lastRule = match.rule;
lastCountdown = match.countdown;
activeRules.push(lastRule);
activeCountdowns.push(lastRule.countdown);
if (lastRule.indent) {

@@ -392,3 +426,5 @@ incrementIndentation(lastRule.lineOffset);

activeRules.pop();
activeCountdowns.pop();
lastRule = activeRules[activeRules.length - 1];
lastCountdown = activeCountdowns[activeCountdowns.length - 1];
}

@@ -395,0 +431,0 @@

@@ -146,2 +146,5 @@ describe('statements.spec.js', function() {

if (test)
test
test
if (test)
if (is) {var t=0}

@@ -157,2 +160,5 @@ else var s=0;

if (test)
test
test
if (test)
if (is) {var t=0}

@@ -159,0 +165,0 @@ else var s=0;

var fs = require('fs');
var indent = require('./../lib/indent.js');
var self = this;

@@ -9,4 +8,4 @@ fs.readFile( __dirname + '/file.js', function (err, data) {

console.log(
indent.indentJS(data.toString(), ' ')
indent.js(data.toString(), ' ')
);
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc