to-camel-case
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -5,3 +5,3 @@ { | ||
"description": "Converts a string to camelCase", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"keywords": [], | ||
@@ -8,0 +8,0 @@ "dependencies": {}, |
@@ -0,1 +1,6 @@ | ||
0.2.0 / 2013-04-06 | ||
================== | ||
Add `first` option for PascalCase | ||
0.1.0 / 2013-04-02 | ||
@@ -2,0 +7,0 @@ ================== |
14
index.js
/** | ||
* Converts a string to camel case | ||
* Convert a string to camel case | ||
* | ||
* @param {String} str | ||
* @param {Boolean} first upper-case first too ? (PascalCase) | ||
*/ | ||
module.exports = function (str) { | ||
return str.replace(/[_-]([a-z])/g, function (l) { | ||
module.exports = function (str, first) { | ||
str = str.replace(/[_-]([a-z])/g, function (l) { | ||
return l[1].toUpperCase() | ||
}) | ||
if (first) | ||
str = str.charAt(0).toUpperCase() + str.slice(1) | ||
return str | ||
} |
{ | ||
"name": "to-camel-case", | ||
"repo": "Nami-Doc/to-camel-case", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"keywords": ["camel-case", "camelCase", "string", "case"], | ||
@@ -6,0 +6,0 @@ "devDependencies": { |
@@ -14,3 +14,3 @@ | ||
### toCamelCase | ||
### toCamelCase(string, first = false) | ||
@@ -21,2 +21,4 @@ ```js | ||
toCamelCase("chocolate-rain").should.equal("chocolateRain") | ||
toCamelCase("hello-howare-ya", true).should.equal("HelloHowareYa") | ||
``` | ||
@@ -23,0 +25,0 @@ |
@@ -5,7 +5,13 @@ var toCamelCase = require('..') | ||
it('should convert dashes to camel case', function () { | ||
toCamelCase("hello-ya").should.equal("helloYa") | ||
toCamelCase("hello-howare-ya").should.equal("helloHowareYa") | ||
}) | ||
it('should convert underscores to camel case', function () { | ||
toCamelCase("chocolate-rain").should.equal("chocolateRain") | ||
toCamelCase("the_chocolate_rain").should.equal("theChocolateRain") | ||
}) | ||
}) | ||
describe('toCamelCase(str, first=true)', function () { | ||
it('should upper case first and convert dashes to camel case', function () { | ||
toCamelCase("hello-howare-ya", true).should.equal("HelloHowareYa") | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
2291
38
27