Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From Spaced To ... #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Util.String.fromSpacedToDash( 'hey yo' ) // 'hey-yo'
dashed should be lower-cased :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// 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,"-");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, maybe you should add .toLowerCase() :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

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