Skip to content

Commit

Permalink
refactor: replace lodash invert method (#2459)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Mar 3, 2024
1 parent abe142a commit 4ccaaa6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/classes/job.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChainableCommander } from 'ioredis';
import { invert } from 'lodash';
import { debuglog } from 'util';
import {
BackoffOptions,
Expand All @@ -24,6 +23,7 @@ import {
} from '../types';
import {
errorObject,
invertObject,
isEmpty,
getParentKey,
lengthInUtf8Bytes,
Expand All @@ -44,7 +44,7 @@ const optsDecodeMap = {
rdof: 'removeDependencyOnFailure',
};

const optsEncodeMap = invert(optsDecodeMap);
const optsEncodeMap = invertObject(optsDecodeMap);

export const PRIORITY_LIMIT = 2 ** 21;

Expand Down
26 changes: 18 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ export function delay(
});
}

export function increaseMaxListeners(
emitter: EventEmitter,
count: number,
): void {
const maxListeners = emitter.getMaxListeners();
emitter.setMaxListeners(maxListeners + count);
}

export const invertObject = (obj: Record<string, string>) => {
return Object.entries(obj).reduce<Record<string, string>>(
(encodeMap, [key, value]) => {
encodeMap[value] = key;
return encodeMap;
},
{},
);
};

export function isRedisInstance(obj: any): obj is Redis | Cluster {
if (!obj) {
return false;
Expand All @@ -79,14 +97,6 @@ export function isRedisCluster(obj: unknown): obj is Cluster {
return isRedisInstance(obj) && (<Cluster>obj).isCluster;
}

export function increaseMaxListeners(
emitter: EventEmitter,
count: number,
): void {
const maxListeners = emitter.getMaxListeners();
emitter.setMaxListeners(maxListeners + count);
}

export function decreaseMaxListeners(
emitter: EventEmitter,
count: number,
Expand Down

0 comments on commit 4ccaaa6

Please sign in to comment.