Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,"-").toLowerCase();
};

});
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