Permalink
Browse files

Changed regex order. Added new tests for overriding separator and pre…

…served characters.
  • Loading branch information...
1 parent 714bf2c commit 0e61dcfaa5b1bec3bacd97b16f3cdff7d0b28dfd tstrimple committed Feb 1, 2012
Showing with 11 additions and 1 deletion.
  1. +1 −1 slugs.js
  2. +10 −0 test/basic-tests.js
View
@@ -17,8 +17,8 @@ var slug = module.exports = function slug (incString, separator, preserved) {
return incString.toLowerCase().
replace(new RegExp('[' + p.join('') + ']', 'g'), ' '). // replace preserved characters with spaces
+ replace(/-{2,}/g, ' '). // remove duplicate spaces
replace(/^\s\s*/, '').replace(/\s\s*$/, ''). // trim both sides of string
replace(/[^\w\ ]/gi, ''). // replaces all non-alphanumeric with empty string
- replace(/-{2,}/g, ' '). // remove duplicate spaces
replace(/[\ ]/gi, s); // Convert spaces to dashes
}
View
@@ -43,4 +43,14 @@ exports['should-not-contain-duplicate-hashes-for-multiple-spaces'] = function(te
exports['should-not-include-unsafe-characters'] = function(test){
test.equal(slugs('%^T%^~!@##$$#%^$^/?????.'), 't');
test.done();
+}
+
+exports['should-override-separator-character'] = function(test){
+ test.equal(slugs('this is a string with spaces', '+'), 'this+is+a+string+with+spaces');
+ test.done();
+}
+
+exports['should-override-preserved-characters'] = function(test){
+ test.equal(slugs('this.is=a-string.without=spaces', '-', []), 'thisisastringwithoutspaces');
+ test.done();
}

0 comments on commit 0e61dcf

Please sign in to comment.