1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Add support for camelCase

Fixes missing `EXEC_BATCH` on multi
This commit is contained in:
Ruben Bridgewater
2016-04-13 03:54:19 +02:00
parent dfd493f6ee
commit d2b8f2f391
11 changed files with 154 additions and 34 deletions

View File

@@ -41,8 +41,10 @@ function print (err, reply) {
}
}
var camelCase;
// Deep clone arbitrary objects with arrays. Can't handle cyclic structures (results in a range error)
// Any attribute with a non primitive value besides object and array will be passed by reference (e.g. Buffers, Maps, Functions)
// All capital letters are going to be replaced with a lower case letter and a underscore infront of it
function clone (obj) {
var copy;
if (Array.isArray(obj)) {
@@ -57,7 +59,14 @@ function clone (obj) {
var elems = Object.keys(obj);
var elem;
while (elem = elems.pop()) {
copy[elem] = clone(obj[elem]);
// Accept camelCase options and convert them to snack_case
var snack_case = elem.replace(/[A-Z][^A-Z]/g, '_$&').toLowerCase();
// If camelCase is detected, pass it to the client, so all variables are going to be camelCased
// There are no deep nested options objects yet, but let's handle this future proof
if (snack_case !== elem.toLowerCase()) {
camelCase = true;
}
copy[snack_case] = clone(obj[elem]);
}
return copy;
}
@@ -65,7 +74,12 @@ function clone (obj) {
}
function convenienceClone (obj) {
return clone(obj) || {};
camelCase = false;
obj = clone(obj) || {};
if (camelCase) {
obj.camel_case = true;
}
return obj;
}
function callbackOrEmit (self, callback, err, res) {