Skip to content

Commit 4ccaaa6

Browse files
authored
refactor: replace lodash invert method (#2459)
1 parent abe142a commit 4ccaaa6

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/classes/job.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ChainableCommander } from 'ioredis';
2-
import { invert } from 'lodash';
32
import { debuglog } from 'util';
43
import {
54
BackoffOptions,
@@ -24,6 +23,7 @@ import {
2423
} from '../types';
2524
import {
2625
errorObject,
26+
invertObject,
2727
isEmpty,
2828
getParentKey,
2929
lengthInUtf8Bytes,
@@ -44,7 +44,7 @@ const optsDecodeMap = {
4444
rdof: 'removeDependencyOnFailure',
4545
};
4646

47-
const optsEncodeMap = invert(optsDecodeMap);
47+
const optsEncodeMap = invertObject(optsDecodeMap);
4848

4949
export const PRIORITY_LIMIT = 2 ** 21;
5050

src/utils.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ export function delay(
6767
});
6868
}
6969

70+
export function increaseMaxListeners(
71+
emitter: EventEmitter,
72+
count: number,
73+
): void {
74+
const maxListeners = emitter.getMaxListeners();
75+
emitter.setMaxListeners(maxListeners + count);
76+
}
77+
78+
export const invertObject = (obj: Record<string, string>) => {
79+
return Object.entries(obj).reduce<Record<string, string>>(
80+
(encodeMap, [key, value]) => {
81+
encodeMap[value] = key;
82+
return encodeMap;
83+
},
84+
{},
85+
);
86+
};
87+
7088
export function isRedisInstance(obj: any): obj is Redis | Cluster {
7189
if (!obj) {
7290
return false;
@@ -79,14 +97,6 @@ export function isRedisCluster(obj: unknown): obj is Cluster {
7997
return isRedisInstance(obj) && (<Cluster>obj).isCluster;
8098
}
8199

82-
export function increaseMaxListeners(
83-
emitter: EventEmitter,
84-
count: number,
85-
): void {
86-
const maxListeners = emitter.getMaxListeners();
87-
emitter.setMaxListeners(maxListeners + count);
88-
}
89-
90100
export function decreaseMaxListeners(
91101
emitter: EventEmitter,
92102
count: number,

0 commit comments

Comments
 (0)