You've already forked node-redis
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:
18
lib/utils.js
18
lib/utils.js
@@ -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) {
|
||||
|
Reference in New Issue
Block a user