You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Remove snack_case and always use camelCase
This commit is contained in:
committed by
Ruben Bridgewater
parent
a86c998a64
commit
28afc33c9a
45
lib/utils.js
45
lib/utils.js
@ -30,10 +30,8 @@ function replyToStrings (reply) {
|
||||
return 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)) {
|
||||
@ -48,18 +46,7 @@ function clone (obj) {
|
||||
var elems = Object.keys(obj);
|
||||
var elem;
|
||||
while (elem = elems.pop()) {
|
||||
if (elem === 'tls') { // special handle tls
|
||||
copy[elem] = obj[elem];
|
||||
continue;
|
||||
}
|
||||
// Accept camelCase options and convert them to snake_case
|
||||
var snake_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 (snake_case !== elem.toLowerCase()) {
|
||||
camelCase = true;
|
||||
}
|
||||
copy[snake_case] = clone(obj[elem]);
|
||||
copy[elem] = clone(obj[elem]);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
@ -67,12 +54,7 @@ function clone (obj) {
|
||||
}
|
||||
|
||||
function convenienceClone (obj) {
|
||||
camelCase = false;
|
||||
obj = clone(obj) || {};
|
||||
if (camelCase) {
|
||||
obj.camel_case = true;
|
||||
}
|
||||
return obj;
|
||||
return clone(obj) || {};
|
||||
}
|
||||
|
||||
function callbackOrEmit (self, callback, err, res) {
|
||||
@ -86,20 +68,19 @@ function callbackOrEmit (self, callback, err, res) {
|
||||
function replyInOrder (self, callback, err, res, queue) {
|
||||
// If the queue is explicitly passed, use that, otherwise fall back to the offline queue first,
|
||||
// as there might be commands in both queues at the same time
|
||||
var command_obj;
|
||||
/* istanbul ignore if: TODO: Remove this as soon as we test Redis 3.2 on travis */
|
||||
var commandObj;
|
||||
if (queue) {
|
||||
command_obj = queue.peekBack();
|
||||
commandObj = queue.peekBack();
|
||||
} else {
|
||||
command_obj = self.offline_queue.peekBack() || self.command_queue.peekBack();
|
||||
commandObj = self.offlineQueue.peekBack() || self.commandQueue.peekBack();
|
||||
}
|
||||
if (!command_obj) {
|
||||
if (!commandObj) {
|
||||
process.nextTick(function () {
|
||||
callbackOrEmit(self, callback, err, res);
|
||||
});
|
||||
} else {
|
||||
var tmp = command_obj.callback;
|
||||
command_obj.callback = tmp ?
|
||||
var tmp = commandObj.callback;
|
||||
commandObj.callback = tmp ?
|
||||
function (e, r) {
|
||||
tmp(e, r);
|
||||
callbackOrEmit(self, callback, err, res);
|
||||
@ -114,11 +95,11 @@ function replyInOrder (self, callback, err, res, queue) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
reply_to_strings: replyToStrings,
|
||||
reply_to_object: replyToObject,
|
||||
err_code: /^([A-Z]+)\s+(.+)$/,
|
||||
replyToStrings: replyToStrings,
|
||||
replyToObject: replyToObject,
|
||||
errCode: /^([A-Z]+)\s+(.+)$/,
|
||||
monitor_regex: /^[0-9]{10,11}\.[0-9]+ \[[0-9]+ .+\]( ".+?")+$/,
|
||||
clone: convenienceClone,
|
||||
callback_or_emit: callbackOrEmit,
|
||||
reply_in_order: replyInOrder
|
||||
callbackOrEmit: callbackOrEmit,
|
||||
replyInOrder: replyInOrder
|
||||
};
|
||||
|
Reference in New Issue
Block a user