Skip to content

Commit

Permalink
Added utils.clean()
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 16, 2012
1 parent 42a211e commit 8ec1434
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ exports.slug = function(str){
.replace(/[^-\w]/g, '');
};

/**
* Strip the function definition from `str`,
* and re-indent for pre whitespace.
*/

exports.clean = function(str) {
str = str
.replace(/^function *\(.*\) *{/, '')
.replace(/\s+\}$/, '');

var spaces = str.match(/^\n?( *)/)[1].length
, re = new RegExp('^ {' + spaces + '}', 'gm');

str = str.replace(re, '');

return str;
};

/**
* Escape regular expression characters in `str`.
*
Expand Down

0 comments on commit 8ec1434

Please sign in to comment.