Comparing version
11
index.js
@@ -8,2 +8,3 @@ module.exports = function(obj) { | ||
if (!obj || typeof obj !== 'object') return obj; | ||
if (isDate(obj) || isRegex(obj)) return obj; | ||
if (isArray(obj)) return map(obj, walk); | ||
@@ -19,3 +20,3 @@ return reduce(objectKeys(obj), function (acc, key) { | ||
return str.replace(/[_.-](\w|$)/g, function (_,x) { | ||
return x.toUpperCase() | ||
return x.toUpperCase(); | ||
}); | ||
@@ -28,2 +29,10 @@ } | ||
var isDate = function (obj) { | ||
return Object.prototype.toString.call(obj) === '[object Date]'; | ||
}; | ||
var isRegex = function (obj) { | ||
return Object.prototype.toString.call(obj) === '[object RegExp]'; | ||
}; | ||
var has = Object.prototype.hasOwnProperty; | ||
@@ -30,0 +39,0 @@ var objectKeys = Object.keys || function (obj) { |
{ | ||
"name": "camelize", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "recursively transform key strings to camel-case", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,2 +29,14 @@ var test = require('tape'); | ||
test('date', function (t) { | ||
t.plan(1); | ||
var d = new Date(); | ||
t.equal(camelize(d), d); | ||
}); | ||
test('regex', function (t) { | ||
t.plan(1); | ||
var r = /1234/; | ||
t.equal(camelize(r), r); | ||
}); | ||
test('only camelize strings that are the root value', function (t) { | ||
@@ -31,0 +43,0 @@ t.plan(2); |
5666
8.75%101
20.24%