Skip to content

Instantly share code, notes, and snippets.

@stuartwakefield
Last active December 15, 2015 10:29
Show Gist options
  • Save stuartwakefield/5246024 to your computer and use it in GitHub Desktop.
Save stuartwakefield/5246024 to your computer and use it in GitHub Desktop.
Converts silly space indenting into tab indenting. Begin rant... The whole use spaces and not tabs brigade infuriates me. A tab can be displayed based on the developers preferences, whereas spaces cannot. Space indentation can be handled automatically by your editor but very few editors support automatic removal of space indentation. Indentation…
var reindent = {
/**
* This function converts space indentation to tabs
* @param input the input to cleanse
* @param n the number of spaces used to indent
* @returns the cleansed output
*/
spacesToTabs: function(input, n) {
var regexp = new RegExp("[^\\S\\r\\n\\t]{" + n + "," + n + "}", "g");
console.log(regexp);
return input.replace(regexp, "\t");
},
/**
* This function removes whitespace at the end of lines
* @param input the input to cleanse
* @returns the cleansed output
*/
trimLineEndings: function(input) {
return input.replace(/[^\S\r\n]+([\r\n])/g, "$1");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment