Skip to content

Commit

Permalink
From Spaced To ...
Browse files Browse the repository at this point in the history
Closes findhit#6
  • Loading branch information
brunocasanova committed Sep 25, 2014
1 parent e3902e9 commit 697af17
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ var Util = require('findhit-util');
Util.String.fromDashToUnderscore( 'hey-yo' ) // 'hey_yo'
Util.String.fromDashToSpaced( 'hey-yo' ) // 'Hey Yo'

// from spaced to ...
Util.String.fromSpacedToCamel( 'hey yo' ) // 'HeyYo'
Util.String.fromSpacedToUnderscore( 'hey yo' ) // 'hey_yo'
Util.String.fromSpacedToDash( 'hey yo' ) // 'Hey-Yo'

// Function utils
// Util.function OR Util.Function

Expand Down
18 changes: 18 additions & 0 deletions lib/type/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,22 @@ module.exports = (function ( Util ){
.replace(/^[a-z]{1}/g,function ( l ){return l.toUpperCase();});
};

// from spaced to ...

st.fromSpacedToCamel = function ( str ){
return str
.replace(/(\ [a-z])/g, function ( l ){return l.toUpperCase();})
.replace(/^[a-z]{1}/g,function ( l ){return l.toUpperCase();}).replace(/\s/g, '');

};
st.fromSpacedToUnderscore = function ( str ){
return str
.split(' ').join('_')
.replace(/ /g,"_");
};
st.fromSpacedToDash = function ( str ){
return str
.replace(/ /g,"-");
};

});
31 changes: 31 additions & 0 deletions test/type/string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,37 @@ describe( "Util", function () {

});

describe('from spaced to ...', function () {

describe( ".fromSpacedToCamel", function () {

it('hey yo', function () {
var str = Util.String.fromSpacedToCamel( 'hey yo' );
expect( str ).to.be.equal( 'HeyYo' );
});

});

describe( ".fromSpacedToUnderscore", function () {

it('hey yo', function () {
var str = Util.String.fromSpacedToUnderscore( 'hey yo' );
expect( str ).to.be.equal( 'hey_yo' );
});

});

describe( ".fromSpacedToDash", function () {

it('hey yo', function () {
var str = Util.String.fromSpacedToDash( 'hey yo' );
expect( str ).to.be.equal( 'hey-yo' );
});

});

});

});

});
Expand Down

0 comments on commit 697af17

Please sign in to comment.