Comparing version 0.1.3 to 0.1.4
@@ -0,1 +1,10 @@ | ||
#v.0.1.4 | ||
- Fixes an issue with multi uppercase letters and number usage. | ||
#v0.1.3 | ||
- Remove needless engines specificity | ||
# v0.1.2 | ||
@@ -2,0 +11,0 @@ |
44
index.js
@@ -5,6 +5,2 @@ 'use strict'; | ||
function filterUndefined(key) { | ||
return !!key; | ||
} | ||
exports = module.exports = { | ||
@@ -18,3 +14,3 @@ | ||
camelize: function camelize(obj, mapFn) { | ||
var newobj; | ||
var newobj, keys, k; | ||
@@ -41,8 +37,12 @@ if (!mapFn) { | ||
newobj = {}; | ||
keys = Object.keys(obj); | ||
Object.keys(obj).map(mapFn).filter(filterUndefined).forEach(function (key) { | ||
var newkey = exports.camelCase(key); | ||
newobj[newkey] = exports.camelize(obj[key], mapFn); | ||
}); | ||
for (var i = 0; i < keys.length; i++) { | ||
k = mapFn(keys[i]); | ||
if (!k) { | ||
continue; | ||
} | ||
k = exports.camelCase(k); | ||
newobj[k] = exports.camelize(obj[keys[i]], mapFn); | ||
} | ||
} | ||
@@ -62,3 +62,3 @@ else { | ||
underscorify: function (obj, mapFn) { | ||
var newobj; | ||
var newobj, keys, k; | ||
@@ -85,8 +85,12 @@ if (!mapFn) { | ||
newobj = {}; | ||
keys = Object.keys(obj); | ||
Object.keys(obj).map(mapFn).filter(filterUndefined).forEach(function (key) { | ||
var newkey = exports.underscore(key); | ||
newobj[newkey] = exports.underscorify(obj[key], mapFn); | ||
}); | ||
for (var i = 0; i < keys.length; i++) { | ||
k = mapFn(keys[i]); | ||
if (!k) { | ||
continue; | ||
} | ||
k = exports.underscore(k); | ||
newobj[k] = exports.underscorify(obj[keys[i]], mapFn); | ||
} | ||
} | ||
@@ -106,3 +110,3 @@ else { | ||
camelCase: function camelCase(str) { | ||
return str.replace(/([a-z])_(\w)/g, function (g) { | ||
return str.replace(/([aA-zZ])_(\w)/g, function (g) { | ||
return g[0] + g[2].toUpperCase(); | ||
@@ -118,6 +122,8 @@ }); | ||
underscore: function underscore(str) { | ||
return str.replace(/([a-z])([A-Z]+)/g, function (g) { | ||
return g[0] + '_' + g[1].toLowerCase(); | ||
return str.replace(/([a-z])([A-Z0-9]+)/g, function (g) { | ||
return g.split('').map(function (k) { | ||
return k.toLowerCase(); | ||
}).join('_'); | ||
}); | ||
} | ||
}; |
{ | ||
"name": "camelscore", | ||
"description": "camelCase and under_score utilities for objects.", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"author": "Trevor Livingston <tlivings@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7261
106